tests: Refactor BinPath into struct
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>dependabot/go_modules/go.uber.org/atomic-1.10.0
parent
de0efc9aa4
commit
d3b9951126
|
@ -25,9 +25,9 @@ import (
|
||||||
"go.etcd.io/etcd/tests/v3/framework/e2e"
|
"go.etcd.io/etcd/tests/v3/framework/e2e"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.CtlBinPath, "bash") }
|
func TestCtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.BinPath.Etcdctl, "bash") }
|
||||||
|
|
||||||
func TestUtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.UtlBinPath, "bash") }
|
func TestUtlV3CompletionBash(t *testing.T) { testShellCompletion(t, e2e.BinPath.Etcdutl, "bash") }
|
||||||
|
|
||||||
func testShellCompletion(t *testing.T, binPath, shellName string) {
|
func testShellCompletion(t *testing.T, binPath, shellName string) {
|
||||||
e2e.BeforeTest(t)
|
e2e.BeforeTest(t)
|
||||||
|
|
|
@ -187,7 +187,7 @@ func testIssue6361(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
dialTimeout := 10 * time.Second
|
dialTimeout := 10 * time.Second
|
||||||
prefixArgs := []string{e2e.CtlBinPath, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()}
|
prefixArgs := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()}
|
||||||
|
|
||||||
t.Log("Writing some keys...")
|
t.Log("Writing some keys...")
|
||||||
kvs := []kv{{"foo1", "val1"}, {"foo2", "val2"}, {"foo3", "val3"}}
|
kvs := []kv{{"foo1", "val1"}, {"foo2", "val2"}, {"foo3", "val3"}}
|
||||||
|
@ -214,7 +214,7 @@ func testIssue6361(t *testing.T) {
|
||||||
|
|
||||||
newDataDir := filepath.Join(t.TempDir(), "test.data")
|
newDataDir := filepath.Join(t.TempDir(), "test.data")
|
||||||
t.Log("etcdctl restoring the snapshot...")
|
t.Log("etcdctl restoring the snapshot...")
|
||||||
err = e2e.SpawnWithExpect([]string{e2e.UtlBinPath, "snapshot", "restore", fpath, "--name", epc.Procs[0].Config().Name, "--initial-cluster", epc.Procs[0].Config().InitialCluster, "--initial-cluster-token", epc.Procs[0].Config().InitialToken, "--initial-advertise-peer-urls", epc.Procs[0].Config().Purl.String(), "--data-dir", newDataDir}, "added member")
|
err = e2e.SpawnWithExpect([]string{e2e.BinPath.Etcdutl, "snapshot", "restore", fpath, "--name", epc.Procs[0].Config().Name, "--initial-cluster", epc.Procs[0].Config().InitialCluster, "--initial-cluster-token", epc.Procs[0].Config().InitialToken, "--initial-advertise-peer-urls", epc.Procs[0].Config().Purl.String(), "--data-dir", newDataDir}, "added member")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ func testIssue6361(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
prefixArgs = []string{e2e.CtlBinPath, "--endpoints", clientURL, "--dial-timeout", dialTimeout.String()}
|
prefixArgs = []string{e2e.BinPath.Etcdctl, "--endpoints", clientURL, "--dial-timeout", dialTimeout.String()}
|
||||||
|
|
||||||
t.Log("Ensuring added member has data from incoming snapshot...")
|
t.Log("Ensuring added member has data from incoming snapshot...")
|
||||||
for i := range kvs {
|
for i := range kvs {
|
||||||
|
|
|
@ -320,7 +320,7 @@ func (cx *ctlCtx) prefixArgs(eps []string) []string {
|
||||||
|
|
||||||
useEnv := cx.envMap != nil
|
useEnv := cx.envMap != nil
|
||||||
|
|
||||||
cmdArgs := []string{e2e.CtlBinPath}
|
cmdArgs := []string{e2e.BinPath.Etcdctl}
|
||||||
for k, v := range fmap {
|
for k, v := range fmap {
|
||||||
if useEnv {
|
if useEnv {
|
||||||
ek := flags.FlagToEnv("ETCDCTL", k)
|
ek := flags.FlagToEnv("ETCDCTL", k)
|
||||||
|
@ -341,7 +341,7 @@ func (cx *ctlCtx) PrefixArgs() []string {
|
||||||
// PrefixArgsUtl returns prefix of the command that is etcdutl
|
// PrefixArgsUtl returns prefix of the command that is etcdutl
|
||||||
// Please not thet 'utl' compatible commands does not consume --endpoints flag.
|
// Please not thet 'utl' compatible commands does not consume --endpoints flag.
|
||||||
func (cx *ctlCtx) PrefixArgsUtl() []string {
|
func (cx *ctlCtx) PrefixArgsUtl() []string {
|
||||||
return []string{e2e.UtlBinPath}
|
return []string{e2e.BinPath.Etcdutl}
|
||||||
}
|
}
|
||||||
|
|
||||||
func isGRPCTimedout(err error) bool {
|
func isGRPCTimedout(err error) bool {
|
||||||
|
|
|
@ -73,7 +73,7 @@ func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) {
|
||||||
}
|
}
|
||||||
defer c.Close()
|
defer c.Close()
|
||||||
|
|
||||||
kubectl := []string{e2e.CtlBinPath, "--endpoints", strings.Join(c.EndpointsV3(), ",")}
|
kubectl := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(c.EndpointsV3(), ",")}
|
||||||
if err := e2e.SpawnWithExpect(append(kubectl, "put", "key", "value"), "OK"); err != nil {
|
if err := e2e.SpawnWithExpect(append(kubectl, "put", "key", "value"), "OK"); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ func testClusterUsingV3Discovery(t *testing.T, discoveryClusterSize, targetClust
|
||||||
defer epc.Close()
|
defer epc.Close()
|
||||||
|
|
||||||
// step 4: sanity test on the etcd cluster
|
// step 4: sanity test on the etcd cluster
|
||||||
etcdctl := []string{e2e.CtlBinPath, "--endpoints", strings.Join(epc.EndpointsV3(), ",")}
|
etcdctl := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(epc.EndpointsV3(), ",")}
|
||||||
if err := e2e.SpawnWithExpect(append(etcdctl, "put", "key", "value"), "OK"); err != nil {
|
if err := e2e.SpawnWithExpect(append(etcdctl, "put", "key", "value"), "OK"); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,14 +39,14 @@ func TestGateway(t *testing.T) {
|
||||||
p := startGateway(t, eps)
|
p := startGateway(t, eps)
|
||||||
defer p.Stop()
|
defer p.Stop()
|
||||||
|
|
||||||
err = e2e.SpawnWithExpect([]string{e2e.CtlBinPath, "--endpoints=" + defaultGatewayEndpoint, "put", "foo", "bar"}, "OK\r\n")
|
err = e2e.SpawnWithExpect([]string{e2e.BinPath.Etcdctl, "--endpoints=" + defaultGatewayEndpoint, "put", "foo", "bar"}, "OK\r\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("failed to finish put request through gateway: %v", err)
|
t.Errorf("failed to finish put request through gateway: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func startGateway(t *testing.T, endpoints string) *expect.ExpectProcess {
|
func startGateway(t *testing.T, endpoints string) *expect.ExpectProcess {
|
||||||
p, err := expect.NewExpect(e2e.BinPath, "gateway", "--endpoints="+endpoints, "start")
|
p, err := expect.NewExpect(e2e.BinPath.Etcd, "gateway", "--endpoints="+endpoints, "start")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ func TestEtctlutlMigrate(t *testing.T) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
dialTimeout := 10 * time.Second
|
dialTimeout := 10 * time.Second
|
||||||
prefixArgs := []string{e2e.CtlBinPath, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()}
|
prefixArgs := []string{e2e.BinPath.Etcdctl, "--endpoints", strings.Join(epc.EndpointsV3(), ","), "--dial-timeout", dialTimeout.String()}
|
||||||
|
|
||||||
t.Log("Write keys to ensure wal snapshot is created and all v3.5 fields are set...")
|
t.Log("Write keys to ensure wal snapshot is created and all v3.5 fields are set...")
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
|
@ -148,7 +148,7 @@ func TestEtctlutlMigrate(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Log("etcdutl migrate...")
|
t.Log("etcdutl migrate...")
|
||||||
args := []string{e2e.UtlBinPath, "migrate", "--data-dir", dataDirPath, "--target-version", tc.targetVersion}
|
args := []string{e2e.BinPath.Etcdutl, "migrate", "--data-dir", dataDirPath, "--target-version", tc.targetVersion}
|
||||||
if tc.force {
|
if tc.force {
|
||||||
args = append(args, "--force")
|
args = append(args, "--force")
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,7 @@ func InitEtcdProcessCluster(t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdP
|
||||||
cfg.BasePort = EtcdProcessBasePort
|
cfg.BasePort = EtcdProcessBasePort
|
||||||
}
|
}
|
||||||
if cfg.ExecPath == "" {
|
if cfg.ExecPath == "" {
|
||||||
cfg.ExecPath = BinPath
|
cfg.ExecPath = BinPath.Etcd
|
||||||
}
|
}
|
||||||
if cfg.SnapshotCount == 0 {
|
if cfg.SnapshotCount == 0 {
|
||||||
cfg.SnapshotCount = etcdserver.DefaultSnapshotCount
|
cfg.SnapshotCount = etcdserver.DefaultSnapshotCount
|
||||||
|
|
|
@ -29,3 +29,11 @@ func SpawnCmd(args []string, envVars map[string]string) (*expect.ExpectProcess,
|
||||||
func SpawnNamedCmd(processName string, args []string, envVars map[string]string) (*expect.ExpectProcess, error) {
|
func SpawnNamedCmd(processName string, args []string, envVars map[string]string) (*expect.ExpectProcess, error) {
|
||||||
return SpawnCmdWithLogger(zap.NewNop(), args, envVars, processName)
|
return SpawnCmdWithLogger(zap.NewNop(), args, envVars, processName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initBinPath(binDir string) binPath {
|
||||||
|
return binPath{
|
||||||
|
Etcd: binDir + "/etcd",
|
||||||
|
Etcdctl: binDir + "/etcdctl",
|
||||||
|
Etcdutl: binDir + "/etcdutl",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -268,7 +268,7 @@ func (ctl *EtcdctlV3) MemberRemove(ctx context.Context, id uint64) (*clientv3.Me
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ctl *EtcdctlV3) cmdArgs(args ...string) []string {
|
func (ctl *EtcdctlV3) cmdArgs(args ...string) []string {
|
||||||
cmdArgs := []string{CtlBinPath}
|
cmdArgs := []string{BinPath.Etcdctl}
|
||||||
for k, v := range ctl.flags() {
|
for k, v := range ctl.flags() {
|
||||||
cmdArgs = append(cmdArgs, fmt.Sprintf("--%s=%s", k, v))
|
cmdArgs = append(cmdArgs, fmt.Sprintf("--%s=%s", k, v))
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,13 +40,16 @@ var (
|
||||||
RevokedCertPath string
|
RevokedCertPath string
|
||||||
RevokedPrivateKeyPath string
|
RevokedPrivateKeyPath string
|
||||||
|
|
||||||
BinPath string
|
BinPath binPath
|
||||||
CtlBinPath string
|
|
||||||
UtlBinPath string
|
|
||||||
|
|
||||||
FixturesDir = testutils.MustAbsPath("../fixtures")
|
FixturesDir = testutils.MustAbsPath("../fixtures")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type binPath struct {
|
||||||
|
Etcd string
|
||||||
|
Etcdctl string
|
||||||
|
Etcdutl string
|
||||||
|
}
|
||||||
|
|
||||||
func InitFlags() {
|
func InitFlags() {
|
||||||
os.Setenv("ETCD_UNSUPPORTED_ARCH", runtime.GOARCH)
|
os.Setenv("ETCD_UNSUPPORTED_ARCH", runtime.GOARCH)
|
||||||
|
|
||||||
|
@ -57,9 +60,7 @@ func InitFlags() {
|
||||||
flag.StringVar(&CertDir, "cert-dir", certDirDef, "The directory for store certificate files.")
|
flag.StringVar(&CertDir, "cert-dir", certDirDef, "The directory for store certificate files.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
BinPath = BinDir + "/etcd"
|
BinPath = initBinPath(BinDir)
|
||||||
CtlBinPath = BinDir + "/etcdctl"
|
|
||||||
UtlBinPath = BinDir + "/etcdutl"
|
|
||||||
CertPath = CertDir + "/server.crt"
|
CertPath = CertDir + "/server.crt"
|
||||||
PrivateKeyPath = CertDir + "/server.key.insecure"
|
PrivateKeyPath = CertDir + "/server.key.insecure"
|
||||||
CaPath = CertDir + "/ca.crt"
|
CaPath = CertDir + "/ca.crt"
|
||||||
|
|
Loading…
Reference in New Issue