tests: Refactor BinPath into struct

Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
dependabot/go_modules/go.uber.org/atomic-1.10.0
Marek Siarkowicz 2022-10-17 12:48:49 +02:00
parent de0efc9aa4
commit d3b9951126
11 changed files with 31 additions and 22 deletions

View File

@ -25,9 +25,9 @@ import (
"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) {
e2e.BeforeTest(t)

View File

@ -187,7 +187,7 @@ func testIssue6361(t *testing.T) {
}()
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...")
kvs := []kv{{"foo1", "val1"}, {"foo2", "val2"}, {"foo3", "val3"}}
@ -214,7 +214,7 @@ func testIssue6361(t *testing.T) {
newDataDir := filepath.Join(t.TempDir(), "test.data")
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 {
t.Fatal(err)
}
@ -265,7 +265,7 @@ func testIssue6361(t *testing.T) {
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...")
for i := range kvs {

View File

@ -320,7 +320,7 @@ func (cx *ctlCtx) prefixArgs(eps []string) []string {
useEnv := cx.envMap != nil
cmdArgs := []string{e2e.CtlBinPath}
cmdArgs := []string{e2e.BinPath.Etcdctl}
for k, v := range fmap {
if useEnv {
ek := flags.FlagToEnv("ETCDCTL", k)
@ -341,7 +341,7 @@ func (cx *ctlCtx) PrefixArgs() []string {
// PrefixArgsUtl returns prefix of the command that is etcdutl
// Please not thet 'utl' compatible commands does not consume --endpoints flag.
func (cx *ctlCtx) PrefixArgsUtl() []string {
return []string{e2e.UtlBinPath}
return []string{e2e.BinPath.Etcdutl}
}
func isGRPCTimedout(err error) bool {

View File

@ -73,7 +73,7 @@ func testClusterUsingDiscovery(t *testing.T, size int, peerTLS bool) {
}
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 {
t.Fatal(err)
}

View File

@ -76,7 +76,7 @@ func testClusterUsingV3Discovery(t *testing.T, discoveryClusterSize, targetClust
defer epc.Close()
// 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 {
t.Fatal(err)
}

View File

@ -39,14 +39,14 @@ func TestGateway(t *testing.T) {
p := startGateway(t, eps)
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 {
t.Errorf("failed to finish put request through gateway: %v", err)
}
}
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 {
t.Fatal(err)
}

View File

@ -133,7 +133,7 @@ func TestEtctlutlMigrate(t *testing.T) {
}()
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...")
for i := 0; i < 10; i++ {
@ -148,7 +148,7 @@ func TestEtctlutlMigrate(t *testing.T) {
}
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 {
args = append(args, "--force")
}

View File

@ -207,7 +207,7 @@ func InitEtcdProcessCluster(t testing.TB, cfg *EtcdProcessClusterConfig) (*EtcdP
cfg.BasePort = EtcdProcessBasePort
}
if cfg.ExecPath == "" {
cfg.ExecPath = BinPath
cfg.ExecPath = BinPath.Etcd
}
if cfg.SnapshotCount == 0 {
cfg.SnapshotCount = etcdserver.DefaultSnapshotCount

View File

@ -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) {
return SpawnCmdWithLogger(zap.NewNop(), args, envVars, processName)
}
func initBinPath(binDir string) binPath {
return binPath{
Etcd: binDir + "/etcd",
Etcdctl: binDir + "/etcdctl",
Etcdutl: binDir + "/etcdutl",
}
}

View File

@ -268,7 +268,7 @@ func (ctl *EtcdctlV3) MemberRemove(ctx context.Context, id uint64) (*clientv3.Me
}
func (ctl *EtcdctlV3) cmdArgs(args ...string) []string {
cmdArgs := []string{CtlBinPath}
cmdArgs := []string{BinPath.Etcdctl}
for k, v := range ctl.flags() {
cmdArgs = append(cmdArgs, fmt.Sprintf("--%s=%s", k, v))
}

View File

@ -40,13 +40,16 @@ var (
RevokedCertPath string
RevokedPrivateKeyPath string
BinPath string
CtlBinPath string
UtlBinPath string
BinPath binPath
FixturesDir = testutils.MustAbsPath("../fixtures")
)
type binPath struct {
Etcd string
Etcdctl string
Etcdutl string
}
func InitFlags() {
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.Parse()
BinPath = BinDir + "/etcd"
CtlBinPath = BinDir + "/etcdctl"
UtlBinPath = BinDir + "/etcdutl"
BinPath = initBinPath(BinDir)
CertPath = CertDir + "/server.crt"
PrivateKeyPath = CertDir + "/server.key.insecure"
CaPath = CertDir + "/ca.crt"