test: Use testing.T.Cleanup to remove tempdirs

This commit is contained in:
greatroar
2022-12-09 13:42:33 +01:00
parent eae7366563
commit f90bf84ba7
31 changed files with 79 additions and 176 deletions

View File

@@ -185,8 +185,7 @@ func verifyRestore(t *testing.T, r *fileRestorer, repo *TestRepo) {
}
func TestFileRestorerBasic(t *testing.T) {
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
for _, sparse := range []bool{false, true} {
restoreAndVerify(t, tempdir, []TestFile{
@@ -217,8 +216,7 @@ func TestFileRestorerBasic(t *testing.T) {
}
func TestFileRestorerPackSkip(t *testing.T) {
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
files := make(map[string]bool)
files["file2"] = true
@@ -250,8 +248,7 @@ func TestFileRestorerPackSkip(t *testing.T) {
}
func TestErrorRestoreFiles(t *testing.T) {
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
content := []TestFile{
{
name: "file1",
@@ -282,8 +279,7 @@ func TestDownloadError(t *testing.T) {
}
func testPartialDownloadError(t *testing.T, part int) {
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
content := []TestFile{
{
name: "file1",

View File

@@ -8,9 +8,7 @@ import (
)
func TestFilesWriterBasic(t *testing.T) {
dir, cleanup := rtest.TempDir(t)
defer cleanup()
dir := rtest.TempDir(t)
w := newFilesWriter(1)
f1 := dir + "/f1"

View File

@@ -14,8 +14,7 @@ import (
func TestPreallocate(t *testing.T) {
for _, i := range []int64{0, 1, 4096, 1024 * 1024} {
t.Run(strconv.FormatInt(i, 10), func(t *testing.T) {
dirpath, cleanup := test.TempDir(t)
defer cleanup()
dirpath := test.TempDir(t)
flags := os.O_CREATE | os.O_TRUNC | os.O_WRONLY
wr, err := os.OpenFile(path.Join(dirpath, "test"), flags, 0600)

View File

@@ -328,9 +328,7 @@ func TestRestorer(t *testing.T) {
res := NewRestorer(context.TODO(), repo, sn, false)
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
// make sure we're creating a new subdir of the tempdir
tempdir = filepath.Join(tempdir, "target")
@@ -448,9 +446,7 @@ func TestRestorerRelative(t *testing.T) {
res := NewRestorer(context.TODO(), repo, sn, false)
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
cleanup = rtest.Chdir(t, tempdir)
defer cleanup()
@@ -682,9 +678,7 @@ func TestRestorerTraverseTree(t *testing.T) {
res.SelectFilter = test.Select
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -776,9 +770,7 @@ func TestRestorerConsistentTimestampsAndPermissions(t *testing.T) {
return selectedForRestore, childMayBeSelected
}
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -818,9 +810,7 @@ func TestVerifyCancel(t *testing.T) {
res := NewRestorer(context.TODO(), repo, sn, false)
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -863,9 +853,7 @@ func TestRestorerSparseFiles(t *testing.T) {
res := NewRestorer(context.TODO(), repo, sn, true)
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

View File

@@ -36,9 +36,7 @@ func TestRestorerRestoreEmptyHardlinkedFileds(t *testing.T) {
return true, true
}
tempdir, cleanup := rtest.TempDir(t)
defer cleanup()
tempdir := rtest.TempDir(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()