@@ -19,13 +19,11 @@ func operator(spec operatorsv1alpha1.OperatorSpec) *operatorsv1alpha1.Operator {
19
19
}
20
20
}
21
21
22
- type testData struct {
22
+ var operatorData = [] struct {
23
23
spec * operatorsv1alpha1.Operator
24
24
comment string
25
25
errMsg string
26
- }
27
-
28
- var operatorData = []testData {
26
+ }{
29
27
{
30
28
operator (operatorsv1alpha1.OperatorSpec {}),
31
29
"operator spec is empty" ,
@@ -57,23 +55,29 @@ var operatorData = []testData{
57
55
}
58
56
59
57
func TestOperatorSpecs (t * testing.T ) {
58
+ t .Parallel ()
60
59
ctx , cancel := context .WithCancel (context .Background ())
61
- defer cancel ()
62
-
63
- for _ , d := range operatorData {
64
- t .Logf ("Running %s" , d .comment )
65
- cl , err := newClient ()
66
- require .NoError (t , err )
67
- require .NotNil (t , cl )
68
- err = cl .Create (ctx , d .spec )
69
- require .Error (t , err )
70
- require .ErrorContains (t , err , d .errMsg )
60
+ t .Cleanup (cancel )
61
+
62
+ for _ , od := range operatorData {
63
+ d := od
64
+ t .Run (d .comment , func (t * testing.T ) {
65
+ t .Parallel ()
66
+ t .Logf ("Running %s" , d .comment )
67
+ cl , err := newClient ()
68
+ require .NoError (t , err )
69
+ require .NotNil (t , cl )
70
+ err = cl .Create (ctx , d .spec )
71
+ require .Error (t , err )
72
+ require .ErrorContains (t , err , d .errMsg )
73
+ })
71
74
}
72
75
}
73
76
74
77
func TestOperatorInvalidSemver (t * testing.T ) {
78
+ t .Parallel ()
75
79
ctx , cancel := context .WithCancel (context .Background ())
76
- defer cancel ( )
80
+ t . Cleanup ( cancel )
77
81
78
82
invalidSemvers := []string {
79
83
"1.2.3.4" ,
@@ -96,23 +100,28 @@ func TestOperatorInvalidSemver(t *testing.T) {
96
100
">1.2.3;<2.3.4" ,
97
101
"1.2.3 - 2.3.4" ,
98
102
}
99
- for _ , invalidSemver := range invalidSemvers {
100
- cl , err := newClient ()
101
- require .NoError (t , err )
102
- require .NotNil (t , cl )
103
- err = cl .Create (ctx , operator (operatorsv1alpha1.OperatorSpec {
104
- PackageName : "package" ,
105
- Version : invalidSemver ,
106
- }))
107
- require .Errorf (t , err , "expected error for invalid semver %q" , invalidSemver )
108
- // Don't need to include the whole regex, this should be enough to match the MasterMinds regex
109
- require .ErrorContains (t , err , "spec.version in body should match '^(\\ s*(=||!=|>|<|>=|=>|<=|=<|~|~>|\\ ^)" )
103
+ for _ , sm := range invalidSemvers {
104
+ d := sm
105
+ t .Run (d , func (t * testing.T ) {
106
+ t .Parallel ()
107
+ cl , err := newClient ()
108
+ require .NoError (t , err )
109
+ require .NotNil (t , cl )
110
+ err = cl .Create (ctx , operator (operatorsv1alpha1.OperatorSpec {
111
+ PackageName : "package" ,
112
+ Version : d ,
113
+ }))
114
+ require .Errorf (t , err , "expected error for invalid semver %q" , d )
115
+ // Don't need to include the whole regex, this should be enough to match the MasterMinds regex
116
+ require .ErrorContains (t , err , "spec.version in body should match '^(\\ s*(=||!=|>|<|>=|=>|<=|=<|~|~>|\\ ^)" )
117
+ })
110
118
}
111
119
}
112
120
113
121
func TestOperatorValidSemver (t * testing.T ) {
122
+ t .Parallel ()
114
123
ctx , cancel := context .WithCancel (context .Background ())
115
- defer cancel ( )
124
+ t . Cleanup ( cancel )
116
125
117
126
validSemvers := []string {
118
127
">=1.2.3" ,
@@ -148,22 +157,27 @@ func TestOperatorValidSemver(t *testing.T) {
148
157
"<1.2.3-abc >2.3.4-def" ,
149
158
"<1.2.3-abc+def >2.3.4-ghi+jkl" ,
150
159
}
151
- for _ , validSemver := range validSemvers {
152
- op := operator (operatorsv1alpha1.OperatorSpec {
153
- PackageName : "package" ,
154
- Version : validSemver ,
160
+ for _ , smx := range validSemvers {
161
+ d := smx
162
+ t .Run (d , func (t * testing.T ) {
163
+ t .Parallel ()
164
+ op := operator (operatorsv1alpha1.OperatorSpec {
165
+ PackageName : "package" ,
166
+ Version : d ,
167
+ })
168
+ cl , err := newClient ()
169
+ require .NoError (t , err )
170
+ require .NotNil (t , cl )
171
+ err = cl .Create (ctx , op )
172
+ require .NoErrorf (t , err , "unexpected error for semver range %q: %w" , d , err )
155
173
})
156
- cl , err := newClient ()
157
- require .NoError (t , err )
158
- require .NotNil (t , cl )
159
- err = cl .Create (ctx , op )
160
- require .NoErrorf (t , err , "unexpected error for semver range '%q': %w" , validSemver , err )
161
174
}
162
175
}
163
176
164
177
func TestOperatorInvalidChannel (t * testing.T ) {
178
+ t .Parallel ()
165
179
ctx , cancel := context .WithCancel (context .Background ())
166
- defer cancel ( )
180
+ t . Cleanup ( cancel )
167
181
168
182
invalidChannels := []string {
169
183
"spaces spaces" ,
@@ -175,37 +189,46 @@ func TestOperatorInvalidChannel(t *testing.T) {
175
189
".start-with-period" ,
176
190
"end-with-period." ,
177
191
}
178
- for _ , invalidChannel := range invalidChannels {
179
- cl , err := newClient ()
180
- require .NoError (t , err )
181
- require .NotNil (t , cl )
182
- err = cl .Create (ctx , operator (operatorsv1alpha1.OperatorSpec {
183
- PackageName : "package" ,
184
- Channel : invalidChannel ,
185
- }))
186
- require .Errorf (t , err , "expected error for invalid channel '%q'" , invalidChannel )
187
- require .ErrorContains (t , err , "spec.channel in body should match '^[a-z0-9]+([\\ .-][a-z0-9]+)*$'" )
192
+ for _ , ch := range invalidChannels {
193
+ d := ch
194
+ t .Run (d , func (t * testing.T ) {
195
+ t .Parallel ()
196
+ cl , err := newClient ()
197
+ require .NoError (t , err )
198
+ require .NotNil (t , cl )
199
+ err = cl .Create (ctx , operator (operatorsv1alpha1.OperatorSpec {
200
+ PackageName : "package" ,
201
+ Channel : d ,
202
+ }))
203
+ require .Errorf (t , err , "expected error for invalid channel %q" , d )
204
+ require .ErrorContains (t , err , "spec.channel in body should match '^[a-z0-9]+([\\ .-][a-z0-9]+)*$'" )
205
+ })
188
206
}
189
207
}
190
208
191
209
func TestOperatorValidChannel (t * testing.T ) {
210
+ t .Parallel ()
192
211
ctx , cancel := context .WithCancel (context .Background ())
193
- defer cancel ( )
212
+ t . Cleanup ( cancel )
194
213
195
214
validChannels := []string {
196
215
"hyphenated-name" ,
197
216
"dotted.name" ,
198
217
"channel-has-version-1.0.1" ,
199
218
}
200
- for _ , validChannel := range validChannels {
201
- op := operator (operatorsv1alpha1.OperatorSpec {
202
- PackageName : "package" ,
203
- Channel : validChannel ,
219
+ for _ , ch := range validChannels {
220
+ d := ch
221
+ t .Run (d , func (t * testing.T ) {
222
+ t .Parallel ()
223
+ op := operator (operatorsv1alpha1.OperatorSpec {
224
+ PackageName : "package" ,
225
+ Channel : d ,
226
+ })
227
+ cl , err := newClient ()
228
+ require .NoError (t , err )
229
+ require .NotNil (t , cl )
230
+ err = cl .Create (ctx , op )
231
+ require .NoErrorf (t , err , "unexpected error creating valid channel %q: %w" , d , err )
204
232
})
205
- cl , err := newClient ()
206
- require .NoError (t , err )
207
- require .NotNil (t , cl )
208
- err = cl .Create (ctx , op )
209
- require .NoErrorf (t , err , "unexpected error creating valid channel '%q': %w" , validChannel , err )
210
233
}
211
234
}
0 commit comments