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.
release-3.3
Anthony Romano 2017-08-31 20:30:46 -07:00
parent 9f7375c225
commit b70263247d
5 changed files with 26 additions and 15 deletions

View File

@ -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)

View File

@ -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 {

View File

@ -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
}

View File

@ -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:]...)
}

View File

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