From 0d08379d0a6e5c91206a82e207c6c05f0f9fddc4 Mon Sep 17 00:00:00 2001 From: Eng Zer Jun Date: Wed, 23 Mar 2022 16:04:21 +0800 Subject: 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 --- pkg/osutil/fileutil_test.go | 8 +------- pkg/osutil/osutil_test.go | 7 +------ 2 files changed, 2 insertions(+), 13 deletions(-) (limited to 'pkg/osutil') diff --git a/pkg/osutil/fileutil_test.go b/pkg/osutil/fileutil_test.go index 62e07bc8f..20d02ea22 100644 --- a/pkg/osutil/fileutil_test.go +++ b/pkg/osutil/fileutil_test.go @@ -5,8 +5,6 @@ package osutil import ( "fmt" - "io/ioutil" - "os" "path/filepath" "strconv" "sync" @@ -16,11 +14,7 @@ import ( func TestProcessTempDir(t *testing.T) { for try := 0; try < 10; try++ { func() { - tmp, err := ioutil.TempDir("", "syz") - if err != nil { - t.Fatalf("failed to create a temp dir: %v", err) - } - defer os.RemoveAll(tmp) + tmp := t.TempDir() const P = 16 // Pre-create half of the instances with stale pid. var dirs []string diff --git a/pkg/osutil/osutil_test.go b/pkg/osutil/osutil_test.go index 168e7ba36..713a62c14 100644 --- a/pkg/osutil/osutil_test.go +++ b/pkg/osutil/osutil_test.go @@ -5,7 +5,6 @@ package osutil import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -81,11 +80,7 @@ func TestCopyFiles(t *testing.T) { t.Run(fnName, func(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprint(i), func(t *testing.T) { - dir, err := ioutil.TempDir("", "syz-osutil-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(dir) + dir := t.TempDir() src := filepath.Join(dir, "src") dst := filepath.Join(dir, "dst") for _, file := range test.files { -- cgit mrf-deployment