diff options
| author | Eng Zer Jun <engzerjun@gmail.com> | 2022-03-23 16:04:21 +0800 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2022-03-28 12:03:24 +0200 |
| commit | 0d08379d0a6e5c91206a82e207c6c05f0f9fddc4 (patch) | |
| tree | 56b9d5c90b545c2d2e7bd74b059b1d1e2be50834 /pkg/bisect | |
| parent | 89bc860804252dbacb8c2bea60b9204859f4afd7 (diff) | |
all: use `t.TempDir` to create temporary test directory
This commit replaces all `ioutil.TempDir` with `t.TempDir` in tests.
The directory created by `t.TempDir` is automatically removed when the
test and all its subtests complete.
Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Diffstat (limited to 'pkg/bisect')
| -rw-r--r-- | pkg/bisect/bisect_test.go | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/pkg/bisect/bisect_test.go b/pkg/bisect/bisect_test.go index 7a05afb36..eebe48e37 100644 --- a/pkg/bisect/bisect_test.go +++ b/pkg/bisect/bisect_test.go @@ -5,8 +5,6 @@ package bisect import ( "fmt" - "io/ioutil" - "os" "strconv" "testing" @@ -84,10 +82,7 @@ func (env *testEnv) headCommit() int { } func createTestRepo(t *testing.T) string { - baseDir, err := ioutil.TempDir("", "syz-bisect-test") - if err != nil { - t.Fatal(err) - } + baseDir := t.TempDir() repo := vcs.CreateTestRepo(t, baseDir, "") if !repo.SupportsBisection() { t.Skip("bisection is unsupported by git (probably too old version)") @@ -432,17 +427,17 @@ func TestBisectionResults(t *testing.T) { // Creating new repos takes majority of the test time, // so we reuse them across tests. repoCache := make(chan string, len(bisectionTests)) - t.Run("group", func(t *testing.T) { + t.Run("group", func(tt *testing.T) { for _, test := range bisectionTests { test := test - t.Run(test.name, func(t *testing.T) { + tt.Run(test.name, func(t *testing.T) { t.Parallel() checkTest(t, test) repoDir := "" select { case repoDir = <-repoCache: default: - repoDir = createTestRepo(t) + repoDir = createTestRepo(tt) } defer func() { repoCache <- repoDir @@ -485,14 +480,6 @@ func TestBisectionResults(t *testing.T) { }) } }) - for { - select { - case dir := <-repoCache: - os.RemoveAll(dir) - default: - return - } - } } func checkTest(t *testing.T, test BisectionTest) { |
