|
|
@@ -15,11 +15,13 @@
|
|
|
package e2e
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"os"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
"time"
|
|
|
|
|
|
+ "github.com/coreos/etcd/pkg/flags"
|
|
|
"github.com/coreos/etcd/pkg/testutil"
|
|
|
"github.com/coreos/etcd/version"
|
|
|
)
|
|
|
@@ -57,6 +59,8 @@ type ctlCtx struct {
|
|
|
|
|
|
epc *etcdProcessCluster
|
|
|
|
|
|
+ envMap map[string]struct{}
|
|
|
+
|
|
|
dialTimeout time.Duration
|
|
|
|
|
|
quorum bool // if true, set up 3-node cluster and linearizable read
|
|
|
@@ -105,6 +109,10 @@ func withNoStrictReconfig() ctlOption {
|
|
|
return func(cx *ctlCtx) { cx.noStrictReconfig = true }
|
|
|
}
|
|
|
|
|
|
+func withFlagByEnv() ctlOption {
|
|
|
+ return func(cx *ctlCtx) { cx.envMap = make(map[string]struct{}) }
|
|
|
+}
|
|
|
+
|
|
|
func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) {
|
|
|
defer testutil.AfterTest(t)
|
|
|
|
|
|
@@ -133,6 +141,11 @@ func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) {
|
|
|
|
|
|
defer func() {
|
|
|
os.Unsetenv("ETCDCTL_API")
|
|
|
+ if ret.envMap != nil {
|
|
|
+ for k := range ret.envMap {
|
|
|
+ os.Unsetenv(k)
|
|
|
+ }
|
|
|
+ }
|
|
|
if errC := ret.epc.Close(); errC != nil {
|
|
|
t.Fatalf("error closing etcd processes (%v)", errC)
|
|
|
}
|
|
|
@@ -160,22 +173,40 @@ func (cx *ctlCtx) prefixArgs(eps []string) []string {
|
|
|
panic("v3 proxy not implemented")
|
|
|
}
|
|
|
|
|
|
- cmdArgs := []string{ctlBinPath, "--endpoints", strings.Join(eps, ","), "--dial-timeout", cx.dialTimeout.String()}
|
|
|
+ fmap := make(map[string]string)
|
|
|
+ fmap["endpoints"] = strings.Join(eps, ",")
|
|
|
+ fmap["dial-timeout"] = cx.dialTimeout.String()
|
|
|
if cx.epc.cfg.clientTLS == clientTLS {
|
|
|
if cx.epc.cfg.isClientAutoTLS {
|
|
|
- cmdArgs = append(cmdArgs, "--insecure-transport=false", "--insecure-skip-tls-verify")
|
|
|
+ fmap["insecure-transport"] = "false"
|
|
|
+ fmap["insecure-skip-tls-verify"] = "true"
|
|
|
} else {
|
|
|
- cmdArgs = append(cmdArgs, "--cacert", caPath, "--cert", certPath, "--key", privateKeyPath)
|
|
|
+ fmap["cacert"] = caPath
|
|
|
+ fmap["cert"] = certPath
|
|
|
+ fmap["key"] = privateKeyPath
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
if cx.user != "" {
|
|
|
- cmdArgs = append(cmdArgs, "--user="+cx.user+":"+cx.pass)
|
|
|
+ fmap["user"] = cx.user + ":" + cx.pass
|
|
|
}
|
|
|
|
|
|
+ useEnv := cx.envMap != nil
|
|
|
+
|
|
|
+ cmdArgs := []string{ctlBinPath}
|
|
|
+ for k, v := range fmap {
|
|
|
+ if useEnv {
|
|
|
+ ek := flags.FlagToEnv("ETCDCTL", k)
|
|
|
+ os.Setenv(ek, v)
|
|
|
+ cx.envMap[ek] = struct{}{}
|
|
|
+ } else {
|
|
|
+ cmdArgs = append(cmdArgs, fmt.Sprintf("--%s=%s", k, v))
|
|
|
+ }
|
|
|
+ }
|
|
|
return cmdArgs
|
|
|
}
|
|
|
|
|
|
+// PrefixArgs prefixes etcdctl command.
|
|
|
+// Make sure to unset environment variables after tests.
|
|
|
func (cx *ctlCtx) PrefixArgs() []string {
|
|
|
return cx.prefixArgs(cx.epc.grpcEndpoints())
|
|
|
}
|