-
Notifications
You must be signed in to change notification settings - Fork 1
/
step_inner_test.go
215 lines (210 loc) · 5.03 KB
/
step_inner_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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package choreograph
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_checkStep(t *testing.T) {
type dummyStruct struct{}
simpleJobOrPreCheckFunc := func(context.Context) error { return nil }
tests := []struct {
name string
step *Step
wantErr error
}{
{
name: "correct step",
step: &Step{
Job: simpleJobOrPreCheckFunc,
PreCheck: simpleJobOrPreCheckFunc,
},
wantErr: nil,
},
{
name: "two outputs for job",
step: &Step{
Job: func(context.Context) (string, error) { return "", nil },
PreCheck: simpleJobOrPreCheckFunc,
},
wantErr: nil,
},
{
name: "two outputs for preCheck",
step: &Step{
PreCheck: func(context.Context) (string, error) { return "", nil },
Job: simpleJobOrPreCheckFunc,
},
wantErr: nil,
},
{
name: "three outputs for job",
step: &Step{
Job: func(context.Context) (int, string, error) { return 0, "", nil },
PreCheck: simpleJobOrPreCheckFunc,
},
wantErr: ErrJobTooManyOutputParameters,
},
{
name: "three outputs for preCheck",
step: &Step{
PreCheck: func(context.Context) (int, string, error) { return 0, "", nil },
Job: simpleJobOrPreCheckFunc,
},
wantErr: ErrPreCheckTooManyOutputParameters,
},
{
name: "three input parameters for preCheck",
step: &Step{
Job: simpleJobOrPreCheckFunc,
PreCheck: func(context.Context, int, string) error { return nil },
},
wantErr: ErrPreCheckTooManyInputParameters,
},
{
name: "three input parameters for job",
step: &Step{
Job: func(context.Context, int, string) error { return nil },
PreCheck: simpleJobOrPreCheckFunc,
},
wantErr: ErrJobTooManyInputParameters,
},
{
name: "two inputs, two outputs for job",
step: &Step{
Job: func(context.Context, int) (string, error) { return "", nil },
PreCheck: simpleJobOrPreCheckFunc,
},
wantErr: nil,
},
{
name: "two inputs, two outputs for preCheck",
step: &Step{
PreCheck: func(context.Context, int) (string, error) { return "", nil },
Job: simpleJobOrPreCheckFunc,
},
wantErr: nil,
},
{
name: "job is not a function",
step: &Step{
Job: dummyStruct{},
PreCheck: simpleJobOrPreCheckFunc,
},
wantErr: ErrJobIsNotAFunction,
},
{
name: "preCheck is not a function",
step: &Step{
Job: simpleJobOrPreCheckFunc,
PreCheck: dummyStruct{},
},
wantErr: ErrPreCheckIsNotAFunction,
},
{
name: "job no context as parameter",
step: &Step{
Job: func() error { return nil },
PreCheck: simpleJobOrPreCheckFunc,
},
wantErr: ErrJobContextParameterRequired,
},
{
name: "preCheck no context as parameter",
step: &Step{
PreCheck: func() error { return nil },
Job: simpleJobOrPreCheckFunc,
},
wantErr: ErrPreCheckContextParameterRequired,
},
{
name: "job no error param on output",
step: &Step{
Job: func(_ context.Context) {},
PreCheck: simpleJobOrPreCheckFunc,
},
wantErr: ErrJobErrorOnOutputRequired,
},
{
name: "preCheck no error param on output",
step: &Step{
PreCheck: func(_ context.Context) {},
Job: simpleJobOrPreCheckFunc,
},
wantErr: ErrPreCheckErrorOnOutputRequired,
},
{
name: "job last param not an error",
step: &Step{
Job: func(_ context.Context) (error, int) { return nil, 0 },
PreCheck: simpleJobOrPreCheckFunc,
},
wantErr: ErrJobErrorAsLastParameterRequired,
},
{
name: "preCheck last param not an error",
step: &Step{
PreCheck: func(_ context.Context) (error, int) { return nil, 0 },
Job: simpleJobOrPreCheckFunc,
},
wantErr: ErrPreCheckLastParamTypeErrorRequired,
},
{
name: "preCheck with no parameters",
step: &Step{
Job: simpleJobOrPreCheckFunc,
PreCheck: func() {},
},
wantErr: ErrPreCheckContextParameterRequired,
},
{
name: "preCheck context as second parameter",
step: &Step{
Job: simpleJobOrPreCheckFunc,
PreCheck: func(int, context.Context) error { return nil },
},
wantErr: ErrPreCheckContextAsFirstParameter,
},
{
name: "job context as second parameter",
step: &Step{
PreCheck: simpleJobOrPreCheckFunc,
Job: func(int, context.Context) error { return nil },
},
wantErr: ErrJobContextAsFirstParameter,
},
{
name: "preCheck no error output function",
step: &Step{
Job: simpleJobOrPreCheckFunc,
PreCheck: func(context.Context) {},
},
wantErr: ErrPreCheckErrorOnOutputRequired,
},
{
name: "job is nil",
step: &Step{
Job: nil,
PreCheck: simpleJobOrPreCheckFunc,
},
wantErr: ErrJobFuncIsRequired,
},
{
name: "preCheck is nil",
step: &Step{
Job: simpleJobOrPreCheckFunc,
PreCheck: nil,
},
wantErr: ErrPreCheckFuncIsRequired,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := checkStep(tt.step)
if tt.wantErr != nil {
assert.ErrorIs(t, err, tt.wantErr)
} else {
assert.NoError(t, err)
}
})
}
}