diff --git a/tests/e2e/cluster_downgrade_test.go b/tests/e2e/cluster_downgrade_test.go index a8531e7dbb2..001f5d7d887 100644 --- a/tests/e2e/cluster_downgrade_test.go +++ b/tests/e2e/cluster_downgrade_test.go @@ -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) } diff --git a/tests/e2e/ctl_v3_completion_test.go b/tests/e2e/ctl_v3_completion_test.go index 88c030d1ac2..b91edcde821 100644 --- a/tests/e2e/ctl_v3_completion_test.go +++ b/tests/e2e/ctl_v3_completion_test.go @@ -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) diff --git a/tests/e2e/ctl_v3_snapshot_test.go b/tests/e2e/ctl_v3_snapshot_test.go index 9047f64acf0..ff7b6e51edf 100644 --- a/tests/e2e/ctl_v3_snapshot_test.go +++ b/tests/e2e/ctl_v3_snapshot_test.go @@ -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"}} @@ -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) } @@ -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 { diff --git a/tests/e2e/ctl_v3_test.go b/tests/e2e/ctl_v3_test.go index 261aec66aea..9f898245aca 100644 --- a/tests/e2e/ctl_v3_test.go +++ b/tests/e2e/ctl_v3_test.go @@ -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) } @@ -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) @@ -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 { diff --git a/tests/e2e/discovery_test.go b/tests/e2e/discovery_test.go index b4c55f23cac..8bfa199e600 100644 --- a/tests/e2e/discovery_test.go +++ b/tests/e2e/discovery_test.go @@ -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) } @@ -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) } diff --git a/tests/e2e/discovery_v3_test.go b/tests/e2e/discovery_v3_test.go index 3cf75f63306..5b592f050e2 100644 --- a/tests/e2e/discovery_v3_test.go +++ b/tests/e2e/discovery_v3_test.go @@ -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) } diff --git a/tests/e2e/etcd_config_test.go b/tests/e2e/etcd_config_test.go index 4af2448e357..822bc45bb11 100644 --- a/tests/e2e/etcd_config_test.go +++ b/tests/e2e/etcd_config_test.go @@ -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) } @@ -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], @@ -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", @@ -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], @@ -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], @@ -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, @@ -278,7 +278,7 @@ func TestGrpcproxyAndCommonName(t *testing.T) { } argsWithEmptyCN := []string{ - e2e.BinDir + "/etcd", + e2e.BinPath.Etcd, "grpc-proxy", "start", "--cert", e2e.CertPath3, @@ -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", @@ -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", "", @@ -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) } diff --git a/tests/e2e/etcd_grpcproxy_test.go b/tests/e2e/etcd_grpcproxy_test.go index dae62b73855..71d01cf617b 100644 --- a/tests/e2e/etcd_grpcproxy_test.go +++ b/tests/e2e/etcd_grpcproxy_test.go @@ -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", diff --git a/tests/e2e/etcd_release_upgrade_test.go b/tests/e2e/etcd_release_upgrade_test.go index 88f97ca737f..1f65afd56d5 100644 --- a/tests/e2e/etcd_release_upgrade_test.go +++ b/tests/e2e/etcd_release_upgrade_test.go @@ -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) } @@ -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) @@ -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) } @@ -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) diff --git a/tests/e2e/gateway_test.go b/tests/e2e/gateway_test.go index ebd179e746a..2e2cc360be7 100644 --- a/tests/e2e/gateway_test.go +++ b/tests/e2e/gateway_test.go @@ -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) } diff --git a/tests/e2e/utl_migrate_test.go b/tests/e2e/utl_migrate_test.go index 3d1d3a10766..a6236991c22 100644 --- a/tests/e2e/utl_migrate_test.go +++ b/tests/e2e/utl_migrate_test.go @@ -32,7 +32,7 @@ import ( ) func TestEtctlutlMigrate(t *testing.T) { - lastReleaseBinary := e2e.BinDir + "/etcd-last-release" + lastReleaseBinary := e2e.BinPath.EtcdLastRelease tcs := []struct { name string @@ -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++ { @@ -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") } diff --git a/tests/e2e/v2store_deprecation_test.go b/tests/e2e/v2store_deprecation_test.go index 5b9f5f4ddad..61dae5a4443 100644 --- a/tests/e2e/v2store_deprecation_test.go +++ b/tests/e2e/v2store_deprecation_test.go @@ -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") @@ -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"`) @@ -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) } @@ -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) @@ -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) diff --git a/tests/framework/e2e/cluster.go b/tests/framework/e2e/cluster.go index 074c318edba..5096df714f5 100644 --- a/tests/framework/e2e/cluster.go +++ b/tests/framework/e2e/cluster.go @@ -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 diff --git a/tests/framework/e2e/etcd_process.go b/tests/framework/e2e/etcd_process.go index f4c85990714..b355669c01a 100644 --- a/tests/framework/e2e/etcd_process.go +++ b/tests/framework/e2e/etcd_process.go @@ -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. diff --git a/tests/framework/e2e/etcd_spawn.go b/tests/framework/e2e/etcd_spawn.go index ab86df150a2..ff2e2f4c790 100644 --- a/tests/framework/e2e/etcd_spawn.go +++ b/tests/framework/e2e/etcd_spawn.go @@ -15,6 +15,7 @@ package e2e import ( + "os" "strings" "go.uber.org/zap" @@ -22,6 +23,11 @@ import ( "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) } @@ -29,3 +35,22 @@ func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, 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) +} diff --git a/tests/framework/e2e/etcd_spawn_cov.go b/tests/framework/e2e/etcd_spawn_cov.go index 97102f08ffd..349391092df 100644 --- a/tests/framework/e2e/etcd_spawn_cov.go +++ b/tests/framework/e2e/etcd_spawn_cov.go @@ -20,13 +20,10 @@ package e2e import ( "fmt" "os" - "strings" "time" "go.etcd.io/etcd/client/pkg/v3/fileutil" - "go.etcd.io/etcd/pkg/v3/expect" "go.etcd.io/etcd/tests/v3/framework/testutils" - "go.uber.org/zap" ) const noOutputLineCount = 2 // cov-enabled binaries emit PASS and coverage count lines @@ -35,40 +32,21 @@ var ( coverDir = testutils.MustAbsPath(os.Getenv("COVERDIR")) ) -func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) { - cmd := args[0] - env := mergeEnvVariables(envVars) - switch { - case strings.HasSuffix(cmd, "/etcd"): - cmd = cmd + "_test" - case strings.HasSuffix(cmd, "/etcdctl"): - cmd = cmd + "_test" - case strings.HasSuffix(cmd, "/etcdutl"): - cmd = cmd + "_test" - } - - wd, err := os.Getwd() - if err != nil { - return nil, err - } +func init() { + initBinPath = initBinPathCov + additionalArgs = additionalArgsCov +} - covArgs, err := getCovArgs() - if err != nil { - return nil, err +func initBinPathCov(binDir string) binPath { + return binPath{ + Etcd: binDir + "/etcd_test", + EtcdLastRelease: binDir + "/etcd-last-release", + Etcdctl: binDir + "/etcdctl_test", + Etcdutl: binDir + "/etcdutl_test", } - // when withFlagByEnv() is used in testCtl(), env variables for ctl is set to os.env. - // they must be included in ctl_cov_env. - - allArgs := append(args[1:], covArgs...) - lg.Info("spawning process in cov test", - zap.Strings("args", args), - zap.String("working-dir", wd), - zap.String("name", name), - zap.Strings("environment-variables", env)) - return expect.NewExpectWithEnv(cmd, allArgs, env, name) } -func getCovArgs() ([]string, error) { +func additionalArgsCov() ([]string, error) { if !fileutil.Exist(coverDir) { return nil, fmt.Errorf("could not find coverage folder: %s", coverDir) } diff --git a/tests/framework/e2e/etcd_spawn_nocov.go b/tests/framework/e2e/etcd_spawn_nocov.go index 46748ede1e2..3f16e388798 100644 --- a/tests/framework/e2e/etcd_spawn_nocov.go +++ b/tests/framework/e2e/etcd_spawn_nocov.go @@ -17,25 +17,22 @@ package e2e -import ( - "go.uber.org/zap" - "os" - - "go.etcd.io/etcd/pkg/v3/expect" -) - const noOutputLineCount = 0 // regular binaries emit no extra lines -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 +func init() { + initBinPath = initBinPathNoCov + additionalArgs = additionalArgsNoCov +} + +func initBinPathNoCov(binDir string) binPath { + return binPath{ + Etcd: binDir + "/etcd", + EtcdLastRelease: binDir + "/etcd-last-release", + Etcdctl: binDir + "/etcdctl", + Etcdutl: binDir + "/etcdutl", } - 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], args[1:], env, name) +} + +func additionalArgsNoCov() ([]string, error) { + return []string{}, nil } diff --git a/tests/framework/e2e/etcdctl.go b/tests/framework/e2e/etcdctl.go index 024bd9d74fe..070c84e2e44 100644 --- a/tests/framework/e2e/etcdctl.go +++ b/tests/framework/e2e/etcdctl.go @@ -268,7 +268,7 @@ func (ctl *EtcdctlV3) MemberRemove(ctx context.Context, id uint64) (*clientv3.Me } func (ctl *EtcdctlV3) cmdArgs(args ...string) []string { - cmdArgs := []string{CtlBinPath} + cmdArgs := []string{BinPath.Etcdctl} for k, v := range ctl.flags() { cmdArgs = append(cmdArgs, fmt.Sprintf("--%s=%s", k, v)) } diff --git a/tests/framework/e2e/flags.go b/tests/framework/e2e/flags.go index a8607830c8b..d51d2898034 100644 --- a/tests/framework/e2e/flags.go +++ b/tests/framework/e2e/flags.go @@ -23,7 +23,6 @@ import ( ) var ( - BinDir string CertDir string CertPath string @@ -40,22 +39,28 @@ var ( RevokedCertPath string RevokedPrivateKeyPath string + BinPath binPath FixturesDir = testutils.MustAbsPath("../fixtures") ) +type binPath struct { + Etcd string + EtcdLastRelease string + Etcdctl string + Etcdutl string +} + func InitFlags() { os.Setenv("ETCD_UNSUPPORTED_ARCH", runtime.GOARCH) binDirDef := testutils.MustAbsPath("../../bin") certDirDef := FixturesDir - flag.StringVar(&BinDir, "bin-dir", binDirDef, "The directory for store etcd and etcdctl binaries.") + binDir := flag.String("bin-dir", binDirDef, "The directory for store etcd and etcdctl binaries.") flag.StringVar(&CertDir, "cert-dir", certDirDef, "The directory for store certificate files.") flag.Parse() - BinPath = BinDir + "/etcd" - CtlBinPath = BinDir + "/etcdctl" - UtlBinPath = BinDir + "/etcdutl" + BinPath = initBinPath(*binDir) CertPath = CertDir + "/server.crt" PrivateKeyPath = CertDir + "/server.key.insecure" CaPath = CertDir + "/ca.crt"