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-02-14 10:38:13 +08:00
parent 5e814afe88
commit b92df1654c
7 changed files with 13 additions and 38 deletions

View File

@@ -4,14 +4,11 @@ import (
"bytes"
"fmt"
"math/rand"
"os"
"testing"
)
func TestOnDisk(t *testing.T) {
tmpDir, _ := os.MkdirTemp("", "c")
defer os.RemoveAll(tmpDir)
tmpDir := t.TempDir()
totalDiskSizeInKB := int64(32)