diff --git a/test.sh b/test.sh index 06137b9eb..7ffd7c58b 100755 --- a/test.sh +++ b/test.sh @@ -67,7 +67,7 @@ fi # This options make sense for cases where SUT (System Under Test) is compiled by test. COMMON_TEST_FLAGS=("${RACE}") -if [[ ! -z "${CPU}" ]]; then +if [[ -n "${CPU}" ]]; then COMMON_TEST_FLAGS+=("--cpu=${CPU}") fi diff --git a/tests/e2e/cluster_test.go b/tests/e2e/cluster_test.go index c3d8227b1..3ea04ca67 100644 --- a/tests/e2e/cluster_test.go +++ b/tests/e2e/cluster_test.go @@ -16,7 +16,6 @@ package e2e import ( "fmt" - "io/ioutil" "net/url" "os" "strings" @@ -171,7 +170,7 @@ type etcdProcessClusterConfig struct { func newEtcdProcessCluster(t testing.TB, cfg *etcdProcessClusterConfig) (*etcdProcessCluster, error) { skipInShortMode(t) - etcdCfgs := cfg.etcdServerProcessConfigs() + etcdCfgs := cfg.etcdServerProcessConfigs(t) epc := &etcdProcessCluster{ cfg: cfg, procs: make([]etcdProcess, cfg.clusterSize), @@ -217,7 +216,7 @@ func (cfg *etcdProcessClusterConfig) peerScheme() string { return peerScheme } -func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerProcessConfig { +func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs(tb testing.TB) []*etcdServerProcessConfig { if cfg.basePort == 0 { cfg.basePort = etcdProcessBasePort } @@ -247,14 +246,10 @@ func (cfg *etcdProcessClusterConfig) etcdServerProcessConfigs() []*etcdServerPro } purl := url.URL{Scheme: cfg.peerScheme(), Host: fmt.Sprintf("localhost:%d", port+1)} - name := fmt.Sprintf("testname%d", i) + name := fmt.Sprintf("test-%s-%d", tb.Name(), i) dataDirPath := cfg.dataDirPath if cfg.dataDirPath == "" { - var derr error - dataDirPath, derr = ioutil.TempDir("", name+".etcd") - if derr != nil { - panic(fmt.Sprintf("could not get tempdir for datadir: %s", derr)) - } + dataDirPath = tb.TempDir() } initialCluster[i] = fmt.Sprintf("%s=%s", name, purl.String()) diff --git a/tests/e2e/ctl_v3_snapshot_test.go b/tests/e2e/ctl_v3_snapshot_test.go index 4bcb3123d..c95a10bda 100644 --- a/tests/e2e/ctl_v3_snapshot_test.go +++ b/tests/e2e/ctl_v3_snapshot_test.go @@ -18,7 +18,6 @@ import ( "encoding/json" "fmt" "io" - "math/rand" "os" "path/filepath" "strings" @@ -32,13 +31,6 @@ import ( func TestCtlV3Snapshot(t *testing.T) { testCtl(t, snapshotTest) } -// TODO: Replace with testing.T.TestDir() in golang-1.15. -func tempDir(tb testing.TB) string { - dir := filepath.Join(os.TempDir(), tb.Name(), fmt.Sprint(rand.Int())) - os.MkdirAll(dir, 0700) - return dir -} - func snapshotTest(cx ctlCtx) { maintenanceInitKeys(cx) @@ -50,7 +42,7 @@ func snapshotTest(cx ctlCtx) { cx.t.Fatalf("snapshot: ctlV3Put error (%v)", err) } - fpath := filepath.Join(tempDir(cx.t), "snapshot") + fpath := filepath.Join(cx.t.TempDir(), "snapshot") defer os.RemoveAll(fpath) if err = ctlV3SnapshotSave(cx, fpath); err != nil { @@ -72,7 +64,7 @@ func snapshotTest(cx ctlCtx) { func TestCtlV3SnapshotCorrupt(t *testing.T) { testCtl(t, snapshotCorruptTest) } func snapshotCorruptTest(cx ctlCtx) { - fpath := filepath.Join(tempDir(cx.t), "snapshot") + fpath := filepath.Join(cx.t.TempDir(), "snapshot") defer os.RemoveAll(fpath) if err := ctlV3SnapshotSave(cx, fpath); err != nil { @@ -89,7 +81,7 @@ func snapshotCorruptTest(cx ctlCtx) { } f.Close() - datadir := filepath.Join(tempDir(cx.t), "data") + datadir := cx.t.TempDir() defer os.RemoveAll(datadir) serr := spawnWithExpect( @@ -107,7 +99,7 @@ func snapshotCorruptTest(cx ctlCtx) { func TestCtlV3SnapshotStatusBeforeRestore(t *testing.T) { testCtl(t, snapshotStatusBeforeRestoreTest) } func snapshotStatusBeforeRestoreTest(cx ctlCtx) { - fpath := filepath.Join(tempDir(cx.t), "snapshot") + fpath := filepath.Join(cx.t.TempDir(), "snapshot") defer os.RemoveAll(fpath) if err := ctlV3SnapshotSave(cx, fpath); err != nil { @@ -120,7 +112,7 @@ func snapshotStatusBeforeRestoreTest(cx ctlCtx) { cx.t.Fatalf("snapshotTest getSnapshotStatus error (%v)", err) } - dataDir := filepath.Join(tempDir(cx.t), "data") + dataDir := cx.t.TempDir() defer os.RemoveAll(dataDir) serr := spawnWithExpect( append(cx.PrefixArgs(), "snapshot", "restore", @@ -201,7 +193,7 @@ func TestIssue6361(t *testing.T) { } } - fpath := filepath.Join(tempDir(t), "snapshot") + fpath := filepath.Join(t.TempDir(), "test.snapshot") defer os.RemoveAll(fpath) t.Log("etcdctl saving snapshot...") @@ -214,7 +206,7 @@ func TestIssue6361(t *testing.T) { t.Fatal(err) } - newDataDir := tempDir(t) + newDataDir := filepath.Join(t.TempDir(), "test.data") defer os.RemoveAll(newDataDir) t.Log("etcdctl restoring the snapshot...") @@ -249,7 +241,7 @@ func TestIssue6361(t *testing.T) { t.Fatal(err) } - newDataDir2 := filepath.Join(tempDir(t), "newdata") + newDataDir2 := t.TempDir() defer os.RemoveAll(newDataDir2) name2 := "infra2"