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

@@ -122,18 +122,10 @@ func TestBtrfsMounts(t *testing.T) {
ctx := context.Background()
// create temporary directory for mount point
mountPoint, err := os.MkdirTemp("", "containerd-btrfs-test")
if err != nil {
t.Fatal("could not create mount point for btrfs test", err)
}
defer os.RemoveAll(mountPoint)
mountPoint := t.TempDir()
t.Log("temporary mount point created", mountPoint)
root, err := os.MkdirTemp(mountPoint, "TestBtrfsPrepare-")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(root)
root := t.TempDir()
b, c, err := boltSnapshotter(t)(ctx, root)
if err != nil {