Skip to content

Commit

Permalink
Merge pull request #19245 from serathius/test-hardcoded-flags
Browse files Browse the repository at this point in the history
Add tests for hardcoded flags in TestEtcdServerProcessConfig
  • Loading branch information
serathius authored Jan 22, 2025
2 parents 43431bd + ce54561 commit b74bc07
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 4 deletions.
20 changes: 18 additions & 2 deletions tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,22 @@ func WithPeerProxy(enabled bool) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.PeerProxy = enabled }
}

func WithClientHTTPSeparate(enabled bool) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.ClientHTTPSeparate = enabled }
}

func WithForceNewCluster(enabled bool) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.ServerConfig.ForceNewCluster = enabled }
}

func WithMetricsURLScheme(scheme string) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.MetricsURLScheme = scheme }
}

func WithCipherSuites(suites []string) EPClusterOption {
return func(c *EtcdProcessClusterConfig) { c.ServerConfig.CipherSuites = suites }
}

// NewEtcdProcessCluster launches a new cluster from etcd processes, returning
// a new EtcdProcessCluster once all nodes are ready to accept client requests.
func NewEtcdProcessCluster(ctx context.Context, t testing.TB, opts ...EPClusterOption) (*EtcdProcessCluster, error) {
Expand Down Expand Up @@ -581,7 +597,7 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
}

if cfg.ServerConfig.ForceNewCluster {
args = append(args, "--force-new-cluster")
args = append(args, "--force-new-cluster=true")
}
if cfg.ServerConfig.QuotaBackendBytes > 0 {
args = append(args,
Expand All @@ -592,7 +608,7 @@ func (cfg *EtcdProcessClusterConfig) EtcdServerProcessConfig(tb testing.TB, i in
args = append(args, "--strict-reconfig-check=false")
}
if cfg.EnableV2 {
args = append(args, "--enable-v2")
args = append(args, "--enable-v2=true")
}
var murl string
if cfg.MetricsURLScheme != "" {
Expand Down
127 changes: 125 additions & 2 deletions tests/framework/e2e/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,25 @@ func TestEtcdServerProcessConfig(t *testing.T) {
tcs := []struct {
name string
config *EtcdProcessClusterConfig
expectArgsEquals []string
expectArgsNotContain []string
expectArgsContain []string
mockBinaryVersion *semver.Version
}{
{
name: "Default",
config: NewConfig(),
expectArgsContain: []string{
config: NewConfig(WithDataDirPath("/tmp/a")),
expectArgsEquals: []string{
"--name=TestEtcdServerProcessConfigDefault-test-0",
"--listen-client-urls=http://localhost:0",
"--advertise-client-urls=http://localhost:0",
"--listen-peer-urls=http://localhost:1",
"--initial-advertise-peer-urls=http://localhost:1",
"--initial-cluster-token=new",
"--data-dir",
"/tmp/a/member-0",
"--snapshot-count=10000",
"--initial-cluster-token=new",
},
},
{
Expand Down Expand Up @@ -95,6 +100,121 @@ func TestEtcdServerProcessConfig(t *testing.T) {
},
mockBinaryVersion: &v3_5_12,
},
{
name: "ClientHTTPSeparate",
config: NewConfig(WithClientHTTPSeparate(true)),
expectArgsContain: []string{
"--listen-client-http-urls=http://localhost:4",
},
},
{
name: "ForceNewCluster",
config: NewConfig(WithForceNewCluster(true)),
expectArgsContain: []string{
"--force-new-cluster=true",
},
},
{
name: "EnableV2",
config: NewConfig(WithEnableV2(true)),
expectArgsContain: []string{
"--enable-v2=true",
},
},
{
name: "MetricsURL",
config: NewConfig(WithMetricsURLScheme("http")),
expectArgsContain: []string{
"--listen-metrics-urls=http://localhost:2",
},
},
{
name: "Discovery",
config: NewConfig(WithDiscovery("123")),
expectArgsContain: []string{
"--discovery=123",
},
},
{
name: "ClientTLS",
config: NewConfig(WithClientConnType(ClientTLS)),
expectArgsContain: []string{
"--cert-file",
"--key-file",
"--trusted-ca-file",
},
expectArgsNotContain: []string{
"--auto-tls",
"--client-cert-auth",
},
},
{
name: "ClientTLSCA",
config: NewConfig(WithClientConnType(ClientTLS), WithClientCertAuthority(true)),
expectArgsContain: []string{
"--cert-file",
"--key-file",
"--trusted-ca-file",
"--client-cert-auth",
},
expectArgsNotContain: []string{
"--auto-tls",
},
},
{
name: "ClientAutoTLS",
config: NewConfig(WithClientConnType(ClientTLS), WithClientAutoTLS(true)),
expectArgsContain: []string{
"--auto-tls",
},
expectArgsNotContain: []string{
"--cert-file",
"--key-file",
"--trusted-ca-file",
"--client-cert-auth",
},
},
{
name: "PeerTLS",
config: NewConfig(WithIsPeerTLS(true)),
expectArgsContain: []string{
"--peer-cert-file",
"--peer-key-file",
"--peer-trusted-ca-file",
},
expectArgsNotContain: []string{
"--peer-auto-tls",
"--peer-client-cert-auth",
},
},
{
name: "PeerAutoTLS",
config: NewConfig(WithIsPeerTLS(true), WithIsPeerAutoTLS(true)),
expectArgsContain: []string{
"--peer-auto-tls",
},
expectArgsNotContain: []string{
"--peer-cert-file",
"--peer-key-file",
"--peer-trusted-ca-file",
"--peer-client-cert-auth",
},
},
{
name: "RevokeCerts",
config: NewConfig(WithClientRevokeCerts(true)),
expectArgsContain: []string{
"--client-crl-file",
"--client-cert-auth",
},
},
{
name: "CipherSuites",
config: NewConfig(WithCipherSuites([]string{"a", "b"})),
expectArgsContain: []string{
"--cipher-suites",
},
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
Expand All @@ -110,6 +230,9 @@ func TestEtcdServerProcessConfig(t *testing.T) {
}
setGetVersionFromBinary(t, mockGetVersionFromBinary)
args := tc.config.EtcdServerProcessConfig(t, 0).Args
if len(tc.expectArgsEquals) != 0 {
assert.Equal(t, args, tc.expectArgsEquals)
}
if len(tc.expectArgsContain) != 0 {
assert.Subset(t, args, tc.expectArgsContain)
}
Expand Down

0 comments on commit b74bc07

Please sign in to comment.