@@ -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 :
@@ -218,7 +240,7 @@ func TestUpdateOldStyleSecretWithKey(t *testing.T) {
218
240
219
241
kubeclient , fakeWatch , controller , informerFactory := controllerSetup ([]runtime.Object {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
@@ -309,7 +331,7 @@ func TestUpdateOldStyleSecretWithoutKey(t *testing.T) {
309
331
return true , tokenSecret , nil
310
332
})
311
333
controller .syncRegistryLocationHandler = wrapHandler (received , controller .syncRegistryLocationChange , t )
312
- controller .syncSecretHandler = wrapHandler (updatedSecret , controller .syncSecretUpdate , t )
334
+ controller .syncSecretHandler = wrapStringHandler (updatedSecret , controller .syncSecretUpdate , t )
313
335
informerFactory .Start (stopChannel )
314
336
go controller .Run (5 , stopChannel )
315
337
@@ -400,17 +422,18 @@ func TestClearSecretAndRecreate(t *testing.T) {
400
422
401
423
kubeclient , fakeWatch , controller , informerFactory := controllerSetup ([]runtime.Object {registryService , oldStyleDockercfgSecret }, t , stopChannel )
402
424
controller .syncRegistryLocationHandler = wrapHandler (received , controller .syncRegistryLocationChange , t )
403
- controller .syncSecretHandler = wrapHandler (updatedSecret , controller .syncSecretUpdate , t )
425
+ controller .syncSecretHandler = wrapStringHandler (updatedSecret , controller .syncSecretUpdate , t )
404
426
informerFactory .Start (stopChannel )
405
427
go controller .Run (5 , stopChannel )
406
428
407
429
t .Log ("Waiting for ready" )
408
430
select {
409
431
case <- controller .dockerURLsInitialized :
410
432
case <- time .After (time .Duration (45 * time .Second )):
411
- t .Fatalf ("failed to become ready " )
433
+ t .Fatalf ("failed waiting for dockerURLsInitialized " )
412
434
}
413
435
436
+ t .Logf ("deleting %s service" , registryService .Name )
414
437
fakeWatch .Delete (registryService )
415
438
416
439
t .Log ("Waiting for first update" )
@@ -419,6 +442,7 @@ func TestClearSecretAndRecreate(t *testing.T) {
419
442
case <- time .After (time .Duration (45 * time .Second )):
420
443
t .Fatalf ("failed to call into syncRegistryLocationHandler" )
421
444
}
445
+
422
446
t .Log ("Waiting to update secret" )
423
447
select {
424
448
case <- updatedSecret :
@@ -449,6 +473,8 @@ func TestClearSecretAndRecreate(t *testing.T) {
449
473
}
450
474
451
475
kubeclient .ClearActions ()
476
+
477
+ t .Logf ("adding %s service" , registryService .Name )
452
478
fakeWatch .Add (registryService )
453
479
454
480
t .Log ("Waiting for second update" )
@@ -457,6 +483,7 @@ func TestClearSecretAndRecreate(t *testing.T) {
457
483
case <- time .After (time .Duration (45 * time .Second )):
458
484
t .Fatalf ("failed to call into syncRegistryLocationHandler" )
459
485
}
486
+
460
487
t .Log ("Waiting to update secret" )
461
488
select {
462
489
case <- updatedSecret :
0 commit comments