@@ -67,47 +67,56 @@ registries:
6767 bearer: fixtures/example_secret
6868`
6969
70- expectedGVR := schema.GroupVersionResource {
71- Group : "" ,
72- Version : "v1" ,
73- Resource : "pods" , // should use pods even if other gvr set
74- }
75-
76- expectedExcludeNamespaces := []string {"kube-system" }
77- expectedIncludeNamespaces := []string {"default" }
78-
7970 cfg := Config {}
8071 err := yaml .Unmarshal ([]byte (textCfg ), & cfg )
8172 if err != nil {
8273 t .Fatalf ("unexpected error: %+v" , err )
8374 }
8475
85- if got , want := cfg .Dynamic .KubeConfigPath , "/home/someone/.kube/config" ; got != want {
86- t .Errorf ("KubeConfigPath does not match: got=%q; want=%q" , got , want )
87- }
88-
89- if got , want := cfg .Dynamic .GroupVersionResource , expectedGVR ; ! reflect .DeepEqual (got , want ) {
90- t .Errorf ("GroupVersionResource does not match: got=%+v want=%+v" , got , want )
91- }
92-
93- if got , want := cfg .Dynamic .ExcludeNamespaces , expectedExcludeNamespaces ; ! reflect .DeepEqual (got , want ) {
94- t .Errorf ("ExcludeNamespaces does not match: got=%+v want=%+v" , got , want )
76+ tests := map [string ]struct {
77+ configTarget interface {}
78+ expTarget interface {}
79+ }{
80+ "KubeConfigPath" : {
81+ configTarget : cfg .Dynamic .KubeConfigPath ,
82+ expTarget : "/home/someone/.kube/config" ,
83+ },
84+ "GVR" : {
85+ configTarget : cfg .Dynamic .GroupVersionResource ,
86+ expTarget : schema.GroupVersionResource {
87+ Group : "" ,
88+ Version : "v1" ,
89+ Resource : "pods" , // should use pods even if other gvr set
90+ },
91+ },
92+ "IncludeNamespaces" : {
93+ configTarget : cfg .Dynamic .IncludeNamespaces ,
94+ expTarget : []string {"default" },
95+ },
96+ "ExcludeNamespaces" : {
97+ configTarget : cfg .Dynamic .ExcludeNamespaces ,
98+ expTarget : []string {"kube-system" },
99+ },
100+ "GCR Token" : {
101+ configTarget : cfg .VersionCheckerClientOptions .GCR .Token ,
102+ expTarget : "pa55w0rd" ,
103+ },
104+ "self hosted password" : {
105+ configTarget : cfg .VersionCheckerClientOptions .Selfhosted ["example.com" ].Password ,
106+ expTarget : "pa55w0rd" ,
107+ },
108+ "self hosted bearer" : {
109+ configTarget : cfg .VersionCheckerClientOptions .Selfhosted ["example.net" ].Bearer ,
110+ expTarget : "pa55w0rd" ,
111+ },
95112 }
96113
97- if got , want := cfg .Dynamic .IncludeNamespaces , expectedIncludeNamespaces ; ! reflect .DeepEqual (got , want ) {
98- t .Errorf ("IncludeNamespaces does not match: got=%+v want=%+v" , got , want )
99- }
100-
101- if got , want := cfg .VersionCheckerClientOptions .GCR .Token , "pa55w0rd" ; got != want {
102- t .Errorf ("GCR token does not match: got=%+v want=%+v" , got , want )
103- }
104-
105- if got , want := cfg .VersionCheckerClientOptions .Selfhosted ["example.com" ].Password , "pa55w0rd" ; got != want {
106- t .Errorf ("Selfhosted 6 password does not match: got=%+v want=%+v" , got , want )
107- }
108-
109- if got , want := cfg .VersionCheckerClientOptions .Selfhosted ["example.net" ].Bearer , "pa55w0rd" ; got != want {
110- t .Errorf ("Selfhosted 7 bearer does not match: got=%+v want=%+v" , got , want )
114+ for name , test := range tests {
115+ t .Run (name , func (t * testing.T ) {
116+ if ! reflect .DeepEqual (test .configTarget , test .expTarget ) {
117+ t .Errorf ("unexpected config target: got=%q; want=%q" , test .configTarget , test .expTarget )
118+ }
119+ })
111120 }
112121}
113122
0 commit comments