Skip to content

Commit 8c3314a

Browse files
committed
Unit tests for DSL workflow
1 parent bcbb3aa commit 8c3314a

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

cmd/samples/dsl/workflow_test.go

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,7 @@ import (
1313
"go.uber.org/cadence/workflow"
1414
)
1515

16-
func Test_SimpleDSLWorkflow(t *testing.T) {
17-
testSuite := &testsuite.WorkflowTestSuite{}
18-
env := testSuite.NewTestWorkflowEnvironment()
19-
env.RegisterWorkflow(simpleDSLWorkflow)
20-
21-
// Define a sample DSL workflow
22-
dslWorkflow := Workflow{
23-
Variables: map[string]string{
24-
"var1": "value1",
25-
"var2": "value2",
26-
},
27-
Root: Statement{
28-
Activity: &ActivityInvocation{
29-
Name: "sampleActivity",
30-
Arguments: []string{"var1", "var2"},
31-
Result: "resultVar",
32-
},
33-
},
34-
}
35-
36-
// Register a sample activity
37-
env.RegisterActivityWithOptions(sampleActivity, activity.RegisterOptions{
38-
Name: "sampleActivity",
39-
})
40-
41-
var activityCalled []string
42-
env.SetOnActivityStartedListener(func(activityInfo *activity.Info, ctx context.Context, args encoded.Values) {
43-
activityType := activityInfo.ActivityType.Name
44-
activityCalled = append(activityCalled, activityType)
45-
require.Equal(t, "sampleActivity", activityType)
46-
})
47-
48-
env.ExecuteWorkflow(simpleDSLWorkflow, dslWorkflow)
49-
50-
require.True(t, env.IsWorkflowCompleted())
51-
require.NoError(t, env.GetWorkflowError())
52-
require.Equal(t, []string{"sampleActivity"}, activityCalled)
53-
}
54-
55-
func sampleActivity(input []string) (string, error) {
56-
name := "sampleActivity"
57-
fmt.Printf("Run %s with input %v \n", name, input)
58-
return "Result_" + name, nil
59-
}
60-
61-
func TestActivitySequenceParallelStatements_execute(t *testing.T) {
16+
func TestActivitySequenceParallelStatements(t *testing.T) {
6217
testSuite := &testsuite.WorkflowTestSuite{}
6318

6419
tests := []struct {
@@ -168,7 +123,7 @@ func TestActivitySequenceParallelStatements_execute(t *testing.T) {
168123
}
169124
}
170125

171-
func TestSequence_execute(t *testing.T) {
126+
func TestSequenceFlow(t *testing.T) {
172127
testSuite := &testsuite.WorkflowTestSuite{}
173128

174129
tests := []struct {
@@ -277,7 +232,7 @@ func TestSequence_execute(t *testing.T) {
277232
}
278233
}
279234

280-
func TestParallel_execute(t *testing.T) {
235+
func TestParallelFlow(t *testing.T) {
281236
testSuite := &testsuite.WorkflowTestSuite{}
282237

283238
tests := []struct {
@@ -386,7 +341,7 @@ func TestParallel_execute(t *testing.T) {
386341
}
387342
}
388343

389-
func TestActivityInvocation_execute(t *testing.T) {
344+
func TestActivityInvocationFlow(t *testing.T) {
390345
testSuite := &testsuite.WorkflowTestSuite{}
391346

392347
tests := []struct {
@@ -448,3 +403,48 @@ func TestActivityInvocation_execute(t *testing.T) {
448403
})
449404
}
450405
}
406+
407+
func Test_SimpleDSLWorkflow(t *testing.T) {
408+
testSuite := &testsuite.WorkflowTestSuite{}
409+
env := testSuite.NewTestWorkflowEnvironment()
410+
env.RegisterWorkflow(simpleDSLWorkflow)
411+
412+
// Define a sample DSL workflow
413+
dslWorkflow := Workflow{
414+
Variables: map[string]string{
415+
"var1": "value1",
416+
"var2": "value2",
417+
},
418+
Root: Statement{
419+
Activity: &ActivityInvocation{
420+
Name: "sampleActivity",
421+
Arguments: []string{"var1", "var2"},
422+
Result: "resultVar",
423+
},
424+
},
425+
}
426+
427+
// Register a sample activity
428+
env.RegisterActivityWithOptions(sampleActivity, activity.RegisterOptions{
429+
Name: "sampleActivity",
430+
})
431+
432+
var activityCalled []string
433+
env.SetOnActivityStartedListener(func(activityInfo *activity.Info, ctx context.Context, args encoded.Values) {
434+
activityType := activityInfo.ActivityType.Name
435+
activityCalled = append(activityCalled, activityType)
436+
require.Equal(t, "sampleActivity", activityType)
437+
})
438+
439+
env.ExecuteWorkflow(simpleDSLWorkflow, dslWorkflow)
440+
441+
require.True(t, env.IsWorkflowCompleted())
442+
require.NoError(t, env.GetWorkflowError())
443+
require.Equal(t, []string{"sampleActivity"}, activityCalled)
444+
}
445+
446+
func sampleActivity(input []string) (string, error) {
447+
name := "sampleActivity"
448+
fmt.Printf("Run %s with input %v \n", name, input)
449+
return "Result_" + name, nil
450+
}

0 commit comments

Comments
 (0)