diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-09 09:01:22 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-11 16:07:33 +0300 |
commit | 67871fb951e2ad6bee75a30b2b695e5e50089277 (patch) | |
tree | 1dc51905daddfa62c8389e005e6ec3a9778eb310 | |
parent | 7db1b87c46a989e0b94151fe1564194e01eca0cf (diff) |
gitpipe: Refactor CatfileInfo tests to not use seeded repos
Refactor the CatfileInfo tests to not use seeded repositories with
hardcoded object IDs. Instead, the tests are changed such that they
generate test data at runtime so that we can easily support different
object hashes.
-rw-r--r-- | internal/git/gitpipe/catfile_info_test.go | 81 |
1 files changed, 45 insertions, 36 deletions
diff --git a/internal/git/gitpipe/catfile_info_test.go b/internal/git/gitpipe/catfile_info_test.go index e9af6cfd7..76164cd3c 100644 --- a/internal/git/gitpipe/catfile_info_test.go +++ b/internal/git/gitpipe/catfile_info_test.go @@ -3,13 +3,13 @@ package gitpipe import ( + "bytes" "context" "errors" "fmt" "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile" "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo" @@ -29,12 +29,21 @@ func TestCatfileInfo(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ SkipCreationViaService: true, - Seed: gittest.SeedGitLabTest, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) + blobA := gittest.WriteBlob(t, cfg, repoPath, bytes.Repeat([]byte("a"), 133)) + blobB := gittest.WriteBlob(t, cfg, repoPath, bytes.Repeat([]byte("b"), 127)) + blobC := gittest.WriteBlob(t, cfg, repoPath, bytes.Repeat([]byte("c"), 127)) + blobD := gittest.WriteBlob(t, cfg, repoPath, bytes.Repeat([]byte("d"), 129)) + + blobID := gittest.WriteBlob(t, cfg, repoPath, []byte("contents")) + treeID := gittest.WriteTree(t, cfg, repoPath, []gittest.TreeEntry{ + {Path: "branch-test.txt", Mode: "100644", OID: blobID}, + }) + for _, tc := range []struct { desc string revlistInputs []RevisionResult @@ -45,36 +54,36 @@ func TestCatfileInfo(t *testing.T) { { desc: "single blob", revlistInputs: []RevisionResult{ - {OID: lfsPointer1}, + {OID: blobA}, }, expectedResults: []CatfileInfoResult{ - {ObjectInfo: &catfile.ObjectInfo{Oid: lfsPointer1, Type: "blob", Size: 133}}, + {ObjectInfo: &catfile.ObjectInfo{Oid: blobA, Type: "blob", Size: 133}}, }, }, { desc: "multiple blobs", revlistInputs: []RevisionResult{ - {OID: lfsPointer1}, - {OID: lfsPointer2}, - {OID: lfsPointer3}, - {OID: lfsPointer4}, + {OID: blobA}, + {OID: blobB}, + {OID: blobC}, + {OID: blobD}, }, expectedResults: []CatfileInfoResult{ - {ObjectInfo: &catfile.ObjectInfo{Oid: lfsPointer1, Type: "blob", Size: 133}}, - {ObjectInfo: &catfile.ObjectInfo{Oid: lfsPointer2, Type: "blob", Size: 127}}, - {ObjectInfo: &catfile.ObjectInfo{Oid: lfsPointer3, Type: "blob", Size: 127}}, - {ObjectInfo: &catfile.ObjectInfo{Oid: lfsPointer4, Type: "blob", Size: 129}}, + {ObjectInfo: &catfile.ObjectInfo{Oid: blobA, Type: "blob", Size: 133}}, + {ObjectInfo: &catfile.ObjectInfo{Oid: blobB, Type: "blob", Size: 127}}, + {ObjectInfo: &catfile.ObjectInfo{Oid: blobC, Type: "blob", Size: 127}}, + {ObjectInfo: &catfile.ObjectInfo{Oid: blobD, Type: "blob", Size: 129}}, }, }, { desc: "object name", revlistInputs: []RevisionResult{ - {OID: "b95c0fad32f4361845f91d9ce4c1721b52b82793"}, - {OID: "93e123ac8a3e6a0b600953d7598af629dec7b735", ObjectName: []byte("branch-test.txt")}, + {OID: treeID}, + {OID: blobID, ObjectName: []byte("branch-test.txt")}, }, expectedResults: []CatfileInfoResult{ - {ObjectInfo: &catfile.ObjectInfo{Oid: "b95c0fad32f4361845f91d9ce4c1721b52b82793", Type: "tree", Size: 43}}, - {ObjectInfo: &catfile.ObjectInfo{Oid: "93e123ac8a3e6a0b600953d7598af629dec7b735", Type: "blob", Size: 59}, ObjectName: []byte("branch-test.txt")}, + {ObjectInfo: &catfile.ObjectInfo{Oid: treeID, Type: "tree", Size: 43}}, + {ObjectInfo: &catfile.ObjectInfo{Oid: blobID, Type: "blob", Size: 8}, ObjectName: []byte("branch-test.txt")}, }, }, { @@ -87,20 +96,20 @@ func TestCatfileInfo(t *testing.T) { { desc: "mixed valid and invalid revision", revlistInputs: []RevisionResult{ - {OID: lfsPointer1}, + {OID: blobA}, {OID: "invalidobjectid"}, - {OID: lfsPointer2}, + {OID: blobB}, }, expectedResults: []CatfileInfoResult{ - {ObjectInfo: &catfile.ObjectInfo{Oid: lfsPointer1, Type: "blob", Size: 133}}, + {ObjectInfo: &catfile.ObjectInfo{Oid: blobA, Type: "blob", Size: 133}}, }, expectedErr: errors.New("retrieving object info for \"invalidobjectid\": object not found"), }, { desc: "skip everything", revlistInputs: []RevisionResult{ - {OID: lfsPointer1}, - {OID: lfsPointer2}, + {OID: blobA}, + {OID: blobB}, }, opts: []CatfileInfoOption{ WithSkipCatfileInfoResult(func(*catfile.ObjectInfo) bool { return true }), @@ -109,30 +118,30 @@ func TestCatfileInfo(t *testing.T) { { desc: "skip one", revlistInputs: []RevisionResult{ - {OID: lfsPointer1}, - {OID: lfsPointer2}, + {OID: blobA}, + {OID: blobB}, }, opts: []CatfileInfoOption{ WithSkipCatfileInfoResult(func(objectInfo *catfile.ObjectInfo) bool { - return objectInfo.Oid == lfsPointer1 + return objectInfo.Oid == blobA }), }, expectedResults: []CatfileInfoResult{ - {ObjectInfo: &catfile.ObjectInfo{Oid: lfsPointer2, Type: "blob", Size: 127}}, + {ObjectInfo: &catfile.ObjectInfo{Oid: blobB, Type: "blob", Size: 127}}, }, }, { desc: "skip nothing", revlistInputs: []RevisionResult{ - {OID: lfsPointer1}, - {OID: lfsPointer2}, + {OID: blobA}, + {OID: blobB}, }, opts: []CatfileInfoOption{ WithSkipCatfileInfoResult(func(*catfile.ObjectInfo) bool { return false }), }, expectedResults: []CatfileInfoResult{ - {ObjectInfo: &catfile.ObjectInfo{Oid: lfsPointer1, Type: "blob", Size: 133}}, - {ObjectInfo: &catfile.ObjectInfo{Oid: lfsPointer2, Type: "blob", Size: 127}}, + {ObjectInfo: &catfile.ObjectInfo{Oid: blobA, Type: "blob", Size: 133}}, + {ObjectInfo: &catfile.ObjectInfo{Oid: blobB, Type: "blob", Size: 127}}, }, }, } { @@ -175,15 +184,15 @@ func TestCatfileInfo(t *testing.T) { defer objectInfoReaderCancel() it, err := CatfileInfo(ctx, objectInfoReader, NewRevisionIterator(ctx, []RevisionResult{ - {OID: lfsPointer1}, - {OID: lfsPointer1}, + {OID: blobA}, + {OID: blobA}, })) require.NoError(t, err) require.True(t, it.Next()) require.NoError(t, it.Err()) require.Equal(t, CatfileInfoResult{ - ObjectInfo: &catfile.ObjectInfo{Oid: lfsPointer1, Type: "blob", Size: 133}, + ObjectInfo: &catfile.ObjectInfo{Oid: blobA, Type: "blob", Size: 133}, }, it.Result()) cancel() @@ -217,7 +226,7 @@ func TestCatfileInfo(t *testing.T) { // not flushed after every object this means that the request is currently // outstanding. <-nextCh - inputCh <- git.ObjectID(lfsPointer1) + inputCh <- blobA // Wait for the pipeline to request the next object. <-nextCh @@ -233,7 +242,7 @@ func TestCatfileInfo(t *testing.T) { cancel() // Now we queue another request that should cause the pipeline to fail. - inputCh <- git.ObjectID(lfsPointer1) + inputCh <- blobA // Verify whether we can receive any more objects via the iterator. This should // fail because the context got cancelled, but in any case it shouldn't block. Note @@ -258,7 +267,7 @@ func TestCatfileInfo(t *testing.T) { defer cancel() input := []RevisionResult{ - {OID: lfsPointer1}, + {OID: blobA}, } it, err := CatfileInfo(ctx, objectInfoReader, NewRevisionIterator(ctx, input)) |