-
Notifications
You must be signed in to change notification settings - Fork 6
/
step_builder_test.go
75 lines (53 loc) · 4.11 KB
/
step_builder_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package asyncjob_test
import (
"testing"
"github.com/Azure/go-asyncjob"
"github.com/stretchr/testify/assert"
)
func TestDefinitionRendering(t *testing.T) {
t.Parallel()
renderGraph(t, SqlSummaryAsyncJobDefinition)
}
func TestDefinitionBuilder(t *testing.T) {
t.Parallel()
job := asyncjob.NewJobDefinition[*SqlSummaryJobLib]("sqlSummaryJob")
notExistingTask := &asyncjob.StepDefinition[any]{}
_, err := asyncjob.AddStep(job, "GetConnection", connectionStepFunc, asyncjob.ExecuteAfter(notExistingTask), asyncjob.WithContextEnrichment(EnrichContext))
assert.EqualError(t, err, "RefStepNotInJob: trying to reference to step \"\", but it is not registered in job")
connTsk, err := asyncjob.AddStep(job, "GetConnection", connectionStepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.NoError(t, err)
_, err = asyncjob.AddStep(job, "GetConnection", connectionStepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.EqualError(t, err, "AddExistingStep: trying to add step \"GetConnection\" to job definition, but it already exists")
table1ClientTsk, err := asyncjob.StepAfter(job, "GetTableClient1", connTsk, tableClient1StepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.NoError(t, err)
_, err = asyncjob.StepAfter(job, "GetTableClient1", connTsk, tableClient1StepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.EqualError(t, err, "AddExistingStep: trying to add step \"GetTableClient1\" to job definition, but it already exists")
table2ClientTsk, err := asyncjob.StepAfter(job, "GetTableClient2", connTsk, tableClient2StepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.NoError(t, err)
_, err = asyncjob.StepAfter(job, "QueryTable1", table1ClientTsk, queryTable1StepFunc, asyncjob.ExecuteAfter(notExistingTask), asyncjob.WithContextEnrichment(EnrichContext))
assert.EqualError(t, err, "RefStepNotInJob: trying to reference to step \"\", but it is not registered in job")
query1Task, err := asyncjob.StepAfter(job, "QueryTable1", table1ClientTsk, queryTable1StepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.NoError(t, err)
query2Task, err := asyncjob.StepAfter(job, "QueryTable2", table2ClientTsk, queryTable2StepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.NoError(t, err)
_, err = asyncjob.StepAfterBoth(job, "Summarize", query1Task, query2Task, summarizeQueryResultStepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.NoError(t, err)
_, err = asyncjob.StepAfterBoth(job, "Summarize", query1Task, query2Task, summarizeQueryResultStepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.EqualError(t, err, "AddExistingStep: trying to add step \"Summarize\" to job definition, but it already exists")
_, err = asyncjob.StepAfterBoth(job, "Summarize1", query1Task, query1Task, summarizeQueryResultStepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.EqualError(t, err, "DuplicateInputParentStep: at least 2 input parentSteps are same")
query3Task := &asyncjob.StepDefinition[*SqlQueryResult]{}
_, err = asyncjob.StepAfterBoth(job, "Summarize2", query1Task, query3Task, summarizeQueryResultStepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.EqualError(t, err, "RefStepNotInJob: trying to reference to step \"\", but it is not registered in job")
assert.False(t, job.Sealed())
job.Seal()
assert.True(t, job.Sealed())
job.Seal()
assert.True(t, job.Sealed())
_, err = asyncjob.AddStep(job, "GetConnectionAgain", connectionStepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.EqualError(t, err, "AddStepInSealedJob: trying to add step \"GetConnectionAgain\" to a sealed job definition")
_, err = asyncjob.StepAfter(job, "QueryTable1Again", table1ClientTsk, queryTable1StepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.EqualError(t, err, "AddStepInSealedJob: trying to add step \"QueryTable1Again\" to a sealed job definition")
_, err = asyncjob.StepAfterBoth(job, "SummarizeAgain", query1Task, query2Task, summarizeQueryResultStepFunc, asyncjob.WithContextEnrichment(EnrichContext))
assert.EqualError(t, err, "AddStepInSealedJob: trying to add step \"SummarizeAgain\" to a sealed job definition")
}