-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkflow_configure_test.go
More file actions
151 lines (136 loc) · 3.72 KB
/
workflow_configure_test.go
File metadata and controls
151 lines (136 loc) · 3.72 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package chain
import (
"context"
"github.com/stretchr/testify/assert"
"testing"
)
func TestWorkflow_Configure(t *testing.T) {
newAction := func(name string) Action[string] {
return NewSimpleAction(
name,
func(_ context.Context, _ string) (string, error) { return "", nil },
)
}
terminate := Terminate[string]()
terminationPlan := TerminationPlan[string]()
type testCase struct {
code func()
panics bool
message string
}
testCases := map[string]testCase{
"creating without name": {
code: func() {
NewWorkflow[string]("")
},
panics: true,
message: "workflow must have a name",
},
"creating without action": {
code: func() {
NewWorkflow[string]("Workflow")
},
panics: true,
message: "no actions were described for creating workflow",
},
"creating with terminate": {
code: func() {
action1 := newAction("action")
NewWorkflow("Workflow", action1, terminate)
},
panics: true,
message: "do not set terminate as a member",
},
"creating with duplicate actions": {
code: func() {
action1 := newAction("action")
NewWorkflow("Workflow", action1, action1)
},
panics: true,
message: "duplicate action specified on actions argument 2",
},
"set action plan for terminate": {
code: func() {
action1 := newAction("action")
workflow := NewWorkflow("Workflow", action1)
workflow.SetRunPlan(terminate, terminationPlan)
},
panics: true,
message: "cannot set plan for terminate",
},
"set action plan for unsupported direction": {
code: func() {
action1, action2 := newAction("action1"), newAction("action2")
workflow := NewWorkflow("Workflow", action1, action2)
workflow.SetRunPlan(action1, RunPlan[string]{
"unsupported": action2,
})
},
panics: true,
message: "`action1` does not support direction `unsupported`",
},
"set action plan for non-member": {
code: func() {
action1, nonMember := newAction("member"), newAction("non-member")
workflow := NewWorkflow("Workflow", action1)
workflow.SetRunPlan(nonMember, SuccessOnlyPlan(action1))
},
panics: true,
message: "`non-member` is not a member of this workflow",
},
"set action plan directing non-member": {
code: func() {
action1, nonMember := newAction("member"), newAction("non-member")
workflow := NewWorkflow("Workflow", action1)
workflow.SetRunPlan(action1, SuccessOnlyPlan(nonMember))
},
panics: true,
message: "setting plan from `member` directing `success` to non-member `non-member`",
},
"set action plan with self loop": {
code: func() {
action1 := newAction("member")
workflow := NewWorkflow("Workflow", action1)
workflow.SetRunPlan(action1, SuccessOnlyPlan(action1))
},
panics: true,
message: "setting self loop plan with `member` directing `success`",
},
"not configuring manual plans": {
code: func() {
action1 := newAction("action")
workflow := NewWorkflow("Workflow", action1)
_ = workflow
},
panics: false,
},
"skipping some default directions": {
code: func() {
action1 := newAction("action")
workflow := NewWorkflow("Workflow", action1)
workflow.SetRunPlan(action1, RunPlan[string]{
Success: terminate,
// Not configuring Failure, Abort
})
},
panics: false,
},
"skipping plan description": {
code: func() {
action1 := newAction("action")
workflow := NewWorkflow("Workflow", action1)
workflow.SetRunPlan(action1, terminationPlan) // terminationPlan is nil
},
panics: false,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
if tc.panics {
assert.PanicsWithError(t, tc.message, tc.code)
} else {
assert.NotPanics(t, tc.code)
}
})
}
}