Skip to content

Commit

Permalink
Merge pull request #14596 from serathius/simplify-e2e-coverage
Browse files Browse the repository at this point in the history
Simplify e2e coverage code
  • Loading branch information
ahrtr authored Oct 18, 2022
2 parents 5e791a0 + 1b3f301 commit e24402d
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 101 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/cluster_downgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func TestDowngradeUpgradeClusterOf3(t *testing.T) {
}

func testDowngradeUpgrade(t *testing.T, clusterSize int) {
currentEtcdBinary := e2e.BinDir + "/etcd"
lastReleaseBinary := e2e.BinDir + "/etcd-last-release"
currentEtcdBinary := e2e.BinPath.Etcd
lastReleaseBinary := e2e.BinPath.EtcdLastRelease
if !fileutil.Exist(lastReleaseBinary) {
t.Skipf("%q does not exist", lastReleaseBinary)
}
Expand Down
8 changes: 6 additions & 2 deletions tests/e2e/ctl_v3_completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ import (
"go.etcd.io/etcd/tests/v3/framework/e2e"
)

func TestCtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.CtlBinPath, "bash") }
func TestCtlV3CompletionBash(t *testing.T) {
testShellCompletion(t, e2e.BinPath.Etcdctl, "bash")
}

func TestUtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.UtlBinPath, "bash") }
func TestUtlV3CompletionBash(t *testing.T) {
testShellCompletion(t, e2e.BinPath.Etcdutl, "bash")
}

func testShellCompletion(t *testing.T, binPath, shellName string) {
e2e.BeforeTest(t)
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/ctl_v3_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func testIssue6361(t *testing.T) {
}()

dialTimeout := 10 * time.Second
prefixArgs := []string{e2e.CtlBinPath, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()}
prefixArgs := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()}

t.Log("Writing some keys...")
kvs := []kv{{"foo1", "val1"}, {"foo2", "val2"}, {"foo3", "val3"}}
Expand All @@ -214,7 +214,7 @@ func testIssue6361(t *testing.T) {

newDataDir := filepath.Join(t.TempDir(), "test.data")
t.Log("etcdctl restoring the snapshot...")
err = e2e.SpawnWithExpect([]string{e2e.UtlBinPath, "snapshot", "restore", fpath, "--name", epc.Procs[0].Config().Name, "--initial-cluster", epc.Procs[0].Config().InitialCluster, "--initial-cluster-token", epc.Procs[0].Config().InitialToken, "--initial-advertise-peer-urls", epc.Procs[0].Config().Purl.String(), "--data-dir", newDataDir}, "added member")
err = e2e.SpawnWithExpect([]string{e2e.BinPath.Etcdutl, "snapshot", "restore", fpath, "--name", epc.Procs[0].Config().Name, "--initial-cluster", epc.Procs[0].Config().InitialCluster, "--initial-cluster-token", epc.Procs[0].Config().InitialToken, "--initial-advertise-peer-urls", epc.Procs[0].Config().Purl.String(), "--data-dir", newDataDir}, "added member")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func testIssue6361(t *testing.T) {
t.Fatal(err)
}

prefixArgs = []string{e2e.CtlBinPath, "--endpoints", clientURL, "--dial-timeout", dialTimeout.String()}
prefixArgs = []string{e2e.BinPath.Etcdctl, "--endpoints", clientURL, "--dial-timeout", dialTimeout.String()}

t.Log("Ensuring added member has data from incoming snapshot...")
for i := range kvs {
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/ctl_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestClusterVersion(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
binary := e2e.BinDir + "/etcd"
binary := e2e.BinPath.Etcd
if !fileutil.Exist(binary) {
t.Skipf("%q does not exist", binary)
}
Expand Down Expand Up @@ -320,7 +320,7 @@ func (cx *ctlCtx) prefixArgs(eps []string) []string {

useEnv := cx.envMap != nil

cmdArgs := []string{e2e.CtlBinPath}
cmdArgs := []string{e2e.BinPath.Etcdctl}
for k, v := range fmap {
if useEnv {
ek := flags.FlagToEnv("ETCDCTL", k)
Expand All @@ -341,7 +341,7 @@ func (cx *ctlCtx) PrefixArgs() []string {
// PrefixArgsUtl returns prefix of the command that is etcdutl
// Please not thet 'utl' compatible commands does not consume --endpoints flag.
func (cx *ctlCtx) PrefixArgsUtl() []string {
return []string{e2e.UtlBinPath}
return []string{e2e.BinPath.Etcdutl}
}

func isGRPCTimedout(err error) bool {
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestTLSClusterOf3UsingDiscovery(t *testing.T) { testClusterUsingDiscovery(t
func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) {
e2e.BeforeTest(t)

lastReleaseBinary := e2e.BinDir + "/etcd-last-release"
lastReleaseBinary := e2e.BinPath.EtcdLastRelease
if !fileutil.Exist(lastReleaseBinary) {
t.Skipf("%q does not exist", lastReleaseBinary)
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) {
}
defer c.Close()

kubectl := []string{e2e.CtlBinPath, "--endpoints", strings.Join(c.EndpointsV3(), ",")}
kubectl := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(c.EndpointsV3(), ",")}
if err := e2e.SpawnWithExpect(append(kubectl, "put", "key", "value"), "OK"); err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/discovery_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func testClusterUsingV3Discovery(t *testing.T, discoveryClusterSize, targetClust
defer epc.Close()

// step 4: sanity test on the etcd cluster
etcdctl := []string{e2e.CtlBinPath, "--endpoints", strings.Join(epc.EndpointsV3(), ",")}
etcdctl := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(epc.EndpointsV3(), ",")}
if err := e2e.SpawnWithExpect(append(etcdctl, "put", "key", "value"), "OK"); err != nil {
t.Fatal(err)
}
Expand Down
20 changes: 10 additions & 10 deletions tests/e2e/etcd_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const exampleConfigFile = "../../etcd.conf.yml.sample"
func TestEtcdExampleConfig(t *testing.T) {
e2e.SkipInShortMode(t)

proc, err := e2e.SpawnCmd([]string{e2e.BinDir + "/etcd", "--config-file", exampleConfigFile}, nil)
proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--config-file", exampleConfigFile}, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestEtcdMultiPeer(t *testing.T) {
}()
for i := range procs {
args := []string{
e2e.BinDir + "/etcd",
e2e.BinPath.Etcd,
"--name", fmt.Sprintf("e%d", i),
"--listen-client-urls", "http://0.0.0.0:0",
"--data-dir", tmpdirs[i],
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestEtcdUnixPeers(t *testing.T) {
d := t.TempDir()
proc, err := e2e.SpawnCmd(
[]string{
e2e.BinDir + "/etcd",
e2e.BinPath.Etcd,
"--data-dir", d,
"--name", "e1",
"--listen-peer-urls", "unix://etcd.unix:1",
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestEtcdPeerCNAuth(t *testing.T) {
// node 0 and 1 have a cert with the correct CN, node 2 doesn't
for i := range procs {
commonArgs := []string{
e2e.BinDir + "/etcd",
e2e.BinPath.Etcd,
"--name", fmt.Sprintf("e%d", i),
"--listen-client-urls", "http://0.0.0.0:0",
"--data-dir", tmpdirs[i],
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestEtcdPeerNameAuth(t *testing.T) {
// node 0 and 1 have a cert with the correct certificate name, node 2 doesn't
for i := range procs {
commonArgs := []string{
e2e.BinDir + "/etcd",
e2e.BinPath.Etcd,
"--name", fmt.Sprintf("e%d", i),
"--listen-client-urls", "http://0.0.0.0:0",
"--data-dir", tmpdirs[i],
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestGrpcproxyAndCommonName(t *testing.T) {
e2e.SkipInShortMode(t)

argsWithNonEmptyCN := []string{
e2e.BinDir + "/etcd",
e2e.BinPath.Etcd,
"grpc-proxy",
"start",
"--cert", e2e.CertPath2,
Expand All @@ -278,7 +278,7 @@ func TestGrpcproxyAndCommonName(t *testing.T) {
}

argsWithEmptyCN := []string{
e2e.BinDir + "/etcd",
e2e.BinPath.Etcd,
"grpc-proxy",
"start",
"--cert", e2e.CertPath3,
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestGrpcproxyAndListenCipherSuite(t *testing.T) {
{
name: "ArgsWithCipherSuites",
args: []string{
e2e.BinDir + "/etcd",
e2e.BinPath.Etcd,
"grpc-proxy",
"start",
"--listen-cipher-suites", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
Expand All @@ -322,7 +322,7 @@ func TestGrpcproxyAndListenCipherSuite(t *testing.T) {
{
name: "ArgsWithoutCipherSuites",
args: []string{
e2e.BinDir + "/etcd",
e2e.BinPath.Etcd,
"grpc-proxy",
"start",
"--listen-cipher-suites", "",
Expand All @@ -346,7 +346,7 @@ func TestGrpcproxyAndListenCipherSuite(t *testing.T) {
func TestBootstrapDefragFlag(t *testing.T) {
e2e.SkipInShortMode(t)

proc, err := e2e.SpawnCmd([]string{e2e.BinDir + "/etcd", "--experimental-bootstrap-defrag-threshold-megabytes", "1000"}, nil)
proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--experimental-bootstrap-defrag-threshold-megabytes", "1000"}, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/etcd_grpcproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestGrpcProxyAutoSync(t *testing.T) {
)

// Run independent grpc-proxy instance
proxyProc, err := e2e.SpawnCmd([]string{e2e.BinDir + "/etcd", "grpc-proxy", "start",
proxyProc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "grpc-proxy", "start",
"--advertise-client-url", proxyClientURL, "--listen-addr", proxyClientURL,
"--endpoints", node1ClientURL,
"--endpoints-auto-sync-interval", "1s",
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/etcd_release_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// TestReleaseUpgrade ensures that changes to master branch does not affect
// upgrade from latest etcd releases.
func TestReleaseUpgrade(t *testing.T) {
lastReleaseBinary := e2e.BinDir + "/etcd-last-release"
lastReleaseBinary := e2e.BinPath.EtcdLastRelease
if !fileutil.Exist(lastReleaseBinary) {
t.Skipf("%q does not exist", lastReleaseBinary)
}
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestReleaseUpgrade(t *testing.T) {
t.Fatalf("#%d: error closing etcd process (%v)", i, err)
}
t.Logf("Stopped node: %v", i)
epc.Procs[i].Config().ExecPath = e2e.BinDir + "/etcd"
epc.Procs[i].Config().ExecPath = e2e.BinPath.Etcd
epc.Procs[i].Config().KeepDataDir = true

t.Logf("Restarting node in the new version: %v", i)
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestReleaseUpgrade(t *testing.T) {
}

func TestReleaseUpgradeWithRestart(t *testing.T) {
lastReleaseBinary := e2e.BinDir + "/etcd-last-release"
lastReleaseBinary := e2e.BinPath.EtcdLastRelease
if !fileutil.Exist(lastReleaseBinary) {
t.Skipf("%q does not exist", lastReleaseBinary)
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestReleaseUpgradeWithRestart(t *testing.T) {
wg.Add(len(epc.Procs))
for i := range epc.Procs {
go func(i int) {
epc.Procs[i].Config().ExecPath = e2e.BinDir + "/etcd"
epc.Procs[i].Config().ExecPath = e2e.BinPath.Etcd
epc.Procs[i].Config().KeepDataDir = true
if err := epc.Procs[i].Restart(context.TODO()); err != nil {
t.Errorf("error restarting etcd process (%v)", err)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ func TestGateway(t *testing.T) {
p := startGateway(t, eps)
defer p.Stop()

err = e2e.SpawnWithExpect([]string{e2e.CtlBinPath, "--endpoints=" + defaultGatewayEndpoint, "put", "foo", "bar"}, "OK\r\n")
err = e2e.SpawnWithExpect([]string{e2e.BinPath.Etcdctl, "--endpoints=" + defaultGatewayEndpoint, "put", "foo", "bar"}, "OK\r\n")
if err != nil {
t.Errorf("failed to finish put request through gateway: %v", err)
}
}

func startGateway(t *testing.T, endpoints string) *expect.ExpectProcess {
p, err := expect.NewExpect(e2e.BinPath, "gateway", "--endpoints="+endpoints, "start")
p, err := expect.NewExpect(e2e.BinPath.Etcd, "gateway", "--endpoints="+endpoints, "start")
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/utl_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

func TestEtctlutlMigrate(t *testing.T) {
lastReleaseBinary := e2e.BinDir + "/etcd-last-release"
lastReleaseBinary := e2e.BinPath.EtcdLastRelease

tcs := []struct {
name string
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestEtctlutlMigrate(t *testing.T) {
}()

dialTimeout := 10 * time.Second
prefixArgs := []string{e2e.CtlBinPath, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()}
prefixArgs := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()}

t.Log("Write keys to ensure wal snapshot is created and all v3.5 fields are set...")
for i := 0; i < 10; i++ {
Expand All @@ -148,7 +148,7 @@ func TestEtctlutlMigrate(t *testing.T) {
}

t.Log("etcdutl migrate...")
args := []string{e2e.UtlBinPath, "migrate", "--data-dir", dataDirPath, "--target-version", tc.targetVersion}
args := []string{e2e.BinPath.Etcdutl, "migrate", "--data-dir", dataDirPath, "--target-version", tc.targetVersion}
if tc.force {
args = append(args, "--force")
}
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/v2store_deprecation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func createV2store(t testing.TB, lastReleaseBinary string, dataDirPath string) {

func assertVerifyCannotStartV2deprecationWriteOnly(t testing.TB, dataDirPath string) {
t.Log("Verify its infeasible to start etcd with --v2-deprecation=write-only mode")
proc, err := e2e.SpawnCmd([]string{e2e.BinDir + "/etcd", "--v2-deprecation=write-only", "--data-dir=" + dataDirPath}, nil)
proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--v2-deprecation=write-only", "--data-dir=" + dataDirPath}, nil)
assert.NoError(t, err)

_, err = proc.Expect("detected disallowed custom content in v2store for stage --v2-deprecation=write-only")
Expand All @@ -64,7 +64,7 @@ func assertVerifyCannotStartV2deprecationWriteOnly(t testing.TB, dataDirPath str

func assertVerifyCannotStartV2deprecationNotYet(t testing.TB, dataDirPath string) {
t.Log("Verify its infeasible to start etcd with --v2-deprecation=not-yet mode")
proc, err := e2e.SpawnCmd([]string{e2e.BinDir + "/etcd", "--v2-deprecation=not-yet", "--data-dir=" + dataDirPath}, nil)
proc, err := e2e.SpawnCmd([]string{e2e.BinPath.Etcd, "--v2-deprecation=not-yet", "--data-dir=" + dataDirPath}, nil)
assert.NoError(t, err)

_, err = proc.Expect(`invalid value "not-yet" for flag -v2-deprecation: invalid value "not-yet"`)
Expand All @@ -75,7 +75,7 @@ func TestV2DeprecationFlags(t *testing.T) {
e2e.BeforeTest(t)
dataDirPath := t.TempDir()

lastReleaseBinary := e2e.BinDir + "/etcd-last-release"
lastReleaseBinary := e2e.BinPath.EtcdLastRelease
if !fileutil.Exist(lastReleaseBinary) {
t.Skipf("%q does not exist", lastReleaseBinary)
}
Expand All @@ -101,8 +101,8 @@ func TestV2DeprecationSnapshotMatches(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

lastReleaseBinary := e2e.BinDir + "/etcd-last-release"
currentReleaseBinary := e2e.BinDir + "/etcd"
lastReleaseBinary := e2e.BinPath.EtcdLastRelease
currentReleaseBinary := e2e.BinPath.Etcd

if !fileutil.Exist(lastReleaseBinary) {
t.Skipf("%q does not exist", lastReleaseBinary)
Expand Down Expand Up @@ -136,8 +136,8 @@ func TestV2DeprecationSnapshotRecover(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

lastReleaseBinary := e2e.BinDir + "/etcd-last-release"
currentReleaseBinary := e2e.BinDir + "/etcd"
lastReleaseBinary := e2e.BinPath.EtcdLastRelease
currentReleaseBinary := e2e.BinPath.Etcd

if !fileutil.Exist(lastReleaseBinary) {
t.Skipf("%q does not exist", lastReleaseBinary)
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/e2e/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func InitEtcdProcessCluster(t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdP
cfg.BasePort = EtcdProcessBasePort
}
if cfg.ExecPath == "" {
cfg.ExecPath = BinPath
cfg.ExecPath = BinPath.Etcd
}
if cfg.SnapshotCount == 0 {
cfg.SnapshotCount = etcdserver.DefaultSnapshotCount
Expand Down
3 changes: 0 additions & 3 deletions tests/framework/e2e/etcd_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ import (

var (
EtcdServerReadyLines = []string{"ready to serve client requests"}
BinPath string
CtlBinPath string
UtlBinPath string
)

// EtcdProcess is a process that serves etcd requests.
Expand Down
25 changes: 25 additions & 0 deletions tests/framework/e2e/etcd_spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,42 @@
package e2e

import (
"os"
"strings"

"go.uber.org/zap"

"go.etcd.io/etcd/pkg/v3/expect"
)

var (
initBinPath func(string) binPath
additionalArgs func() ([]string, error)
)

func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, error) {
return SpawnNamedCmd(strings.Join(args, "_"), args, envVars)
}

func SpawnNamedCmd(processName string, args []string, envVars map[string]string) (*expect.ExpectProcess, error) {
return SpawnCmdWithLogger(zap.NewNop(), args, envVars, processName)
}

func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) {
wd, err := os.Getwd()
if err != nil {
return nil, err
}

newArgs, err := additionalArgs()
if err != nil {
return nil, err
}
env := mergeEnvVariables(envVars)
lg.Info("spawning process",
zap.Strings("args", args),
zap.String("working-dir", wd),
zap.String("name", name),
zap.Strings("environment-variables", env))
return expect.NewExpectWithEnv(args[0], append(args[1:], newArgs...), env, name)
}
Loading

0 comments on commit e24402d

Please sign in to comment.