@@ -191,11 +191,12 @@ func TestRetainClusterIPInServiceFields(t *testing.T) {
191
191
192
192
func TestRetainServiceAccountFields (t * testing.T ) {
193
193
tests := []struct {
194
- name string
195
- desiredObj * unstructured.Unstructured
196
- observedObj * unstructured.Unstructured
197
- expectedErr bool
198
- expectedSecretsValue []interface {}
194
+ name string
195
+ desiredObj * unstructured.Unstructured
196
+ observedObj * unstructured.Unstructured
197
+ expectedErr bool
198
+ expectedSecretsValue []interface {}
199
+ expectedImagePullSecretsValue []interface {}
199
200
}{
200
201
{
201
202
name : "neither desired or observed service account has the secrets field" ,
@@ -234,6 +235,7 @@ func TestRetainServiceAccountFields(t *testing.T) {
234
235
"name" : "test" ,
235
236
},
236
237
},
238
+ expectedImagePullSecretsValue : nil ,
237
239
},
238
240
{
239
241
name : "desired and observed service account have the different secrets field" ,
@@ -267,6 +269,44 @@ func TestRetainServiceAccountFields(t *testing.T) {
267
269
"name" : "test-token" ,
268
270
},
269
271
},
272
+ expectedImagePullSecretsValue : nil ,
273
+ },
274
+ {
275
+ name : "observed service account has the imagePullSecrets field but the desired not" ,
276
+ desiredObj : & unstructured.Unstructured {
277
+ Object : map [string ]interface {}{
278
+ "secrets" : []interface {}{
279
+ map [string ]interface {}{
280
+ "name" : "test" ,
281
+ },
282
+ },
283
+ },
284
+ },
285
+ observedObj : & unstructured.Unstructured {
286
+ Object : map [string ]interface {}{
287
+ "secrets" : []interface {}{
288
+ map [string ]interface {}{
289
+ "name" : "test" ,
290
+ },
291
+ },
292
+ "imagePullSecrets" : []interface {}{
293
+ map [string ]interface {}{
294
+ "name" : "foo" ,
295
+ },
296
+ },
297
+ },
298
+ },
299
+ expectedErr : false ,
300
+ expectedSecretsValue : []interface {}{
301
+ map [string ]interface {}{
302
+ "name" : "test" ,
303
+ },
304
+ },
305
+ expectedImagePullSecretsValue : []interface {}{
306
+ map [string ]interface {}{
307
+ "name" : "foo" ,
308
+ },
309
+ },
270
310
},
271
311
}
272
312
for _ , test := range tests {
@@ -277,15 +317,26 @@ func TestRetainServiceAccountFields(t *testing.T) {
277
317
}
278
318
279
319
if err == nil {
280
- currentSecretValue , ok , err := unstructured .NestedSlice (desiredObj .Object , SecretsField )
281
- if err != nil {
282
- t .Fatalf ("failed to get the secrets field from the serviceaccount, err is: %v" , err )
320
+ table := []struct {
321
+ name string
322
+ field string
323
+ expectedValue []interface {}
324
+ }{
325
+ {name : "secrets" , field : SecretsField , expectedValue : test .expectedSecretsValue },
326
+ {name : "imagePullSecrets" , field : ImagePullSecretsField , expectedValue : test .expectedImagePullSecretsValue },
283
327
}
284
- if ! ok && test .expectedSecretsValue != nil {
285
- t .Fatalf ("expect specified secrets %s but not found" , test .expectedSecretsValue )
286
- }
287
- if ok && ! reflect .DeepEqual (test .expectedSecretsValue , currentSecretValue ) {
288
- t .Fatalf ("expect specified secrets %s but get %s" , test .expectedSecretsValue , currentSecretValue )
328
+
329
+ for _ , entry := range table {
330
+ currentValue , ok , err := unstructured .NestedSlice (desiredObj .Object , entry .field )
331
+ if err != nil {
332
+ t .Fatalf ("failed to get %q field from serviceaccount: %v" , entry .name , err )
333
+ }
334
+ if ! ok && entry .expectedValue != nil {
335
+ t .Fatalf ("expected %q %v but not found" , entry .name , entry .expectedValue )
336
+ }
337
+ if ok && ! reflect .DeepEqual (entry .expectedValue , currentValue ) {
338
+ t .Fatalf ("unexpected %q: got %v, want %v" , entry .name , currentValue , entry .expectedValue )
339
+ }
289
340
}
290
341
}
291
342
})
0 commit comments