@@ -63,7 +63,20 @@ func controllerSetup(startingObjects []runtime.Object, t *testing.T, stopCh <-ch
63
63
return kubeclient , fakeWatch , controller , informerFactory
64
64
}
65
65
66
- func wrapHandler (indicator chan bool , handler func (string ) error , t * testing.T ) func (string ) error {
66
+ func wrapHandler (indicator chan bool , handler func () error , t * testing.T ) func () error {
67
+ return func () error {
68
+ defer func () { indicator <- true }()
69
+
70
+ err := handler ()
71
+ if err != nil {
72
+ t .Errorf ("unexpected error: %v" , err )
73
+ }
74
+
75
+ return err
76
+ }
77
+ }
78
+
79
+ func wrapStringHandler (indicator chan bool , handler func (string ) error , t * testing.T ) func (string ) error {
67
80
return func (key string ) error {
68
81
defer func () { indicator <- true }()
69
82
@@ -129,7 +142,7 @@ func TestUpdateNewStyleSecret(t *testing.T) {
129
142
130
143
kubeclient , fakeWatch , controller , informerFactory := controllerSetup ([]runtime.Object {newStyleDockercfgSecret }, t , stopChannel )
131
144
controller .syncRegistryLocationHandler = wrapHandler (received , controller .syncRegistryLocationChange , t )
132
- controller .syncSecretHandler = wrapHandler (updatedSecret , controller .syncSecretUpdate , t )
145
+ controller .syncSecretHandler = wrapStringHandler (updatedSecret , controller .syncSecretUpdate , t )
133
146
informerFactory .Start (stopChannel )
134
147
go controller .Run (5 , stopChannel )
135
148
@@ -139,6 +152,9 @@ func TestUpdateNewStyleSecret(t *testing.T) {
139
152
case <- time .After (time .Duration (45 * time .Second )):
140
153
t .Fatalf ("failed to become ready" )
141
154
}
155
+ if controller .initialSecretsCheckDone != false {
156
+ t .Fatalf ("initialSecretsCheckDone should be false" )
157
+ }
142
158
143
159
fakeWatch .Modify (registryService )
144
160
t .Log ("Waiting to reach syncRegistryLocationHandler" )
@@ -147,6 +163,12 @@ func TestUpdateNewStyleSecret(t *testing.T) {
147
163
case <- time .After (time .Duration (45 * time .Second )):
148
164
t .Fatalf ("failed to call into syncRegistryLocationHandler" )
149
165
}
166
+
167
+ // after this point the secrets should be added to the queue and initial check should be done.
168
+ if controller .initialSecretsCheckDone != true {
169
+ t .Fatalf ("initialSecretsCheckDone should be true" )
170
+ }
171
+
150
172
t .Log ("Waiting to update secret" )
151
173
select {
152
174
case <- updatedSecret :
@@ -216,9 +238,9 @@ func TestUpdateOldStyleSecretWithKey(t *testing.T) {
216
238
Data : map [string ][]byte {v1 .DockerConfigKey : dockercfgContent },
217
239
}
218
240
219
- kubeclient , fakeWatch , controller , informerFactory := controllerSetup ([]runtime.Object {oldStyleDockercfgSecret }, t , stopChannel )
241
+ kubeclient , _ , controller , informerFactory := controllerSetup ([]runtime.Object {registryService , oldStyleDockercfgSecret }, t , stopChannel )
220
242
controller .syncRegistryLocationHandler = wrapHandler (received , controller .syncRegistryLocationChange , t )
221
- controller .syncSecretHandler = wrapHandler (updatedSecret , controller .syncSecretUpdate , t )
243
+ controller .syncSecretHandler = wrapStringHandler (updatedSecret , controller .syncSecretUpdate , t )
222
244
informerFactory .Start (stopChannel )
223
245
go controller .Run (5 , stopChannel )
224
246
@@ -229,8 +251,6 @@ func TestUpdateOldStyleSecretWithKey(t *testing.T) {
229
251
t .Fatalf ("failed to become ready" )
230
252
}
231
253
232
- fakeWatch .Modify (registryService )
233
-
234
254
t .Log ("Waiting to reach syncRegistryLocationHandler" )
235
255
select {
236
256
case <- received :
@@ -309,7 +329,7 @@ func TestUpdateOldStyleSecretWithoutKey(t *testing.T) {
309
329
return true , tokenSecret , nil
310
330
})
311
331
controller .syncRegistryLocationHandler = wrapHandler (received , controller .syncRegistryLocationChange , t )
312
- controller .syncSecretHandler = wrapHandler (updatedSecret , controller .syncSecretUpdate , t )
332
+ controller .syncSecretHandler = wrapStringHandler (updatedSecret , controller .syncSecretUpdate , t )
313
333
informerFactory .Start (stopChannel )
314
334
go controller .Run (5 , stopChannel )
315
335
@@ -400,17 +420,18 @@ func TestClearSecretAndRecreate(t *testing.T) {
400
420
401
421
kubeclient , fakeWatch , controller , informerFactory := controllerSetup ([]runtime.Object {registryService , oldStyleDockercfgSecret }, t , stopChannel )
402
422
controller .syncRegistryLocationHandler = wrapHandler (received , controller .syncRegistryLocationChange , t )
403
- controller .syncSecretHandler = wrapHandler (updatedSecret , controller .syncSecretUpdate , t )
423
+ controller .syncSecretHandler = wrapStringHandler (updatedSecret , controller .syncSecretUpdate , t )
404
424
informerFactory .Start (stopChannel )
405
425
go controller .Run (5 , stopChannel )
406
426
407
427
t .Log ("Waiting for ready" )
408
428
select {
409
429
case <- controller .dockerURLsInitialized :
410
430
case <- time .After (time .Duration (45 * time .Second )):
411
- t .Fatalf ("failed to become ready " )
431
+ t .Fatalf ("failed waiting for dockerURLsInitialized " )
412
432
}
413
433
434
+ t .Logf ("deleting %s service" , registryService .Name )
414
435
fakeWatch .Delete (registryService )
415
436
416
437
t .Log ("Waiting for first update" )
@@ -419,6 +440,7 @@ func TestClearSecretAndRecreate(t *testing.T) {
419
440
case <- time .After (time .Duration (45 * time .Second )):
420
441
t .Fatalf ("failed to call into syncRegistryLocationHandler" )
421
442
}
443
+
422
444
t .Log ("Waiting to update secret" )
423
445
select {
424
446
case <- updatedSecret :
@@ -449,6 +471,8 @@ func TestClearSecretAndRecreate(t *testing.T) {
449
471
}
450
472
451
473
kubeclient .ClearActions ()
474
+
475
+ t .Logf ("adding %s service" , registryService .Name )
452
476
fakeWatch .Add (registryService )
453
477
454
478
t .Log ("Waiting for second update" )
@@ -457,6 +481,7 @@ func TestClearSecretAndRecreate(t *testing.T) {
457
481
case <- time .After (time .Duration (45 * time .Second )):
458
482
t .Fatalf ("failed to call into syncRegistryLocationHandler" )
459
483
}
484
+
460
485
t .Log ("Waiting to update secret" )
461
486
select {
462
487
case <- updatedSecret :
0 commit comments