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:
@@ -122,10 +122,7 @@ func TestCompressDecompressUncompressed(t *testing.T) {
|
||||
|
||||
func TestDetectPigz(t *testing.T) {
|
||||
// Create fake PATH with unpigz executable, make sure detectPigz can find it
|
||||
tempPath, err := os.MkdirTemp("", "containerd_temp_")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tempPath := t.TempDir()
|
||||
|
||||
filename := "unpigz"
|
||||
if runtime.GOOS == "windows" {
|
||||
@@ -138,8 +135,6 @@ func TestDetectPigz(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
defer os.RemoveAll(tempPath)
|
||||
|
||||
oldPath := os.Getenv("PATH")
|
||||
os.Setenv("PATH", tempPath)
|
||||
defer os.Setenv("PATH", oldPath)
|
||||
|
||||
Reference in New Issue
Block a user