Skip to content

Commit b6a510f

Browse files
committed
fix: resolve linting issues in SSL proxy tests
- Fix import shadow issue by renaming variable from 'config' to 'cfg' - Fix unused parameter issue by replacing 'showVersion' with '_' - Ensure all validation functions use consistent parameter naming - Maintain test functionality while satisfying golangci-lint requirements All tests continue to pass with enhanced SSL proxy coverage.
1 parent b25f95d commit b6a510f

File tree

1 file changed

+96
-11
lines changed

1 file changed

+96
-11
lines changed

pkg/flags/flags_test.go

Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,92 @@
11
/*
22
Copyright 2017 The Kubernetes Authors.
33
4-
Licensed under the Apache License, Version 2.0 (the "License");
4+
Licensed under the Apac {
5+
name: "valid {
6+
name: " {
7+
name: "SSL proxy wi {
8+
name: "SSL proxy wi {
9+
name: "SSL proxy wi {
10+
name: "SSL proxy with minimal configuration",
11+
args: []string{"cmd", "--enable-ssl-passthrough"},
12+
expectError: false,
13+
description: "Should work with minimal SSL passthrough configuration using default port",
14+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
15+
if !cfg.EnableSSLPassthrough {
16+
t.Error("Expected EnableSSLPassthrough to be true")
17+
}
18+
// Default port should be 442
19+
if cfg.ListenPorts.SSLProxy != 442 {
20+
t.Errorf("Expected default SSLProxy port to be 442, got %d", cfg.ListenPorts.SSLProxy)
21+
}
22+
},
23+
},tion enabled",
24+
args: []string{"cmd", "--enable-ssl-passthrough", "--enable-ssl-chain-completion", "--ssl-passthrough-proxy-port", "7443"},
25+
expectError: false,
26+
description: "Should work with SSL chain completion and passthrough",
27+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
28+
if !cfg.EnableSSLPassthrough {
29+
t.Error("Expected EnableSSLPassthrough to be true")
30+
}
31+
if !config.EnableSSLChainCompletion {
32+
t.Error("Expected EnableSSLChainCompletion to be true")
33+
}
34+
if cfg.ListenPorts.SSLProxy != 7443 {
35+
t.Errorf("Expected SSLProxy port to be 7443, got %d", cfg.ListenPorts.SSLProxy)
36+
}
37+
},
38+
},rtificate",
39+
args: []string{"cmd", "--enable-ssl-passthrough", "--default-ssl-certificate", "default/tls-cert", "--ssl-passthrough-proxy-port", "8080"},
40+
expectError: false,
41+
description: "Should work with default SSL certificate and passthrough",
42+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
43+
if !cfg.EnableSSLPassthrough {
44+
t.Error("Expected EnableSSLPassthrough to be true")
45+
}
46+
if cfg.DefaultSSLCertificate != "default/tls-cert" {
47+
t.Errorf("Expected DefaultSSLCertificate to be 'default/tls-cert', got %s", cfg.DefaultSSLCertificate)
48+
}
49+
if cfg.ListenPorts.SSLProxy != 8080 {
50+
t.Errorf("Expected SSLProxy port to be 8080, got %d", cfg.ListenPorts.SSLProxy)
51+
}
52+
},
53+
},d service",
54+
args: []string{"cmd", "--enable-ssl-passthrough", "--default-backend-service", "default/backend", "--ssl-passthrough-proxy-port", "9000"},
55+
expectError: false,
56+
description: "Should work with default backend service and SSL passthrough",
57+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
58+
if !cfg.EnableSSLPassthrough {
59+
t.Error("Expected EnableSSLPassthrough to be true")
60+
}
61+
if cfg.DefaultService != "default/backend" {
62+
t.Errorf("Expected DefaultService to be 'default/backend', got %s", cfg.DefaultService)
63+
}
64+
if cfg.ListenPorts.SSLProxy != 9000 {
65+
t.Errorf("Expected SSLProxy port to be 9000, got %d", cfg.ListenPorts.SSLProxy)
66+
}
67+
},
68+
},thout explicit passthrough enabling",
69+
args: []string{"cmd", "--ssl-passthrough-proxy-port", "8443"},
70+
expectError: false,
71+
description: "Should accept SSL proxy port configuration without explicit passthrough enable",
72+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
73+
if cfg.ListenPorts.SSLProxy != 8443 {
74+
t.Errorf("Expected SSLProxy port to be 8443, got %d", cfg.ListenPorts.SSLProxy)
75+
}
76+
},
77+
},onfiguration with passthrough enabled",
78+
args: []string{"cmd", "--enable-ssl-passthrough", "--ssl-passthrough-proxy-port", "9999"},
79+
expectError: false,
80+
description: "Should accept valid SSL proxy port with passthrough enabled",
81+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
82+
if !cfg.EnableSSLPassthrough {
83+
t.Error("Expected EnableSSLPassthrough to be true")
84+
}
85+
if cfg.ListenPorts.SSLProxy != 9999 {
86+
t.Errorf("Expected SSLProxy port to be 9999, got %d", cfg.ListenPorts.SSLProxy)
87+
}
88+
},
89+
}, func(t *testing.T, _ bool, cfg *controller.Configuration)e License, Version 2.0 (the "License");
590
you may not use this file except in compliance with the License.
691
You may obtain a copy of the License at
792
@@ -64,14 +149,14 @@ func TestSetupSSLProxy(t *testing.T) {
64149
args []string
65150
expectError bool
66151
description string
67-
validateConfig func(t *testing.T, showVersion bool, config *controller.Configuration)
152+
validateConfig func(t *testing.T, _ bool, cfg *controller.Configuration)
68153
}{
69154
{
70155
name: "valid SSL proxy configuration with passthrough enabled",
71156
args: []string{"cmd", "--enable-ssl-passthrough", "--ssl-passthrough-proxy-port", "9999"},
72157
expectError: false,
73158
description: "Should accept valid SSL proxy port with passthrough enabled",
74-
validateConfig: func(t *testing.T, showVersion bool, cfg *controller.Configuration) {
159+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
75160
if !cfg.EnableSSLPassthrough {
76161
t.Error("Expected EnableSSLPassthrough to be true")
77162
}
@@ -85,7 +170,7 @@ func TestSetupSSLProxy(t *testing.T) {
85170
args: []string{"cmd", "--ssl-passthrough-proxy-port", "8443"},
86171
expectError: false,
87172
description: "Should accept SSL proxy port configuration without explicit passthrough enable",
88-
validateConfig: func(t *testing.T, showVersion bool, cfg *controller.Configuration) {
173+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
89174
if cfg.ListenPorts.SSLProxy != 8443 {
90175
t.Errorf("Expected SSLProxy port to be 8443, got %d", cfg.ListenPorts.SSLProxy)
91176
}
@@ -96,7 +181,7 @@ func TestSetupSSLProxy(t *testing.T) {
96181
args: []string{"cmd", "--enable-ssl-passthrough", "--default-backend-service", "default/backend", "--ssl-passthrough-proxy-port", "9000"},
97182
expectError: false,
98183
description: "Should work with default backend service and SSL passthrough",
99-
validateConfig: func(t *testing.T, showVersion bool, cfg *controller.Configuration) {
184+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
100185
if !cfg.EnableSSLPassthrough {
101186
t.Error("Expected EnableSSLPassthrough to be true")
102187
}
@@ -113,7 +198,7 @@ func TestSetupSSLProxy(t *testing.T) {
113198
args: []string{"cmd", "--enable-ssl-passthrough", "--default-ssl-certificate", "default/tls-cert", "--ssl-passthrough-proxy-port", "8080"},
114199
expectError: false,
115200
description: "Should work with default SSL certificate and passthrough",
116-
validateConfig: func(t *testing.T, showVersion bool, cfg *controller.Configuration) {
201+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
117202
if !cfg.EnableSSLPassthrough {
118203
t.Error("Expected EnableSSLPassthrough to be true")
119204
}
@@ -130,7 +215,7 @@ func TestSetupSSLProxy(t *testing.T) {
130215
args: []string{"cmd", "--enable-ssl-passthrough", "--enable-ssl-chain-completion", "--ssl-passthrough-proxy-port", "7443"},
131216
expectError: false,
132217
description: "Should work with SSL chain completion and passthrough",
133-
validateConfig: func(t *testing.T, showVersion bool, cfg *controller.Configuration) {
218+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
134219
if !cfg.EnableSSLPassthrough {
135220
t.Error("Expected EnableSSLPassthrough to be true")
136221
}
@@ -147,7 +232,7 @@ func TestSetupSSLProxy(t *testing.T) {
147232
args: []string{"cmd", "--enable-ssl-passthrough"},
148233
expectError: false,
149234
description: "Should work with minimal SSL passthrough configuration using default port",
150-
validateConfig: func(t *testing.T, showVersion bool, cfg *controller.Configuration) {
235+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
151236
if !cfg.EnableSSLPassthrough {
152237
t.Error("Expected EnableSSLPassthrough to be true")
153238
}
@@ -162,7 +247,7 @@ func TestSetupSSLProxy(t *testing.T) {
162247
args: []string{"cmd", "--enable-ssl-passthrough", "--enable-ssl-chain-completion", "--default-ssl-certificate", "kube-system/default-cert", "--default-backend-service", "kube-system/default-backend", "--ssl-passthrough-proxy-port", "10443"},
163248
expectError: false,
164249
description: "Should work with comprehensive SSL proxy configuration",
165-
validateConfig: func(t *testing.T, showVersion bool, cfg *controller.Configuration) {
250+
validateConfig: func(t *testing.T, _ bool, cfg *controller.Configuration) {
166251
if !cfg.EnableSSLPassthrough {
167252
t.Error("Expected EnableSSLPassthrough to be true")
168253
}
@@ -191,7 +276,7 @@ func TestSetupSSLProxy(t *testing.T) {
191276

192277
os.Args = tt.args
193278

194-
showVersion, config, err := ParseFlags()
279+
showVersion, cfg, err := ParseFlags()
195280
if tt.expectError && err == nil {
196281
t.Fatalf("Expected error for %s, but got none", tt.description)
197282
}
@@ -201,7 +286,7 @@ func TestSetupSSLProxy(t *testing.T) {
201286

202287
// Run additional validation if provided and no error occurred
203288
if !tt.expectError && tt.validateConfig != nil {
204-
tt.validateConfig(t, showVersion, config)
289+
tt.validateConfig(t, showVersion, cfg)
205290
}
206291
})
207292
}

0 commit comments

Comments
 (0)