From d3b9951126fd7a3c5aa1c688c5b8d24e47eb097d Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 17 Oct 2022 12:48:49 +0200 Subject: [PATCH] tests: Refactor BinPath into struct Signed-off-by: Marek Siarkowicz --- tests/e2e/ctl_v3_completion_test.go | 4 ++-- tests/e2e/ctl_v3_snapshot_test.go | 6 +++--- tests/e2e/ctl_v3_test.go | 4 ++-- tests/e2e/discovery_test.go | 2 +- tests/e2e/discovery_v3_test.go | 2 +- tests/e2e/gateway_test.go | 4 ++-- tests/e2e/utl_migrate_test.go | 4 ++-- tests/framework/e2e/cluster.go | 2 +- tests/framework/e2e/etcd_spawn.go | 8 ++++++++ tests/framework/e2e/etcdctl.go | 2 +- tests/framework/e2e/flags.go | 15 ++++++++------- 11 files changed, 31 insertions(+), 22 deletions(-) diff --git a/tests/e2e/ctl_v3_completion_test.go b/tests/e2e/ctl_v3_completion_test.go index 88c030d1a..ccadb4a89 100644 --- a/tests/e2e/ctl_v3_completion_test.go +++ b/tests/e2e/ctl_v3_completion_test.go @@ -25,9 +25,9 @@ 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 9047f64ac..ff7b6e51e 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 261aec66a..a6118b069 100644 --- a/tests/e2e/ctl_v3_test.go +++ b/tests/e2e/ctl_v3_test.go @@ -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 b4c55f23c..001fd96c3 100644 --- a/tests/e2e/discovery_test.go +++ b/tests/e2e/discovery_test.go @@ -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 3cf75f633..5b592f050 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/gateway_test.go b/tests/e2e/gateway_test.go index ebd179e74..2e2cc360b 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 3d1d3a107..20f6e3f53 100644 --- a/tests/e2e/utl_migrate_test.go +++ b/tests/e2e/utl_migrate_test.go @@ -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/framework/e2e/cluster.go b/tests/framework/e2e/cluster.go index 074c318ed..5096df714 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_spawn.go b/tests/framework/e2e/etcd_spawn.go index ab86df150..02e8b3cf1 100644 --- a/tests/framework/e2e/etcd_spawn.go +++ b/tests/framework/e2e/etcd_spawn.go @@ -29,3 +29,11 @@ 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 initBinPath(binDir string) binPath { + return binPath{ + Etcd: binDir + "/etcd", + Etcdctl: binDir + "/etcdctl", + Etcdutl: binDir + "/etcdutl", + } +} diff --git a/tests/framework/e2e/etcdctl.go b/tests/framework/e2e/etcdctl.go index 024bd9d74..070c84e2e 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 85d7e858a..2b1e5dca3 100644 --- a/tests/framework/e2e/flags.go +++ b/tests/framework/e2e/flags.go @@ -40,13 +40,16 @@ var ( RevokedCertPath string RevokedPrivateKeyPath string - BinPath string - CtlBinPath string - UtlBinPath string - + BinPath binPath FixturesDir = testutils.MustAbsPath("../fixtures") ) +type binPath struct { + Etcd string + Etcdctl string + Etcdutl string +} + func InitFlags() { os.Setenv("ETCD_UNSUPPORTED_ARCH", runtime.GOARCH) @@ -57,9 +60,7 @@ func InitFlags() { 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"