From b70263247d6b95c6cce9b7458b323d91cd69e882 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Thu, 31 Aug 2017 20:30:46 -0700 Subject: [PATCH] e2e: launch etcdctl with api=3 when calling etcdctl3 Setting the ETCDCTL_API=3, then calling etcdctl was unwieldy and not thread safe; all ctl v3 tests had to go through the ctlv3 wrapper and could not easily mix with v2 commands. --- e2e/ctl_v3_test.go | 4 +--- e2e/etcd_process.go | 6 +++++- e2e/etcd_spawn_cov.go | 19 +++++++++++-------- e2e/etcd_spawn_nocov.go | 10 +++++++++- e2e/main_test.go | 2 -- 5 files changed, 26 insertions(+), 15 deletions(-) diff --git a/e2e/ctl_v3_test.go b/e2e/ctl_v3_test.go index 45e2abeec..28b88b762 100644 --- a/e2e/ctl_v3_test.go +++ b/e2e/ctl_v3_test.go @@ -123,7 +123,6 @@ func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) { } ret.applyOpts(opts) - os.Setenv("ETCDCTL_API", "3") mustEtcdctl(t) if !ret.quorum { ret.cfg = *configStandalone(ret.cfg) @@ -140,7 +139,6 @@ func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) { ret.epc = epc defer func() { - os.Unsetenv("ETCDCTL_API") if ret.envMap != nil { for k := range ret.envMap { os.Unsetenv(k) @@ -192,7 +190,7 @@ func (cx *ctlCtx) prefixArgs(eps []string) []string { useEnv := cx.envMap != nil - cmdArgs := []string{ctlBinPath} + cmdArgs := []string{ctlBinPath + "3"} for k, v := range fmap { if useEnv { ek := flags.FlagToEnv("ETCDCTL", k) diff --git a/e2e/etcd_process.go b/e2e/etcd_process.go index 3ae710563..3663d248a 100644 --- a/e2e/etcd_process.go +++ b/e2e/etcd_process.go @@ -23,7 +23,11 @@ import ( "github.com/coreos/etcd/pkg/fileutil" ) -var etcdServerReadyLines = []string{"enabled capabilities for version", "published"} +var ( + etcdServerReadyLines = []string{"enabled capabilities for version", "published"} + binPath string + ctlBinPath string +) // etcdProcess is a process that serves etcd requests. type etcdProcess interface { diff --git a/e2e/etcd_spawn_cov.go b/e2e/etcd_spawn_cov.go index ca45a571e..e3098caa2 100644 --- a/e2e/etcd_spawn_cov.go +++ b/e2e/etcd_spawn_cov.go @@ -35,21 +35,24 @@ func spawnCmd(args []string) (*expect.ExpectProcess, error) { if args[0] == binPath { return spawnEtcd(args) } + if args[0] == ctlBinPath || args[0] == ctlBinPath+"3" { + // avoid test flag conflicts in coverage enabled etcdctl by putting flags in ETCDCTL_ARGS + env := []string{ + // was \xff, but that's used for testing boundary conditions; 0xe7cd should be safe + "ETCDCTL_ARGS=" + strings.Join(args, "\xe7\xcd"), + } + if args[0] == ctlBinPath+"3" { + env = append(env, "ETCDCTL_API=3") + } - if args[0] == ctlBinPath { covArgs, err := getCovArgs() if err != nil { return nil, err } - // avoid test flag conflicts in coverage enabled etcdctl by putting flags in ETCDCTL_ARGS - ctl_cov_env := []string{ - // was \xff, but that's used for testing boundary conditions; 0xe7cd should be safe - "ETCDCTL_ARGS=" + strings.Join(args, "\xe7\xcd"), - } // when withFlagByEnv() is used in testCtl(), env variables for ctl is set to os.env. // they must be included in ctl_cov_env. - ctl_cov_env = append(ctl_cov_env, os.Environ()...) - ep, err := expect.NewExpectWithEnv(binDir+"/etcdctl_test", covArgs, ctl_cov_env) + env = append(env, os.Environ()...) + ep, err := expect.NewExpectWithEnv(binDir+"/etcdctl_test", covArgs, env) if err != nil { return nil, err } diff --git a/e2e/etcd_spawn_nocov.go b/e2e/etcd_spawn_nocov.go index 82243e7e0..49d41822e 100644 --- a/e2e/etcd_spawn_nocov.go +++ b/e2e/etcd_spawn_nocov.go @@ -16,10 +16,18 @@ package e2e -import "github.com/coreos/etcd/pkg/expect" +import ( + "os" + + "github.com/coreos/etcd/pkg/expect" +) const noOutputLineCount = 0 // regular binaries emit no extra lines func spawnCmd(args []string) (*expect.ExpectProcess, error) { + if args[0] == ctlBinPath+"3" { + env := append(os.Environ(), "ETCDCTL_API=3") + return expect.NewExpectWithEnv(ctlBinPath, args[1:], env) + } return expect.NewExpect(args[0], args[1:]...) } diff --git a/e2e/main_test.go b/e2e/main_test.go index 858018a26..47691a9b3 100644 --- a/e2e/main_test.go +++ b/e2e/main_test.go @@ -17,8 +17,6 @@ var ( binDir string certDir string - binPath string - ctlBinPath string certPath string privateKeyPath string caPath string