@@ -27,16 +27,19 @@ func TestEncodeAuth(t *testing.T) {
27
27
}
28
28
29
29
func TestProxyConfig (t * testing.T ) {
30
- httpProxy := "http://proxy.mycorp.example.com:3128"
31
- httpsProxy := "https://user:password@proxy.mycorp.example.com:3129"
32
- ftpProxy := "http://ftpproxy.mycorp.example.com:21"
33
- noProxy := "*.intra.mycorp.example.com"
34
- defaultProxyConfig := ProxyConfig {
35
- HTTPProxy : httpProxy ,
36
- HTTPSProxy : httpsProxy ,
37
- FTPProxy : ftpProxy ,
38
- NoProxy : noProxy ,
39
- }
30
+ var (
31
+ httpProxy = "http://proxy.mycorp.example.com:3128"
32
+ httpsProxy = "https://user:password@proxy.mycorp.example.com:3129"
33
+ ftpProxy = "http://ftpproxy.mycorp.example.com:21"
34
+ noProxy = "*.intra.mycorp.example.com"
35
+
36
+ defaultProxyConfig = ProxyConfig {
37
+ HTTPProxy : httpProxy ,
38
+ HTTPSProxy : httpsProxy ,
39
+ FTPProxy : ftpProxy ,
40
+ NoProxy : noProxy ,
41
+ }
42
+ )
40
43
41
44
cfg := ConfigFile {
42
45
Proxies : map [string ]ProxyConfig {
@@ -59,18 +62,21 @@ func TestProxyConfig(t *testing.T) {
59
62
}
60
63
61
64
func TestProxyConfigOverride (t * testing.T ) {
62
- httpProxy := "http://proxy.mycorp.example.com:3128"
63
- overrideHTTPProxy := "http://proxy.example.com:3128"
64
- overrideNoProxy := ""
65
- httpsProxy := "https://user:password@proxy.mycorp.example.com:3129"
66
- ftpProxy := "http://ftpproxy.mycorp.example.com:21"
67
- noProxy := "*.intra.mycorp.example.com"
68
- defaultProxyConfig := ProxyConfig {
69
- HTTPProxy : httpProxy ,
70
- HTTPSProxy : httpsProxy ,
71
- FTPProxy : ftpProxy ,
72
- NoProxy : noProxy ,
73
- }
65
+ var (
66
+ httpProxy = "http://proxy.mycorp.example.com:3128"
67
+ httpProxyOverride = "http://proxy.example.com:3128"
68
+ httpsProxy = "https://user:password@proxy.mycorp.example.com:3129"
69
+ ftpProxy = "http://ftpproxy.mycorp.example.com:21"
70
+ noProxy = "*.intra.mycorp.example.com"
71
+ noProxyOverride = ""
72
+
73
+ defaultProxyConfig = ProxyConfig {
74
+ HTTPProxy : httpProxy ,
75
+ HTTPSProxy : httpsProxy ,
76
+ FTPProxy : ftpProxy ,
77
+ NoProxy : noProxy ,
78
+ }
79
+ )
74
80
75
81
cfg := ConfigFile {
76
82
Proxies : map [string ]ProxyConfig {
@@ -84,46 +90,49 @@ func TestProxyConfigOverride(t *testing.T) {
84
90
}
85
91
86
92
ropts := map [string ]* string {
87
- "HTTP_PROXY" : clone (overrideHTTPProxy ),
88
- "NO_PROXY" : clone (overrideNoProxy ),
93
+ "HTTP_PROXY" : clone (httpProxyOverride ),
94
+ "NO_PROXY" : clone (noProxyOverride ),
89
95
}
90
96
proxyConfig := cfg .ParseProxyConfig ("/var/run/docker.sock" , ropts )
91
97
expected := map [string ]* string {
92
- "HTTP_PROXY" : & overrideHTTPProxy ,
98
+ "HTTP_PROXY" : & httpProxyOverride ,
93
99
"http_proxy" : & httpProxy ,
94
100
"HTTPS_PROXY" : & httpsProxy ,
95
101
"https_proxy" : & httpsProxy ,
96
102
"FTP_PROXY" : & ftpProxy ,
97
103
"ftp_proxy" : & ftpProxy ,
98
- "NO_PROXY" : & overrideNoProxy ,
104
+ "NO_PROXY" : & noProxyOverride ,
99
105
"no_proxy" : & noProxy ,
100
106
}
101
107
assert .Check (t , is .DeepEqual (expected , proxyConfig ))
102
108
}
103
109
104
110
func TestProxyConfigPerHost (t * testing.T ) {
105
- httpProxy := "http://proxy.mycorp.example.com:3128"
106
- httpsProxy := "https://user:password@proxy.mycorp.example.com:3129"
107
- ftpProxy := "http://ftpproxy.mycorp.example.com:21"
108
- noProxy := "*.intra.mycorp.example.com"
109
-
110
- extHTTPProxy := "http://proxy.example.com:3128"
111
- extHTTPSProxy := "https://user:password@proxy.example.com:3129"
112
- extFTPProxy := "http://ftpproxy.example.com:21"
113
- extNoProxy := "*.intra.example.com"
114
-
115
- defaultProxyConfig := ProxyConfig {
116
- HTTPProxy : httpProxy ,
117
- HTTPSProxy : httpsProxy ,
118
- FTPProxy : ftpProxy ,
119
- NoProxy : noProxy ,
120
- }
121
- externalProxyConfig := ProxyConfig {
122
- HTTPProxy : extHTTPProxy ,
123
- HTTPSProxy : extHTTPSProxy ,
124
- FTPProxy : extFTPProxy ,
125
- NoProxy : extNoProxy ,
126
- }
111
+ var (
112
+ httpProxy = "http://proxy.mycorp.example.com:3128"
113
+ httpsProxy = "https://user:password@proxy.mycorp.example.com:3129"
114
+ ftpProxy = "http://ftpproxy.mycorp.example.com:21"
115
+ noProxy = "*.intra.mycorp.example.com"
116
+
117
+ extHTTPProxy = "http://proxy.example.com:3128"
118
+ extHTTPSProxy = "https://user:password@proxy.example.com:3129"
119
+ extFTPProxy = "http://ftpproxy.example.com:21"
120
+ extNoProxy = "*.intra.example.com"
121
+
122
+ defaultProxyConfig = ProxyConfig {
123
+ HTTPProxy : httpProxy ,
124
+ HTTPSProxy : httpsProxy ,
125
+ FTPProxy : ftpProxy ,
126
+ NoProxy : noProxy ,
127
+ }
128
+
129
+ externalProxyConfig = ProxyConfig {
130
+ HTTPProxy : extHTTPProxy ,
131
+ HTTPSProxy : extHTTPSProxy ,
132
+ FTPProxy : extFTPProxy ,
133
+ NoProxy : extNoProxy ,
134
+ }
135
+ )
127
136
128
137
cfg := ConfigFile {
129
138
Proxies : map [string ]ProxyConfig {
@@ -226,9 +235,11 @@ func TestGetAllCredentialsCredsStore(t *testing.T) {
226
235
}
227
236
228
237
func TestGetAllCredentialsCredHelper (t * testing.T ) {
229
- testCredHelperSuffix := "test_cred_helper"
230
- testCredHelperRegistryHostname := "credhelper.com"
231
- testExtraCredHelperRegistryHostname := "somethingweird.com"
238
+ const (
239
+ testCredHelperSuffix = "test_cred_helper"
240
+ testCredHelperRegistryHostname = "credhelper.com"
241
+ testExtraCredHelperRegistryHostname = "somethingweird.com"
242
+ )
232
243
233
244
unexpectedCredHelperAuth := types.AuthConfig {
234
245
Username : "file_store_user" ,
@@ -265,9 +276,11 @@ func TestGetAllCredentialsCredHelper(t *testing.T) {
265
276
}
266
277
267
278
func TestGetAllCredentialsFileStoreAndCredHelper (t * testing.T ) {
268
- testFileStoreRegistryHostname := "example.com"
269
- testCredHelperSuffix := "test_cred_helper"
270
- testCredHelperRegistryHostname := "credhelper.com"
279
+ const (
280
+ testFileStoreRegistryHostname = "example.com"
281
+ testCredHelperSuffix = "test_cred_helper"
282
+ testCredHelperRegistryHostname = "credhelper.com"
283
+ )
271
284
272
285
expectedFileStoreAuth := types.AuthConfig {
273
286
Username : "file_store_user" ,
@@ -301,10 +314,12 @@ func TestGetAllCredentialsFileStoreAndCredHelper(t *testing.T) {
301
314
}
302
315
303
316
func TestGetAllCredentialsCredStoreAndCredHelper (t * testing.T ) {
304
- testCredStoreSuffix := "test_creds_store"
305
- testCredStoreRegistryHostname := "credstore.com"
306
- testCredHelperSuffix := "test_cred_helper"
307
- testCredHelperRegistryHostname := "credhelper.com"
317
+ const (
318
+ testCredStoreSuffix = "test_creds_store"
319
+ testCredStoreRegistryHostname = "credstore.com"
320
+ testCredHelperSuffix = "test_cred_helper"
321
+ testCredHelperRegistryHostname = "credhelper.com"
322
+ )
308
323
309
324
configFile := New ("filename" )
310
325
configFile .CredentialsStore = testCredStoreSuffix
@@ -343,9 +358,11 @@ func TestGetAllCredentialsCredStoreAndCredHelper(t *testing.T) {
343
358
}
344
359
345
360
func TestGetAllCredentialsCredHelperOverridesDefaultStore (t * testing.T ) {
346
- testCredStoreSuffix := "test_creds_store"
347
- testCredHelperSuffix := "test_cred_helper"
348
- testRegistryHostname := "example.com"
361
+ const (
362
+ testCredStoreSuffix = "test_creds_store"
363
+ testCredHelperSuffix = "test_cred_helper"
364
+ testRegistryHostname = "example.com"
365
+ )
349
366
350
367
configFile := New ("filename" )
351
368
configFile .CredentialsStore = testCredStoreSuffix
@@ -424,38 +441,36 @@ func TestCheckKubernetesConfigurationRaiseAnErrorOnInvalidValue(t *testing.T) {
424
441
expectError bool
425
442
}{
426
443
{
427
- "no kubernetes config is valid" ,
428
- nil ,
429
- false ,
444
+ name : "no kubernetes config is valid" ,
430
445
},
431
446
{
432
- "enabled is valid" ,
433
- & KubernetesConfig {AllNamespaces : "enabled" },
434
- false ,
447
+ name : "enabled is valid" ,
448
+ config : & KubernetesConfig {AllNamespaces : "enabled" },
435
449
},
436
450
{
437
- "disabled is valid" ,
438
- & KubernetesConfig {AllNamespaces : "disabled" },
439
- false ,
451
+ name : "disabled is valid" ,
452
+ config : & KubernetesConfig {AllNamespaces : "disabled" },
440
453
},
441
454
{
442
- "empty string is valid" ,
443
- & KubernetesConfig {AllNamespaces : "" },
444
- false ,
455
+ name : "empty string is valid" ,
456
+ config : & KubernetesConfig {AllNamespaces : "" },
445
457
},
446
458
{
447
- "other value is invalid" ,
448
- & KubernetesConfig {AllNamespaces : "unknown" },
449
- true ,
459
+ name : "other value is invalid" ,
460
+ config : & KubernetesConfig {AllNamespaces : "unknown" },
461
+ expectError : true ,
450
462
},
451
463
}
452
- for _ , test := range testCases {
453
- err := checkKubernetesConfiguration (test .config )
454
- if test .expectError {
455
- assert .Assert (t , err != nil , test .name )
456
- } else {
457
- assert .NilError (t , err , test .name )
458
- }
464
+ for _ , tc := range testCases {
465
+ test := tc
466
+ t .Run (test .name , func (t * testing.T ) {
467
+ err := checkKubernetesConfiguration (test .config )
468
+ if test .expectError {
469
+ assert .Assert (t , err != nil , test .name )
470
+ } else {
471
+ assert .NilError (t , err , test .name )
472
+ }
473
+ })
459
474
}
460
475
}
461
476
0 commit comments