diff options
Diffstat (limited to 'objectstore/packed')
| -rw-r--r-- | objectstore/packed/helpers_test.go | 13 | ||||
| -rw-r--r-- | objectstore/packed/read_test.go | 40 |
2 files changed, 25 insertions, 28 deletions
diff --git a/objectstore/packed/helpers_test.go b/objectstore/packed/helpers_test.go index 1b517294..581c0dd7 100644 --- a/objectstore/packed/helpers_test.go +++ b/objectstore/packed/helpers_test.go @@ -3,8 +3,6 @@ package packed_test import ( "fmt" "io" - "os" - "path/filepath" "strconv" "strings" "testing" @@ -16,17 +14,10 @@ import ( "codeberg.org/lindenii/furgit/objecttype" ) -func openPackedStore(t *testing.T, repoPath string, algo objectid.Algorithm) *packed.Store { +func openPackedStore(t *testing.T, testRepo *testgit.TestRepo, algo objectid.Algorithm) *packed.Store { t.Helper() - packPath := filepath.Join(repoPath, "objects", "pack") - - root, err := os.OpenRoot(packPath) - if err != nil { - t.Fatalf("OpenRoot(%q): %v", packPath, err) - } - - t.Cleanup(func() { _ = root.Close() }) + root := testRepo.OpenPackRoot(t) store, err := packed.New(root, algo) if err != nil { diff --git a/objectstore/packed/read_test.go b/objectstore/packed/read_test.go index 02ef4e75..435bc350 100644 --- a/objectstore/packed/read_test.go +++ b/objectstore/packed/read_test.go @@ -4,8 +4,7 @@ import ( "bytes" "errors" "fmt" - "os" - "path/filepath" + "io/fs" "strconv" "strings" "testing" @@ -20,7 +19,7 @@ func TestPackedStoreReadAgainstGit(t *testing.T) { t.Parallel() testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper testRepo, ids := createPackedFixtureRepo(t, algo) - store := openPackedStore(t, testRepo.Dir(), algo) + store := openPackedStore(t, testRepo, algo) for _, id := range ids { t.Run(id.String(), func(t *testing.T) { @@ -106,7 +105,7 @@ func TestPackedStoreErrors(t *testing.T) { t.Parallel() testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper testRepo, _ := createPackedFixtureRepo(t, algo) - store := openPackedStore(t, testRepo.Dir(), algo) + store := openPackedStore(t, testRepo, algo) notFoundID, err := objectid.ParseHex(algo, strings.Repeat("0", algo.HexLen())) if err != nil { @@ -172,7 +171,7 @@ func TestPackedStoreNewValidation(t *testing.T) { testgit.ForEachAlgorithm(t, func(t *testing.T, algo objectid.Algorithm) { //nolint:thelper testRepo, _ := createPackedFixtureRepo(t, algo) - store := openPackedStore(t, testRepo.Dir(), algo) + store := openPackedStore(t, testRepo, algo) err := store.Close() if err != nil { @@ -190,14 +189,9 @@ func TestPackedStoreInvalidAlgorithm(t *testing.T) { t.Parallel() testRepo := testgit.NewRepo(t, testgit.RepoOptions{ObjectFormat: objectid.AlgorithmSHA1, Bare: true}) - root, err := os.OpenRoot(testRepo.Dir()) - if err != nil { - t.Fatalf("OpenRoot(%q): %v", testRepo.Dir(), err) - } - - t.Cleanup(func() { _ = root.Close() }) + root := testRepo.OpenPackRoot(t) - _, err = packed.New(root, objectid.AlgorithmUnknown) + _, err := packed.New(root, objectid.AlgorithmUnknown) if !errors.Is(err, objectid.ErrInvalidAlgorithm) { t.Fatalf("packed.New invalid algorithm error = %v", err) } @@ -227,7 +221,7 @@ func TestPackedStoreReadHeaderUsesResolvedObjectSizeForDelta(t *testing.T) { testRepo.Repack(t, "-a", "-d", "-f", "--window=128", "--depth=128") deltaID, wantResolvedSize := findDeltaObjectWithResolvedSizeMismatch(t, testRepo, algo) - store := openPackedStore(t, testRepo.Dir(), algo) + store := openPackedStore(t, testRepo, algo) _, gotSize, err := store.ReadHeader(deltaID) if err != nil { @@ -252,16 +246,28 @@ func TestPackedStoreReadHeaderUsesResolvedObjectSizeForDelta(t *testing.T) { func findDeltaObjectWithResolvedSizeMismatch(t *testing.T, testRepo *testgit.TestRepo, algo objectid.Algorithm) (objectid.ObjectID, int64) { t.Helper() - idxFiles, err := filepath.Glob(filepath.Join(testRepo.Dir(), "objects", "pack", "*.idx")) + packRoot := testRepo.OpenPackRoot(t) + + entries, err := fs.ReadDir(packRoot.FS(), ".") if err != nil { - t.Fatalf("Glob idx: %v", err) + t.Fatalf("ReadDir(pack): %v", err) + } + + var idxName string + + for _, entry := range entries { + if strings.HasSuffix(entry.Name(), ".idx") { + idxName = entry.Name() + + break + } } - if len(idxFiles) == 0 { + if idxName == "" { t.Fatalf("no idx files found") } - verifyOut := testRepo.Run(t, "verify-pack", "-v", idxFiles[0]) + verifyOut := testRepo.Run(t, "verify-pack", "-v", "objects/pack/"+idxName) for line := range strings.SplitSeq(strings.TrimSpace(verifyOut), "\n") { fields := strings.Fields(line) if len(fields) < 7 { |
