Skip to content

Commit b74bc07

Browse files
authored
Merge pull request #19245 from serathius/test-hardcoded-flags
Add tests for hardcoded flags in TestEtcdServerProcessConfig
2 parents 43431bd + ce54561 commit b74bc07

File tree

2 files changed

+143
-4
lines changed

2 files changed

+143
-4
lines changed

tests/framework/e2e/cluster.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,22 @@ func WithPeerProxy(enabled bool) EPClusterOption {
396396
return func(c *EtcdProcessClusterConfig) { c.PeerProxy = enabled }
397397
}
398398

399+
func WithClientHTTPSeparate(enabled bool) EPClusterOption {
400+
return func(c *EtcdProcessClusterConfig) { c.ClientHTTPSeparate = enabled }
401+
}
402+
403+
func WithForceNewCluster(enabled bool) EPClusterOption {
404+
return func(c *EtcdProcessClusterConfig) { c.ServerConfig.ForceNewCluster = enabled }
405+
}
406+
407+
func WithMetricsURLScheme(scheme string) EPClusterOption {
408+
return func(c *EtcdProcessClusterConfig) { c.MetricsURLScheme = scheme }
409+
}
410+
411+
func WithCipherSuites(suites []string) EPClusterOption {
412+
return func(c *EtcdProcessClusterConfig) { c.ServerConfig.CipherSuites = suites }
413+
}
414+
399415
// NewEtcdProcessCluster launches a new cluster from etcd processes, returning
400416
// a new EtcdProcessCluster once all nodes are ready to accept client requests.
401417
func NewEtcdProcessCluster(ctx context.Context, t testing.TB, opts ...EPClusterOption) (*EtcdProcessCluster, error) {
@@ -581,7 +597,7 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
581597
}
582598

583599
if cfg.ServerConfig.ForceNewCluster {
584-
args = append(args, "--force-new-cluster")
600+
args = append(args, "--force-new-cluster=true")
585601
}
586602
if cfg.ServerConfig.QuotaBackendBytes > 0 {
587603
args = append(args,
@@ -592,7 +608,7 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
592608
args = append(args, "--strict-reconfig-check=false")
593609
}
594610
if cfg.EnableV2 {
595-
args = append(args, "--enable-v2")
611+
args = append(args, "--enable-v2=true")
596612
}
597613
var murl string
598614
if cfg.MetricsURLScheme != "" {

tests/framework/e2e/cluster_test.go

Lines changed: 125 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,25 @@ func TestEtcdServerProcessConfig(t *testing.T) {
2828
tcs := []struct {
2929
name string
3030
config *EtcdProcessClusterConfig
31+
expectArgsEquals []string
3132
expectArgsNotContain []string
3233
expectArgsContain []string
3334
mockBinaryVersion *semver.Version
3435
}{
3536
{
3637
name: "Default",
37-
config: NewConfig(),
38-
expectArgsContain: []string{
38+
config: NewConfig(WithDataDirPath("/tmp/a")),
39+
expectArgsEquals: []string{
40+
"--name=TestEtcdServerProcessConfigDefault-test-0",
3941
"--listen-client-urls=http://localhost:0",
4042
"--advertise-client-urls=http://localhost:0",
4143
"--listen-peer-urls=http://localhost:1",
4244
"--initial-advertise-peer-urls=http://localhost:1",
4345
"--initial-cluster-token=new",
46+
"--data-dir",
47+
"/tmp/a/member-0",
4448
"--snapshot-count=10000",
49+
"--initial-cluster-token=new",
4550
},
4651
},
4752
{
@@ -95,6 +100,121 @@ func TestEtcdServerProcessConfig(t *testing.T) {
95100
},
96101
mockBinaryVersion: &v3_5_12,
97102
},
103+
{
104+
name: "ClientHTTPSeparate",
105+
config: NewConfig(WithClientHTTPSeparate(true)),
106+
expectArgsContain: []string{
107+
"--listen-client-http-urls=http://localhost:4",
108+
},
109+
},
110+
{
111+
name: "ForceNewCluster",
112+
config: NewConfig(WithForceNewCluster(true)),
113+
expectArgsContain: []string{
114+
"--force-new-cluster=true",
115+
},
116+
},
117+
{
118+
name: "EnableV2",
119+
config: NewConfig(WithEnableV2(true)),
120+
expectArgsContain: []string{
121+
"--enable-v2=true",
122+
},
123+
},
124+
{
125+
name: "MetricsURL",
126+
config: NewConfig(WithMetricsURLScheme("http")),
127+
expectArgsContain: []string{
128+
"--listen-metrics-urls=http://localhost:2",
129+
},
130+
},
131+
{
132+
name: "Discovery",
133+
config: NewConfig(WithDiscovery("123")),
134+
expectArgsContain: []string{
135+
"--discovery=123",
136+
},
137+
},
138+
{
139+
name: "ClientTLS",
140+
config: NewConfig(WithClientConnType(ClientTLS)),
141+
expectArgsContain: []string{
142+
"--cert-file",
143+
"--key-file",
144+
"--trusted-ca-file",
145+
},
146+
expectArgsNotContain: []string{
147+
"--auto-tls",
148+
"--client-cert-auth",
149+
},
150+
},
151+
{
152+
name: "ClientTLSCA",
153+
config: NewConfig(WithClientConnType(ClientTLS), WithClientCertAuthority(true)),
154+
expectArgsContain: []string{
155+
"--cert-file",
156+
"--key-file",
157+
"--trusted-ca-file",
158+
"--client-cert-auth",
159+
},
160+
expectArgsNotContain: []string{
161+
"--auto-tls",
162+
},
163+
},
164+
{
165+
name: "ClientAutoTLS",
166+
config: NewConfig(WithClientConnType(ClientTLS), WithClientAutoTLS(true)),
167+
expectArgsContain: []string{
168+
"--auto-tls",
169+
},
170+
expectArgsNotContain: []string{
171+
"--cert-file",
172+
"--key-file",
173+
"--trusted-ca-file",
174+
"--client-cert-auth",
175+
},
176+
},
177+
{
178+
name: "PeerTLS",
179+
config: NewConfig(WithIsPeerTLS(true)),
180+
expectArgsContain: []string{
181+
"--peer-cert-file",
182+
"--peer-key-file",
183+
"--peer-trusted-ca-file",
184+
},
185+
expectArgsNotContain: []string{
186+
"--peer-auto-tls",
187+
"--peer-client-cert-auth",
188+
},
189+
},
190+
{
191+
name: "PeerAutoTLS",
192+
config: NewConfig(WithIsPeerTLS(true), WithIsPeerAutoTLS(true)),
193+
expectArgsContain: []string{
194+
"--peer-auto-tls",
195+
},
196+
expectArgsNotContain: []string{
197+
"--peer-cert-file",
198+
"--peer-key-file",
199+
"--peer-trusted-ca-file",
200+
"--peer-client-cert-auth",
201+
},
202+
},
203+
{
204+
name: "RevokeCerts",
205+
config: NewConfig(WithClientRevokeCerts(true)),
206+
expectArgsContain: []string{
207+
"--client-crl-file",
208+
"--client-cert-auth",
209+
},
210+
},
211+
{
212+
name: "CipherSuites",
213+
config: NewConfig(WithCipherSuites([]string{"a", "b"})),
214+
expectArgsContain: []string{
215+
"--cipher-suites",
216+
},
217+
},
98218
}
99219
for _, tc := range tcs {
100220
t.Run(tc.name, func(t *testing.T) {
@@ -110,6 +230,9 @@ func TestEtcdServerProcessConfig(t *testing.T) {
110230
}
111231
setGetVersionFromBinary(t, mockGetVersionFromBinary)
112232
args := tc.config.EtcdServerProcessConfig(t, 0).Args
233+
if len(tc.expectArgsEquals) != 0 {
234+
assert.Equal(t, args, tc.expectArgsEquals)
235+
}
113236
if len(tc.expectArgsContain) != 0 {
114237
assert.Subset(t, args, tc.expectArgsContain)
115238
}

0 commit comments

Comments
 (0)