Skip to content

Commit

Permalink
server/embed/config_test.go: Add unit test for socket options
Browse files Browse the repository at this point in the history
  • Loading branch information
lilic committed May 20, 2021
1 parent 73c530d commit 7957f44
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
5 changes: 3 additions & 2 deletions client/pkg/testutil/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ func AssertEqual(t *testing.T, e, a interface{}, msg ...string) {
return
}
s := ""
if len(msg) > 1 {
if len(msg) > 0 {
s = msg[0] + ": "
}
s = fmt.Sprintf("%sexpected %+v, got %+v", s, e, a)

s = fmt.Sprintf("%s:expected %+v, got %+v", s, e, a)
FatalStack(t, s)
}

Expand Down
27 changes: 17 additions & 10 deletions server/embed/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"go.etcd.io/etcd/client/pkg/v3/srv"
"go.etcd.io/etcd/client/pkg/v3/testutil"
"go.etcd.io/etcd/client/pkg/v3/transport"
"go.etcd.io/etcd/client/pkg/v3/types"

Expand All @@ -40,19 +41,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 @@ -68,16 +73,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)
}

testutil.AssertEqual(t, true, cfg.ForceNewCluster, "ForceNewCluster does not match")

testutil.AssertEqual(t, true, cfg.SocketOpts.ReusePort, "ReusePort does not match")

testutil.AssertEqual(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 7957f44

Please sign in to comment.