@@ -2,6 +2,7 @@ package controllers_test
2
2
3
3
import (
4
4
"context"
5
+ "sync"
5
6
"testing"
6
7
7
8
"github.com/stretchr/testify/require"
@@ -61,15 +62,21 @@ func TestOperatorSpecs(t *testing.T) {
61
62
ctx , cancel := context .WithCancel (context .Background ())
62
63
defer cancel ()
63
64
65
+ var wg sync.WaitGroup
66
+ wg .Add (len (operatorData ))
64
67
for _ , d := range operatorData {
65
- t .Logf ("Running %s" , d .comment )
66
- cl , err := newClient ()
67
- require .NoError (t , err )
68
- require .NotNil (t , cl )
69
- err = cl .Create (ctx , d .spec )
70
- require .Error (t , err )
71
- require .ErrorContains (t , err , d .errMsg )
68
+ go func (t * testing.T , d testData ) {
69
+ defer wg .Done ()
70
+ t .Logf ("Running %s" , d .comment )
71
+ cl , err := newClient ()
72
+ require .NoError (t , err )
73
+ require .NotNil (t , cl )
74
+ err = cl .Create (ctx , d .spec )
75
+ require .Error (t , err )
76
+ require .ErrorContains (t , err , d .errMsg )
77
+ }(t , d )
72
78
}
79
+ wg .Wait ()
73
80
}
74
81
75
82
func TestOperatorInvalidSemver (t * testing.T ) {
@@ -97,18 +104,24 @@ func TestOperatorInvalidSemver(t *testing.T) {
97
104
">1.2.3;<2.3.4" ,
98
105
"1.2.3 - 2.3.4" ,
99
106
}
100
- for _ , invalidSemver := range invalidSemvers {
101
- cl , err := newClient ()
102
- require .NoError (t , err )
103
- require .NotNil (t , cl )
104
- err = cl .Create (ctx , operator (operatorsv1alpha1.OperatorSpec {
105
- PackageName : "package" ,
106
- Version : invalidSemver ,
107
- }))
108
- require .Errorf (t , err , "expected error for invalid semver %q" , invalidSemver )
109
- // Don't need to include the whole regex, this should be enough to match the MasterMinds regex
110
- require .ErrorContains (t , err , "spec.version in body should match '^(\\ s*(=||!=|>|<|>=|=>|<=|=<|~|~>|\\ ^)" )
107
+ var wg sync.WaitGroup
108
+ wg .Add (len (invalidSemvers ))
109
+ for _ , sm := range invalidSemvers {
110
+ go func (t * testing.T , sm string ) {
111
+ defer wg .Done ()
112
+ cl , err := newClient ()
113
+ require .NoError (t , err )
114
+ require .NotNil (t , cl )
115
+ err = cl .Create (ctx , operator (operatorsv1alpha1.OperatorSpec {
116
+ PackageName : "package" ,
117
+ Version : sm ,
118
+ }))
119
+ require .Errorf (t , err , "expected error for invalid semver %q" , sm )
120
+ // Don't need to include the whole regex, this should be enough to match the MasterMinds regex
121
+ require .ErrorContains (t , err , "spec.version in body should match '^(\\ s*(=||!=|>|<|>=|=>|<=|=<|~|~>|\\ ^)" )
122
+ }(t , sm )
111
123
}
124
+ wg .Wait ()
112
125
}
113
126
114
127
func TestOperatorValidSemver (t * testing.T ) {
@@ -149,17 +162,23 @@ func TestOperatorValidSemver(t *testing.T) {
149
162
"<1.2.3-abc >2.3.4-def" ,
150
163
"<1.2.3-abc+def >2.3.4-ghi+jkl" ,
151
164
}
152
- for _ , validSemver := range validSemvers {
153
- op := operator (operatorsv1alpha1.OperatorSpec {
154
- PackageName : "package" ,
155
- Version : validSemver ,
156
- })
157
- cl , err := newClient ()
158
- require .NoError (t , err )
159
- require .NotNil (t , cl )
160
- err = cl .Create (ctx , op )
161
- require .NoErrorf (t , err , "unexpected error for semver range '%q': %w" , validSemver , err )
165
+ var wg sync.WaitGroup
166
+ wg .Add (len (validSemvers ))
167
+ for _ , sm := range validSemvers {
168
+ go func (t * testing.T , sm string ) {
169
+ defer wg .Done ()
170
+ op := operator (operatorsv1alpha1.OperatorSpec {
171
+ PackageName : "package" ,
172
+ Version : sm ,
173
+ })
174
+ cl , err := newClient ()
175
+ require .NoError (t , err )
176
+ require .NotNil (t , cl )
177
+ err = cl .Create (ctx , op )
178
+ require .NoErrorf (t , err , "unexpected error for semver range '%q': %w" , sm , err )
179
+ }(t , sm )
162
180
}
181
+ wg .Wait ()
163
182
}
164
183
165
184
func TestOperatorInvalidChannel (t * testing.T ) {
@@ -176,17 +195,23 @@ func TestOperatorInvalidChannel(t *testing.T) {
176
195
".start-with-period" ,
177
196
"end-with-period." ,
178
197
}
179
- for _ , invalidChannel := range invalidChannels {
180
- cl , err := newClient ()
181
- require .NoError (t , err )
182
- require .NotNil (t , cl )
183
- err = cl .Create (ctx , operator (operatorsv1alpha1.OperatorSpec {
184
- PackageName : "package" ,
185
- Channel : invalidChannel ,
186
- }))
187
- require .Errorf (t , err , "expected error for invalid channel '%q'" , invalidChannel )
188
- require .ErrorContains (t , err , "spec.channel in body should match '^[a-z0-9]+([\\ .-][a-z0-9]+)*$'" )
198
+ var wg sync.WaitGroup
199
+ wg .Add (len (invalidChannels ))
200
+ for _ , ch := range invalidChannels {
201
+ go func (t * testing.T , ch string ) {
202
+ defer wg .Done ()
203
+ cl , err := newClient ()
204
+ require .NoError (t , err )
205
+ require .NotNil (t , cl )
206
+ err = cl .Create (ctx , operator (operatorsv1alpha1.OperatorSpec {
207
+ PackageName : "package" ,
208
+ Channel : ch ,
209
+ }))
210
+ require .Errorf (t , err , "expected error for invalid channel '%q'" , ch )
211
+ require .ErrorContains (t , err , "spec.channel in body should match '^[a-z0-9]+([\\ .-][a-z0-9]+)*$'" )
212
+ }(t , ch )
189
213
}
214
+ wg .Wait ()
190
215
}
191
216
192
217
func TestOperatorValidChannel (t * testing.T ) {
@@ -198,15 +223,21 @@ func TestOperatorValidChannel(t *testing.T) {
198
223
"dotted.name" ,
199
224
"channel-has-version-1.0.1" ,
200
225
}
201
- for _ , validChannel := range validChannels {
202
- op := operator (operatorsv1alpha1.OperatorSpec {
203
- PackageName : "package" ,
204
- Channel : validChannel ,
205
- })
206
- cl , err := newClient ()
207
- require .NoError (t , err )
208
- require .NotNil (t , cl )
209
- err = cl .Create (ctx , op )
210
- require .NoErrorf (t , err , "unexpected error creating valid channel '%q': %w" , validChannel , err )
226
+ var wg sync.WaitGroup
227
+ wg .Add (len (validChannels ))
228
+ for _ , ch := range validChannels {
229
+ go func (t * testing.T , ch string ) {
230
+ defer wg .Done ()
231
+ op := operator (operatorsv1alpha1.OperatorSpec {
232
+ PackageName : "package" ,
233
+ Channel : ch ,
234
+ })
235
+ cl , err := newClient ()
236
+ require .NoError (t , err )
237
+ require .NotNil (t , cl )
238
+ err = cl .Create (ctx , op )
239
+ require .NoErrorf (t , err , "unexpected error creating valid channel '%q': %w" , ch , err )
240
+ }(t , ch )
211
241
}
242
+ wg .Wait ()
212
243
}
0 commit comments