From bbb492ee650fe9afa23b43b2766b849e5eb463df Mon Sep 17 00:00:00 2001 From: knbr13 Date: Sun, 5 Jan 2025 13:53:20 +0200 Subject: [PATCH] remove duplicate imports --- internal/fs/node_test.go | 3 +-- internal/repository/lock_test.go | 29 ++++++++++++------------- internal/repository/repair_pack_test.go | 7 +++--- internal/repository/repository_test.go | 11 +++++----- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/internal/fs/node_test.go b/internal/fs/node_test.go index 65098e30473..15f19adc7f2 100644 --- a/internal/fs/node_test.go +++ b/internal/fs/node_test.go @@ -13,7 +13,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test" ) @@ -293,5 +292,5 @@ func TestNodeRestoreMetadataError(t *testing.T) { // This will fail because the target file does not exist err := NodeRestoreMetadata(node, nodePath, func(msg string) { rtest.OK(t, fmt.Errorf("Warning triggered for path: %s: %s", nodePath, msg)) }) - test.Assert(t, errors.Is(err, os.ErrNotExist), "failed for an unexpected reason") + rtest.Assert(t, errors.Is(err, os.ErrNotExist), "failed for an unexpected reason") } diff --git a/internal/repository/lock_test.go b/internal/repository/lock_test.go index bd7cbd5e2ca..a9ff369c206 100644 --- a/internal/repository/lock_test.go +++ b/internal/repository/lock_test.go @@ -13,7 +13,6 @@ import ( "github.com/restic/restic/internal/backend/mem" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test" ) @@ -36,8 +35,8 @@ func openLockTestRepo(t *testing.T, wrapper backendWrapper) (*Repository, backen func checkedLockRepo(ctx context.Context, t *testing.T, repo *Repository, lockerInst *locker, retryLock time.Duration) (*Unlocker, context.Context) { lock, wrappedCtx, err := lockerInst.Lock(ctx, repo, false, retryLock, func(msg string) {}, func(format string, args ...interface{}) {}) - test.OK(t, err) - test.OK(t, wrappedCtx.Err()) + rtest.OK(t, err) + rtest.OK(t, wrappedCtx.Err()) if lock.info.lock.Stale() { t.Fatal("lock returned stale lock") } @@ -77,13 +76,13 @@ func TestLockConflict(t *testing.T) { repo2 := TestOpenBackend(t, be) lock, _, err := Lock(context.Background(), repo, true, 0, func(msg string) {}, func(format string, args ...interface{}) {}) - test.OK(t, err) + rtest.OK(t, err) defer lock.Unlock() _, _, err = Lock(context.Background(), repo2, false, 0, func(msg string) {}, func(format string, args ...interface{}) {}) if err == nil { t.Fatal("second lock should have failed") } - test.Assert(t, restic.IsAlreadyLocked(err), "unexpected error %v", err) + rtest.Assert(t, restic.IsAlreadyLocked(err), "unexpected error %v", err) } type writeOnceBackend struct { @@ -241,7 +240,7 @@ func TestLockWaitTimeout(t *testing.T) { repo, _ := openLockTestRepo(t, nil) elock, _, err := Lock(context.TODO(), repo, true, 0, func(msg string) {}, func(format string, args ...interface{}) {}) - test.OK(t, err) + rtest.OK(t, err) defer elock.Unlock() retryLock := 200 * time.Millisecond @@ -250,11 +249,11 @@ func TestLockWaitTimeout(t *testing.T) { _, _, err = Lock(context.TODO(), repo, false, retryLock, func(msg string) {}, func(format string, args ...interface{}) {}) duration := time.Since(start) - test.Assert(t, err != nil, + rtest.Assert(t, err != nil, "create normal lock with exclusively locked repo didn't return an error") - test.Assert(t, strings.Contains(err.Error(), "repository is already locked exclusively"), + rtest.Assert(t, strings.Contains(err.Error(), "repository is already locked exclusively"), "create normal lock with exclusively locked repo didn't return the correct error") - test.Assert(t, retryLock <= duration && duration < retryLock*3/2, + rtest.Assert(t, retryLock <= duration && duration < retryLock*3/2, "create normal lock with exclusively locked repo didn't wait for the specified timeout") } @@ -263,7 +262,7 @@ func TestLockWaitCancel(t *testing.T) { repo, _ := openLockTestRepo(t, nil) elock, _, err := Lock(context.TODO(), repo, true, 0, func(msg string) {}, func(format string, args ...interface{}) {}) - test.OK(t, err) + rtest.OK(t, err) defer elock.Unlock() retryLock := 200 * time.Millisecond @@ -276,11 +275,11 @@ func TestLockWaitCancel(t *testing.T) { _, _, err = Lock(ctx, repo, false, retryLock, func(msg string) {}, func(format string, args ...interface{}) {}) duration := time.Since(start) - test.Assert(t, err != nil, + rtest.Assert(t, err != nil, "create normal lock with exclusively locked repo didn't return an error") - test.Assert(t, strings.Contains(err.Error(), "context canceled"), + rtest.Assert(t, strings.Contains(err.Error(), "context canceled"), "create normal lock with exclusively locked repo didn't return the correct error") - test.Assert(t, cancelAfter <= duration && duration < retryLock-10*time.Millisecond, + rtest.Assert(t, cancelAfter <= duration && duration < retryLock-10*time.Millisecond, "create normal lock with exclusively locked repo didn't return in time, duration %v", duration) } @@ -289,7 +288,7 @@ func TestLockWaitSuccess(t *testing.T) { repo, _ := openLockTestRepo(t, nil) elock, _, err := Lock(context.TODO(), repo, true, 0, func(msg string) {}, func(format string, args ...interface{}) {}) - test.OK(t, err) + rtest.OK(t, err) retryLock := 200 * time.Millisecond unlockAfter := 40 * time.Millisecond @@ -299,6 +298,6 @@ func TestLockWaitSuccess(t *testing.T) { }) lock, _, err := Lock(context.TODO(), repo, false, retryLock, func(msg string) {}, func(format string, args ...interface{}) {}) - test.OK(t, err) + rtest.OK(t, err) lock.Unlock() } diff --git a/internal/repository/repair_pack_test.go b/internal/repository/repair_pack_test.go index e5f7a7f2265..5f02e7d6184 100644 --- a/internal/repository/repair_pack_test.go +++ b/internal/repository/repair_pack_test.go @@ -10,7 +10,6 @@ import ( backendtest "github.com/restic/restic/internal/backend/test" "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" "github.com/restic/restic/internal/ui/progress" ) @@ -25,10 +24,10 @@ func listBlobs(repo restic.Repository) restic.BlobSet { func replaceFile(t *testing.T, be backend.Backend, h backend.Handle, damage func([]byte) []byte) { buf, err := backendtest.LoadAll(context.TODO(), be, h) - test.OK(t, err) + rtest.OK(t, err) buf = damage(buf) - test.OK(t, be.Remove(context.TODO(), h)) - test.OK(t, be.Save(context.TODO(), h, backend.NewByteReader(buf, be.Hasher()))) + rtest.OK(t, be.Remove(context.TODO(), h)) + rtest.OK(t, be.Save(context.TODO(), h, backend.NewByteReader(buf, be.Hasher()))) } func TestRepairBrokenPack(t *testing.T) { diff --git a/internal/repository/repository_test.go b/internal/repository/repository_test.go index 3467a9cfade..5a6897f8f44 100644 --- a/internal/repository/repository_test.go +++ b/internal/repository/repository_test.go @@ -21,7 +21,6 @@ import ( "github.com/restic/restic/internal/repository" "github.com/restic/restic/internal/repository/index" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/test" rtest "github.com/restic/restic/internal/test" "golang.org/x/sync/errgroup" ) @@ -145,7 +144,7 @@ func testLoadBlob(t *testing.T, version uint) { func TestLoadBlobBroken(t *testing.T) { be := mem.New() repo, _ := repository.TestRepositoryWithBackend(t, &damageOnceBackend{Backend: be}, restic.StableRepoVersion, repository.Options{}) - buf := test.Random(42, 1000) + buf := rtest.Random(42, 1000) var wg errgroup.Group repo.StartPackUploader(context.TODO(), &wg) @@ -421,7 +420,7 @@ func TestInvalidCompression(t *testing.T) { func TestListPack(t *testing.T) { be := mem.New() repo, _ := repository.TestRepositoryWithBackend(t, &damageOnceBackend{Backend: be}, restic.StableRepoVersion, repository.Options{}) - buf := test.Random(42, 1000) + buf := rtest.Random(42, 1000) var wg errgroup.Group repo.StartPackUploader(context.TODO(), &wg) @@ -460,12 +459,12 @@ func TestNoDoubleInit(t *testing.T) { rtest.OK(t, err) pol := r.Config().ChunkerPolynomial - err = repo.Init(context.TODO(), r.Config().Version, test.TestPassword, &pol) + err = repo.Init(context.TODO(), r.Config().Version, rtest.TestPassword, &pol) rtest.Assert(t, strings.Contains(err.Error(), "repository master key and config already initialized"), "expected config exist error, got %q", err) // must also prevent init if only keys exist rtest.OK(t, be.Remove(context.TODO(), backend.Handle{Type: backend.ConfigFile})) - err = repo.Init(context.TODO(), r.Config().Version, test.TestPassword, &pol) + err = repo.Init(context.TODO(), r.Config().Version, rtest.TestPassword, &pol) rtest.Assert(t, strings.Contains(err.Error(), "repository already contains keys"), "expected already contains keys error, got %q", err) // must also prevent init if a snapshot exists and keys were deleted @@ -475,6 +474,6 @@ func TestNoDoubleInit(t *testing.T) { rtest.OK(t, be.List(context.TODO(), restic.KeyFile, func(fi backend.FileInfo) error { return be.Remove(context.TODO(), backend.Handle{Type: restic.KeyFile, Name: fi.Name}) })) - err = repo.Init(context.TODO(), r.Config().Version, test.TestPassword, &pol) + err = repo.Init(context.TODO(), r.Config().Version, rtest.TestPassword, &pol) rtest.Assert(t, strings.Contains(err.Error(), "repository already contains snapshots"), "expected already contains snapshots error, got %q", err) }