test: Use testing.T.Cleanup to remove tempdirs

This commit is contained in:
greatroar
2022-12-09 14:23:55 +01:00
parent eae7366563
commit f90bf84ba7
31 changed files with 79 additions and 176 deletions
+1 -2
View File
@@ -14,8 +14,7 @@ import (
)
func TestCollectTargets(t *testing.T) {
dir, cleanup := rtest.TempDir(t)
defer cleanup()
dir := rtest.TempDir(t)
fooSpace := "foo "
barStar := "bar*" // Must sort before the others, below.
+3 -6
View File
@@ -84,8 +84,7 @@ func TestIsExcludedByFile(t *testing.T) {
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
tempDir, cleanup := test.TempDir(t)
defer cleanup()
tempDir := test.TempDir(t)
foo := filepath.Join(tempDir, "foo")
err := os.WriteFile(foo, []byte("foo"), 0666)
@@ -115,8 +114,7 @@ func TestIsExcludedByFile(t *testing.T) {
// cancel each other out. It was initially written to demonstrate a bug in
// rejectIfPresent.
func TestMultipleIsExcludedByFile(t *testing.T) {
tempDir, cleanup := test.TempDir(t)
defer cleanup()
tempDir := test.TempDir(t)
// Create some files in a temporary directory.
// Files in UPPERCASE will be used as exclusion triggers later on.
@@ -240,8 +238,7 @@ func TestParseInvalidSizeStr(t *testing.T) {
// TestIsExcludedByFileSize is for testing the instance of
// --exclude-larger-than parameters
func TestIsExcludedByFileSize(t *testing.T) {
tempDir, cleanup := test.TempDir(t)
defer cleanup()
tempDir := test.TempDir(t)
// Max size of file is set to be 1k
maxSizeStr := "1k"
+1 -2
View File
@@ -31,8 +31,7 @@ func Test_PrintFunctionsRespectsGlobalStdout(t *testing.T) {
}
func TestReadRepo(t *testing.T) {
tempDir, cleanup := test.TempDir(t)
defer cleanup()
tempDir := test.TempDir(t)
// test --repo option
var opts GlobalOptions
+2 -4
View File
@@ -160,10 +160,8 @@ func TestFillSecondaryGlobalOpts(t *testing.T) {
}
//Create temp dir to create password file.
dir, cleanup := rtest.TempDir(t)
defer cleanup()
cleanup = rtest.Chdir(t, dir)
dir := rtest.TempDir(t)
cleanup := rtest.Chdir(t, dir)
defer cleanup()
//Create temporary password file