Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Hiltunen <shiltunen@gitlab.com>2023-04-13 13:13:48 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2023-04-17 17:04:48 +0300
commit0e134a21f5d173673026565304a29c4ceec37393 (patch)
tree47c3a79edc50c97efdafad6fb4eaea5bef26fe0c
parentc6595eef3a0a33e052fcd8cb304b9f5ab9f7d584 (diff)
Generalize RequireObjects to ListObjects
RequireObjects currently asserts that the repository's object database contains the expected objects. This commit extracts the object listing code from the function to ListObjects. This is more flexible as one can then do whatever is needed with the given objects. The listing code is changed to include the empty tree oid. It doesn't make sense to filter it out in the more general context. As RequireObjects is mostly now a wrapper around ListObjects, it is unnecessary as one can just pass the objects with the expected objects to require.ElementsMatch as usual.
-rw-r--r--internal/git/gittest/objects.go17
-rw-r--r--internal/git/localrepo/objects_test.go27
2 files changed, 26 insertions, 18 deletions
diff --git a/internal/git/gittest/objects.go b/internal/git/gittest/objects.go
index b96d7ffbb..eeba87c0b 100644
--- a/internal/git/gittest/objects.go
+++ b/internal/git/gittest/objects.go
@@ -20,10 +20,8 @@ func ObjectHashIsSHA256() bool {
return DefaultObjectHash.EmptyTreeOID == git.ObjectHashSHA256.EmptyTreeOID
}
-// RequireObjects asserts that the object database contains the expected objects. It filters the empty tree
-// oid of the default object hash from the actual elements. Empty tree oid should not be included in the
-// expectedObjects.
-func RequireObjects(tb testing.TB, cfg config.Cfg, repoPath string, expectedObjects []git.ObjectID) {
+// ListObjects returns a list of all object IDs in the repository.
+func ListObjects(tb testing.TB, cfg config.Cfg, repoPath string) []git.ObjectID {
tb.Helper()
rawOutput := bytes.Split(
@@ -33,19 +31,14 @@ func RequireObjects(tb testing.TB, cfg config.Cfg, repoPath string, expectedObje
[]byte{'\n'},
)
- actualObjects := []git.ObjectID{}
+ objects := []git.ObjectID{}
if len(rawOutput[0]) > 0 {
for _, oid := range rawOutput {
- oid := git.ObjectID(oid)
- if oid == DefaultObjectHash.EmptyTreeOID {
- continue
- }
-
- actualObjects = append(actualObjects, oid)
+ objects = append(objects, git.ObjectID(oid))
}
}
- require.ElementsMatch(tb, expectedObjects, actualObjects)
+ return objects
}
// RequireObjectExists asserts that the given repository does contain an object with the specified
diff --git a/internal/git/localrepo/objects_test.go b/internal/git/localrepo/objects_test.go
index d9af7525c..c57c66c1b 100644
--- a/internal/git/localrepo/objects_test.go
+++ b/internal/git/localrepo/objects_test.go
@@ -562,9 +562,16 @@ func TestWalkUnreachableObjects(t *testing.T) {
// Unpack brokenParent now that the parent has been pruned.
require.NoError(t, repo.UnpackObjects(ctx, &packedBrokenParent))
- gittest.RequireObjects(t, cfg, repoPath, []git.ObjectID{
- commit1, unreachableCommit1, unreachableCommit2, brokenParent1,
- })
+ require.ElementsMatch(t,
+ []git.ObjectID{
+ gittest.DefaultObjectHash.EmptyTreeOID,
+ commit1,
+ unreachableCommit1,
+ unreachableCommit2,
+ brokenParent1,
+ },
+ gittest.ListObjects(t, cfg, repoPath),
+ )
for _, tc := range []struct {
desc string
@@ -632,7 +639,15 @@ func TestPackAndUnpackObjects(t *testing.T) {
commit2 := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(commit1))
commit3 := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(commit2))
- gittest.RequireObjects(t, cfg, repoPath, []git.ObjectID{commit1, commit2, commit3})
+ require.ElementsMatch(t,
+ []git.ObjectID{
+ gittest.DefaultObjectHash.EmptyTreeOID,
+ commit1,
+ commit2,
+ commit3,
+ },
+ gittest.ListObjects(t, cfg, repoPath),
+ )
var emptyPack bytes.Buffer
require.NoError(t,
@@ -714,7 +729,7 @@ func TestPackAndUnpackObjects(t *testing.T) {
t.Parallel()
cfg, repo, repoPath := setupRepo(t)
- gittest.RequireObjects(t, cfg, repoPath, []git.ObjectID{})
+ require.Empty(t, gittest.ListObjects(t, cfg, repoPath))
err := repo.UnpackObjects(ctx, bytes.NewReader(tc.pack))
if tc.expectedErrorMessage != "" {
@@ -722,7 +737,7 @@ func TestPackAndUnpackObjects(t *testing.T) {
} else {
require.NoError(t, err)
}
- gittest.RequireObjects(t, cfg, repoPath, tc.expectedObjects)
+ require.ElementsMatch(t, tc.expectedObjects, gittest.ListObjects(t, cfg, repoPath))
})
}
}