From 09587e6c08a84fff1687715d03d3b27b8dd6c9ed Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 14 Apr 2024 13:57:19 +0200 Subject: [PATCH] repository: duplicate a few blobs in prune tests --- internal/repository/prune_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/repository/prune_test.go b/internal/repository/prune_test.go index 13bf58adc..bff221f49 100644 --- a/internal/repository/prune_test.go +++ b/internal/repository/prune_test.go @@ -10,6 +10,7 @@ import ( "github.com/restic/restic/internal/restic" rtest "github.com/restic/restic/internal/test" "github.com/restic/restic/internal/ui/progress" + "golang.org/x/sync/errgroup" ) func testPrune(t *testing.T, opts repository.PruneOptions, errOnUnused bool) { @@ -18,6 +19,17 @@ func testPrune(t *testing.T, opts repository.PruneOptions, errOnUnused bool) { createRandomBlobs(t, repo, 5, 0.5, true) keep, _ := selectBlobs(t, repo, 0.5) + var wg errgroup.Group + repo.StartPackUploader(context.TODO(), &wg) + // duplicate a few blobs to exercise those code paths + for blob := range keep { + buf, err := repo.LoadBlob(context.TODO(), blob.Type, blob.ID, nil) + rtest.OK(t, err) + _, _, _, err = repo.SaveBlob(context.TODO(), blob.Type, buf, blob.ID, true) + rtest.OK(t, err) + } + rtest.OK(t, repo.Flush(context.TODO())) + plan, err := repository.PlanPrune(context.TODO(), opts, repo, func(ctx context.Context, repo restic.Repository) (usedBlobs restic.CountedBlobSet, err error) { return restic.NewCountedBlobSet(keep.List()...), nil }, &progress.NoopPrinter{})