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
parent
9f7375c225
commit
b70263247d
|
@ -123,7 +123,6 @@ func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) {
|
||||||
}
|
}
|
||||||
ret.applyOpts(opts)
|
ret.applyOpts(opts)
|
||||||
|
|
||||||
os.Setenv("ETCDCTL_API", "3")
|
|
||||||
mustEtcdctl(t)
|
mustEtcdctl(t)
|
||||||
if !ret.quorum {
|
if !ret.quorum {
|
||||||
ret.cfg = *configStandalone(ret.cfg)
|
ret.cfg = *configStandalone(ret.cfg)
|
||||||
|
@ -140,7 +139,6 @@ func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) {
|
||||||
ret.epc = epc
|
ret.epc = epc
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
os.Unsetenv("ETCDCTL_API")
|
|
||||||
if ret.envMap != nil {
|
if ret.envMap != nil {
|
||||||
for k := range ret.envMap {
|
for k := range ret.envMap {
|
||||||
os.Unsetenv(k)
|
os.Unsetenv(k)
|
||||||
|
@ -192,7 +190,7 @@ func (cx *ctlCtx) prefixArgs(eps []string) []string {
|
||||||
|
|
||||||
useEnv := cx.envMap != nil
|
useEnv := cx.envMap != nil
|
||||||
|
|
||||||
cmdArgs := []string{ctlBinPath}
|
cmdArgs := []string{ctlBinPath + "3"}
|
||||||
for k, v := range fmap {
|
for k, v := range fmap {
|
||||||
if useEnv {
|
if useEnv {
|
||||||
ek := flags.FlagToEnv("ETCDCTL", k)
|
ek := flags.FlagToEnv("ETCDCTL", k)
|
||||||
|
|
|
@ -23,7 +23,11 @@ import (
|
||||||
"github.com/coreos/etcd/pkg/fileutil"
|
"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.
|
// etcdProcess is a process that serves etcd requests.
|
||||||
type etcdProcess interface {
|
type etcdProcess interface {
|
||||||
|
|
|
@ -35,21 +35,24 @@ func spawnCmd(args []string) (*expect.ExpectProcess, error) {
|
||||||
if args[0] == binPath {
|
if args[0] == binPath {
|
||||||
return spawnEtcd(args)
|
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()
|
covArgs, err := getCovArgs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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.
|
// when withFlagByEnv() is used in testCtl(), env variables for ctl is set to os.env.
|
||||||
// they must be included in ctl_cov_env.
|
// they must be included in ctl_cov_env.
|
||||||
ctl_cov_env = append(ctl_cov_env, os.Environ()...)
|
env = append(env, os.Environ()...)
|
||||||
ep, err := expect.NewExpectWithEnv(binDir+"/etcdctl_test", covArgs, ctl_cov_env)
|
ep, err := expect.NewExpectWithEnv(binDir+"/etcdctl_test", covArgs, env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,18 @@
|
||||||
|
|
||||||
package e2e
|
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
|
const noOutputLineCount = 0 // regular binaries emit no extra lines
|
||||||
|
|
||||||
func spawnCmd(args []string) (*expect.ExpectProcess, error) {
|
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:]...)
|
return expect.NewExpect(args[0], args[1:]...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,6 @@ var (
|
||||||
binDir string
|
binDir string
|
||||||
certDir string
|
certDir string
|
||||||
|
|
||||||
binPath string
|
|
||||||
ctlBinPath string
|
|
||||||
certPath string
|
certPath string
|
||||||
privateKeyPath string
|
privateKeyPath string
|
||||||
caPath string
|
caPath string
|
||||||
|
|
Loading…
Reference in New Issue