@@ -104,19 +104,19 @@ func newRouteLister(t *testing.T, routes ...*routev1.Route) routev1listers.Route
104
104
return routev1listers .NewRouteLister (routeIndexer )
105
105
}
106
106
107
- func newTestOAuthsClientsController (t * testing.T ) * oauthsClientsController {
107
+ func newTestOAuthsClientsController (t * testing.T ) (* oauthsClientsController , cache.Indexer ) {
108
+ indexer := cache .NewIndexer (cache .MetaNamespaceKeyFunc , cache.Indexers {})
108
109
return & oauthsClientsController {
109
110
oauthClientClient : fakeoauthclient .NewSimpleClientset ().OauthV1 ().OAuthClients (),
110
- oauthClientLister : oauthv1listers .NewOAuthClientLister (cache . NewIndexer ( cache . MetaNamespaceKeyFunc , cache. Indexers {}) ),
111
+ oauthClientLister : oauthv1listers .NewOAuthClientLister (indexer ),
111
112
routeLister : newRouteLister (t , defaultRoute ),
112
113
ingressLister : newIngressLister (t , defaultIngress ),
113
- }
114
+ }, indexer
114
115
}
115
116
116
117
func Test_sync (t * testing.T ) {
117
118
ctx := context .TODO ()
118
119
syncCtx := & fakeSyncContext {}
119
- c := newTestOAuthsClientsController (t )
120
120
121
121
tests := []struct {
122
122
name string
@@ -133,6 +133,7 @@ func Test_sync(t *testing.T) {
133
133
134
134
for _ , tt := range tests {
135
135
t .Run (tt .name , func (t * testing.T ) {
136
+ c , _ := newTestOAuthsClientsController (t )
136
137
if tt .withIngressLister != nil {
137
138
c .ingressLister = tt .withIngressLister
138
139
}
@@ -150,7 +151,7 @@ func Test_sync(t *testing.T) {
150
151
}
151
152
152
153
func Test_getIngressConfig (t * testing.T ) {
153
- c := newTestOAuthsClientsController (t )
154
+ c , _ := newTestOAuthsClientsController (t )
154
155
155
156
tests := []struct {
156
157
name string
@@ -193,7 +194,7 @@ func Test_getCanonicalRouteHost(t *testing.T) {
193
194
{"namespace-not-found" , masterPublicURL , "not-openshift-authentication" , "oauth-openshift" , "" , true },
194
195
}
195
196
196
- c := newTestOAuthsClientsController (t )
197
+ c , _ := newTestOAuthsClientsController (t )
197
198
198
199
for _ , tt := range tests {
199
200
t .Run (tt .host , func (t * testing.T ) {
@@ -219,7 +220,7 @@ func Test_ensureBootstrappedOAuthClients(t *testing.T) {
219
220
ctx := context .TODO ()
220
221
221
222
t .Run ("bootstrapped-oauth-clients-succeed" , func (t * testing.T ) {
222
- c := newTestOAuthsClientsController (t )
223
+ c , _ := newTestOAuthsClientsController (t )
223
224
224
225
if err := c .ensureBootstrappedOAuthClients (ctx , masterPublicURL ); err != nil {
225
226
t .Errorf ("got unexpected error: %v" , err )
@@ -232,7 +233,7 @@ func Test_ensureBootstrappedOAuthClients(t *testing.T) {
232
233
return true , nil , fmt .Errorf ("%s %s fake error" , action .GetVerb (), action .GetResource ().Resource )
233
234
})
234
235
235
- c := newTestOAuthsClientsController (t )
236
+ c , _ := newTestOAuthsClientsController (t )
236
237
c .oauthClientClient = fakeClientset .OauthV1 ().OAuthClients ()
237
238
238
239
if err := c .ensureBootstrappedOAuthClients (ctx , masterPublicURL ); err == nil {
@@ -277,6 +278,7 @@ func Test_ensureOAuthClient(t *testing.T) {
277
278
updateOAuthClient * oauthv1.OAuthClient
278
279
oauthClientClient * fakeoauthclient.Clientset
279
280
281
+ alreadyExists bool
280
282
wantEnsureErr bool
281
283
wantUpdateErr bool
282
284
}{
@@ -406,6 +408,7 @@ func Test_ensureOAuthClient(t *testing.T) {
406
408
},
407
409
},
408
410
oauthClientClient : newFakeOAuthClientClient (nil ),
411
+ alreadyExists : true ,
409
412
},
410
413
{
411
414
name : "valid-oauth-client-when-already-exists-with-updates" ,
@@ -428,6 +431,7 @@ func Test_ensureOAuthClient(t *testing.T) {
428
431
},
429
432
},
430
433
oauthClientClient : newFakeOAuthClientClient (nil ),
434
+ alreadyExists : true ,
431
435
},
432
436
{
433
437
name : "valid-oauth-client-when-already-exists-with-updated-empty-secret" ,
@@ -440,6 +444,7 @@ func Test_ensureOAuthClient(t *testing.T) {
440
444
Secret : "" ,
441
445
},
442
446
oauthClientClient : newFakeOAuthClientClient (nil ),
447
+ alreadyExists : true ,
443
448
},
444
449
{
445
450
name : "valid-oauth-client-when-already-exists-with-updated-new-secret" ,
@@ -451,6 +456,7 @@ func Test_ensureOAuthClient(t *testing.T) {
451
456
Secret : "secret" ,
452
457
},
453
458
oauthClientClient : newFakeOAuthClientClient (nil ),
459
+ alreadyExists : true ,
454
460
},
455
461
{
456
462
name : "valid-oauth-client-when-already-exists-with-updated-longer-secret" ,
@@ -463,6 +469,7 @@ func Test_ensureOAuthClient(t *testing.T) {
463
469
Secret : "secretbutlonger" ,
464
470
},
465
471
oauthClientClient : newFakeOAuthClientClient (nil ),
472
+ alreadyExists : true ,
466
473
},
467
474
{
468
475
name : "valid-oauth-client-when-already-exists-with-updated-same-length-secret" ,
@@ -498,16 +505,26 @@ func Test_ensureOAuthClient(t *testing.T) {
498
505
t .SkipNow ()
499
506
}
500
507
501
- c := newTestOAuthsClientsController (t )
508
+ c , indexer := newTestOAuthsClientsController (t )
502
509
c .oauthClientClient = tt .oauthClientClient .OauthV1 ().OAuthClients ()
503
510
504
- err := ensureOAuthClient (ctx , c .oauthClientClient , * tt .oauthClient )
511
+ if tt .alreadyExists && tt .oauthClient != nil {
512
+ _ , err := c .oauthClientClient .Create (ctx , tt .oauthClient , metav1.CreateOptions {})
513
+ if err != nil {
514
+ t .Fatalf ("got unexpected err when creating in fake clientset: %v" , err )
515
+ }
516
+ if err := indexer .Add (tt .oauthClient ); err != nil {
517
+ t .Fatalf ("got unexpected err when adding to lister indexer: %v" , err )
518
+ }
519
+ }
520
+
521
+ err := c .ensureOAuthClient (ctx , * tt .oauthClient )
505
522
if (err != nil ) != tt .wantEnsureErr {
506
523
t .Fatalf ("got error: %v; want error: %v" , err , tt .wantEnsureErr )
507
524
}
508
525
509
526
if tt .updateOAuthClient != nil {
510
- updateErr := ensureOAuthClient (ctx , c . oauthClientClient , * tt .updateOAuthClient )
527
+ updateErr := c . ensureOAuthClient (ctx , * tt .updateOAuthClient )
511
528
if (updateErr != nil ) != tt .wantUpdateErr {
512
529
t .Fatalf ("got error: %v; want error: %v" , updateErr , tt .wantUpdateErr )
513
530
}
0 commit comments