From e01baeabba114b83b405384143cfb6f661d045e3 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 18 May 2023 17:44:56 +0200 Subject: [PATCH] Use either test or rtest to refer to internal test helpers A single test file should not use both names. --- cmd/restic/global_test.go | 3 +-- cmd/restic/lock_test.go | 13 ++++++------- internal/cache/file_test.go | 3 +-- internal/repository/repository_test.go | 5 ++--- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/cmd/restic/global_test.go b/cmd/restic/global_test.go index 85a9514b9..7d2699a22 100644 --- a/cmd/restic/global_test.go +++ b/cmd/restic/global_test.go @@ -6,7 +6,6 @@ import ( "path/filepath" "testing" - "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test" ) @@ -31,7 +30,7 @@ func Test_PrintFunctionsRespectsGlobalStdout(t *testing.T) { } func TestReadRepo(t *testing.T) { - tempDir := test.TempDir(t) + tempDir := rtest.TempDir(t) // test --repo option var opts GlobalOptions diff --git a/cmd/restic/lock_test.go b/cmd/restic/lock_test.go index 86daf83f0..a07231f6d 100644 --- a/cmd/restic/lock_test.go +++ b/cmd/restic/lock_test.go @@ -11,7 +11,6 @@ import ( "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/test" - rtest "github.com/restic/restic/internal/test" ) func openTestRepo(t *testing.T, wrapper backendWrapper) (*repository.Repository, func(), *testEnvironment) { @@ -22,14 +21,14 @@ func openTestRepo(t *testing.T, wrapper backendWrapper) (*repository.Repository, testRunInit(t, env.gopts) repo, err := OpenRepository(context.TODO(), env.gopts) - rtest.OK(t, err) + test.OK(t, err) return repo, cleanup, env } func checkedLockRepo(ctx context.Context, t *testing.T, repo restic.Repository, env *testEnvironment) (*restic.Lock, context.Context) { lock, wrappedCtx, err := lockRepo(ctx, repo, env.gopts.RetryLock, env.gopts.JSON) - rtest.OK(t, err) - rtest.OK(t, wrappedCtx.Err()) + test.OK(t, err) + test.OK(t, wrappedCtx.Err()) if lock.Stale() { t.Fatal("lock returned stale lock") } @@ -69,7 +68,7 @@ func TestLockUnlockAll(t *testing.T) { lock, wrappedCtx := checkedLockRepo(context.Background(), t, repo, env) _, err := unlockAll(0) - rtest.OK(t, err) + test.OK(t, err) if wrappedCtx.Err() == nil { t.Fatal("canceled parent context did not cancel context") } @@ -82,10 +81,10 @@ func TestLockConflict(t *testing.T) { repo, cleanup, env := openTestRepo(t, nil) defer cleanup() repo2, err := OpenRepository(context.TODO(), env.gopts) - rtest.OK(t, err) + test.OK(t, err) lock, _, err := lockRepoExclusive(context.Background(), repo, env.gopts.RetryLock, env.gopts.JSON) - rtest.OK(t, err) + test.OK(t, err) defer unlockRepo(lock) _, _, err = lockRepo(context.Background(), repo2, env.gopts.RetryLock, env.gopts.JSON) if err == nil { diff --git a/internal/cache/file_test.go b/internal/cache/file_test.go index 335e78aba..e72133cd7 100644 --- a/internal/cache/file_test.go +++ b/internal/cache/file_test.go @@ -14,7 +14,6 @@ import ( "github.com/restic/restic/internal/fs" "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/test" - rtest "github.com/restic/restic/internal/test" "golang.org/x/sync/errgroup" ) @@ -271,7 +270,7 @@ func TestFileSaveConcurrent(t *testing.T) { func TestFileSaveAfterDamage(t *testing.T) { c := TestNewCache(t) - rtest.OK(t, fs.RemoveAll(c.path)) + test.OK(t, fs.RemoveAll(c.path)) // save a few bytes of data in the cache data := test.Random(123456789, 42) diff --git a/internal/repository/repository_test.go b/internal/repository/repository_test.go index 13b5ad79f..d769b4ce6 100644 --- a/internal/repository/repository_test.go +++ b/internal/repository/repository_test.go @@ -21,7 +21,6 @@ import ( "github.com/restic/restic/internal/index" "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test" "golang.org/x/sync/errgroup" ) @@ -322,7 +321,7 @@ func TestRepositoryLoadUnpackedRetryBroken(t *testing.T) { rtest.OK(t, err) repo, err := repository.New(&damageOnceBackend{Backend: be}, repository.Options{}) rtest.OK(t, err) - err = repo.SearchKey(context.TODO(), test.TestPassword, 10, "") + err = repo.SearchKey(context.TODO(), rtest.TestPassword, 10, "") rtest.OK(t, err) rtest.OK(t, repo.LoadIndex(context.TODO())) @@ -446,7 +445,7 @@ func buildPackfileWithoutHeader(t testing.TB, blobSizes []int, key *crypto.Key, var offset uint for i, size := range blobSizes { - plaintext := test.Random(800+i, size) + plaintext := rtest.Random(800+i, size) id := restic.Hash(plaintext) uncompressedLength := uint(0) if compress {