test: use T.TempDir to create temporary test directory

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>
This commit is contained in:
Eng Zer Jun
2022-03-15 11:41:08 +08:00
parent ed4cc4b482
commit 18ec2761c0
40 changed files with 137 additions and 428 deletions

View File

@@ -20,7 +20,6 @@
package overlayutils
import (
"os"
"testing"
"github.com/containerd/containerd/pkg/testutil"
@@ -30,11 +29,7 @@ import (
func testOverlaySupported(t testing.TB, expected bool, mkfs ...string) {
testutil.RequiresRoot(t)
mnt, err := os.MkdirTemp("", "containerd-fs-test-supports-overlay")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(mnt)
mnt := t.TempDir()
loop, err := loopback.New(100 << 20) // 100 MB
if err != nil {