Skip to content

Commit

Permalink
Safer temporary file deletion with t.TempDir()
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonghezzi committed Jun 22, 2021
1 parent 1ce3654 commit ea07b21
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions sdk/resource/os_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package resource_test
import (
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -90,8 +89,10 @@ func TestCharsToString(t *testing.T) {
}

func TestGetFirstAvailableFile(t *testing.T) {
file1, _ := ioutil.TempFile("", "candidate_")
file2, _ := ioutil.TempFile("", "candidate_")
tempDir := t.TempDir()

file1, _ := ioutil.TempFile(tempDir, "candidate_")
file2, _ := ioutil.TempFile(tempDir, "candidate_")

filename1, filename2 := file1.Name(), file2.Name()

Expand Down Expand Up @@ -130,7 +131,4 @@ func TestGetFirstAvailableFile(t *testing.T) {
require.Equal(t, tc.ExpectedErr, errString)
})
}

os.Remove(filename1)
os.Remove(filename2)
}

0 comments on commit ea07b21

Please sign in to comment.