@@ -33,7 +33,7 @@ func Test_readCredentialProviderConfigFile(t *testing.T) {
33
33
name string
34
34
configData string
35
35
config * kubeletconfig.CredentialProviderConfig
36
- expectErr bool
36
+ expectErr string
37
37
}{
38
38
{
39
39
name : "config with 1 plugin and 1 image matcher" ,
@@ -293,7 +293,7 @@ providers:
293
293
- name: FOO
294
294
value: BAR` ,
295
295
config : nil ,
296
- expectErr : true ,
296
+ expectErr : `no kind "WrongKind" is registered for version "kubelet.config.k8s.io/v1alpha1"` ,
297
297
},
298
298
{
299
299
name : "config with wrong apiversion" ,
@@ -312,7 +312,27 @@ providers:
312
312
- name: FOO
313
313
value: BAR` ,
314
314
config : nil ,
315
- expectErr : true ,
315
+ expectErr : `no kind "CredentialProviderConfig" is registered for version "foobar/v1alpha1` ,
316
+ },
317
+ {
318
+ name : "config with invalid typo" ,
319
+ configData : `---
320
+ kind: CredentialProviderConfig
321
+ apiVersion: kubelet.config.k8s.io/v1
322
+ providers:
323
+ - name: test
324
+ matchImages:
325
+ - "registry.io/foobar"
326
+ defaultCacheDuration: 10m
327
+ unknownField: should not be here # this field should not be here
328
+ apiVersion: credentialprovider.kubelet.k8s.io/v1alpha1
329
+ args:
330
+ - --v=5
331
+ env:
332
+ - name: FOO
333
+ value: BAR` ,
334
+ config : nil ,
335
+ expectErr : `strict decoding error: unknown field "providers[0].unknownField"` ,
316
336
},
317
337
}
318
338
@@ -330,12 +350,12 @@ providers:
330
350
}
331
351
332
352
authConfig , err := readCredentialProviderConfigFile (file .Name ())
333
- if err != nil && ! testcase .expectErr {
353
+ if err != nil && len ( testcase .expectErr ) == 0 {
334
354
t .Fatal (err )
335
355
}
336
356
337
- if err == nil && testcase .expectErr {
338
- t .Error ("expected error but got none" )
357
+ if err == nil && len ( testcase .expectErr ) > 0 {
358
+ t .Fatalf ("expected error %q but got none" , testcase . expectErr )
339
359
}
340
360
341
361
if ! reflect .DeepEqual (authConfig , testcase .config ) {
@@ -521,7 +541,6 @@ func Test_validateCredentialProviderConfig(t *testing.T) {
521
541
t .Errorf ("expected error but got none" )
522
542
} else if ! testcase .shouldErr && len (errs ) > 0 {
523
543
t .Errorf ("expected no error but received errors: %v" , errs .ToAggregate ())
524
-
525
544
}
526
545
})
527
546
}
0 commit comments