From 89a1e7978ceb7ed5a00ece603e1c69c1ee2cbfb6 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 17 Oct 2022 12:40:26 +0200 Subject: [PATCH] tests: Configure coverage binary paths via init Signed-off-by: Marek Siarkowicz --- tests/e2e/ctl_v3_completion_test.go | 8 ++++++-- tests/framework/e2e/etcd_spawn.go | 12 ++++-------- tests/framework/e2e/etcd_spawn_cov.go | 21 ++++++++++++--------- tests/framework/e2e/etcd_spawn_nocov.go | 15 ++++++++++++++- 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/tests/e2e/ctl_v3_completion_test.go b/tests/e2e/ctl_v3_completion_test.go index ccadb4a89..b91edcde8 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.BinPath.Etcdctl, "bash") } +func TestCtlV3CompletionBash(t *testing.T) { + testShellCompletion(t, e2e.BinPath.Etcdctl, "bash") +} -func TestUtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.BinPath.Etcdutl, "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/framework/e2e/etcd_spawn.go b/tests/framework/e2e/etcd_spawn.go index 02e8b3cf1..5f76f1868 100644 --- a/tests/framework/e2e/etcd_spawn.go +++ b/tests/framework/e2e/etcd_spawn.go @@ -22,6 +22,10 @@ import ( "go.etcd.io/etcd/pkg/v3/expect" ) +var ( + initBinPath func(string) binPath +) + func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess, error) { return SpawnNamedCmd(strings.Join(args, "_"), args, envVars) } @@ -29,11 +33,3 @@ 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/etcd_spawn_cov.go b/tests/framework/e2e/etcd_spawn_cov.go index 97102f08f..fba1c37fe 100644 --- a/tests/framework/e2e/etcd_spawn_cov.go +++ b/tests/framework/e2e/etcd_spawn_cov.go @@ -20,7 +20,6 @@ package e2e import ( "fmt" "os" - "strings" "time" "go.etcd.io/etcd/client/pkg/v3/fileutil" @@ -35,17 +34,21 @@ var ( coverDir = testutils.MustAbsPath(os.Getenv("COVERDIR")) ) +func init() { + initBinPath = initBinPathCov +} + +func initBinPathCov(binDir string) binPath { + return binPath{ + Etcd: binDir + "/etcd_test", + Etcdctl: binDir + "/etcdctl_test", + Etcdutl: binDir + "/etcdutl_test", + } +} + 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 { diff --git a/tests/framework/e2e/etcd_spawn_nocov.go b/tests/framework/e2e/etcd_spawn_nocov.go index 46748ede1..a02df0d6c 100644 --- a/tests/framework/e2e/etcd_spawn_nocov.go +++ b/tests/framework/e2e/etcd_spawn_nocov.go @@ -18,14 +18,27 @@ package e2e import ( - "go.uber.org/zap" "os" + "go.uber.org/zap" + "go.etcd.io/etcd/pkg/v3/expect" ) const noOutputLineCount = 0 // regular binaries emit no extra lines +func init() { + initBinPath = initBinPathNoCov +} + +func initBinPathNoCov(binDir string) binPath { + return binPath{ + Etcd: binDir + "/etcd", + Etcdctl: binDir + "/etcdctl", + Etcdutl: binDir + "/etcdutl", + } +} + func SpawnCmdWithLogger(lg *zap.Logger, args []string, envVars map[string]string, name string) (*expect.ExpectProcess, error) { wd, err := os.Getwd() if err != nil {