Skip to content

Commit

Permalink
Backport adding unit test for socket options.
Browse files Browse the repository at this point in the history
Co-authored-by: Shawn Gerrard <shawn.gerrard@gmail.com>
Signed-off-by: James Blair <mail@jamesblair.net>
  • Loading branch information
jmhbnz and shawngerrard committed Aug 18, 2023
1 parent 2a7bffc commit f23416e
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions server/embed/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ func TestConfigFileOtherFields(t *testing.T) {
ctls := securityConfig{TrustedCAFile: "cca", CertFile: "ccert", KeyFile: "ckey"}
ptls := securityConfig{TrustedCAFile: "pca", CertFile: "pcert", KeyFile: "pkey"}
yc := struct {
ClientSecurityCfgFile securityConfig `json:"client-transport-security"`
PeerSecurityCfgFile securityConfig `json:"peer-transport-security"`
ForceNewCluster bool `json:"force-new-cluster"`
Logger string `json:"logger"`
LogOutputs []string `json:"log-outputs"`
Debug bool `json:"debug"`
ClientSecurityCfgFile securityConfig `json:"client-transport-security"`
PeerSecurityCfgFile securityConfig `json:"peer-transport-security"`
ForceNewCluster bool `json:"force-new-cluster"`
Logger string `json:"logger"`
LogOutputs []string `json:"log-outputs"`
Debug bool `json:"debug"`
SocketOpts transport.SocketOpts `json:"socket-options"`
}{
ctls,
ptls,
true,
"zap",
[]string{"/dev/null"},
false,
transport.SocketOpts{
ReusePort: true,
},
}

b, err := yaml.Marshal(&yc)
Expand All @@ -70,16 +74,18 @@ func TestConfigFileOtherFields(t *testing.T) {
t.Fatal(err)
}

if !cfg.ForceNewCluster {
t.Errorf("ForceNewCluster = %v, want %v", cfg.ForceNewCluster, true)
}

if !ctls.equals(&cfg.ClientTLSInfo) {
t.Errorf("ClientTLS = %v, want %v", cfg.ClientTLSInfo, ctls)
}
if !ptls.equals(&cfg.PeerTLSInfo) {
t.Errorf("PeerTLS = %v, want %v", cfg.PeerTLSInfo, ptls)
}

assert.Equal(t, true, cfg.ForceNewCluster, "ForceNewCluster does not match")

assert.Equal(t, true, cfg.SocketOpts.ReusePort, "ReusePort does not match")

assert.Equal(t, false, cfg.SocketOpts.ReuseAddress, "ReuseAddress does not match")
}

// TestUpdateDefaultClusterFromName ensures that etcd can start with 'etcd --name=abc'.
Expand Down

0 comments on commit f23416e

Please sign in to comment.