瀏覽代碼

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.
Anthony Romano 8 年之前
父節點
當前提交
b70263247d
共有 5 個文件被更改,包括 26 次插入15 次删除
  1. 1 3
      e2e/ctl_v3_test.go
  2. 5 1
      e2e/etcd_process.go
  3. 11 8
      e2e/etcd_spawn_cov.go
  4. 9 1
      e2e/etcd_spawn_nocov.go
  5. 0 2
      e2e/main_test.go

+ 1 - 3
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)

+ 5 - 1
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 {

+ 11 - 8
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
 		}

+ 9 - 1
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:]...)
 }

+ 0 - 2
e2e/main_test.go

@@ -17,8 +17,6 @@ var (
 	binDir  string
 	certDir string
 
-	binPath        string
-	ctlBinPath     string
 	certPath       string
 	privateKeyPath string
 	caPath         string