diff options
author | Justin Tobler <jtobler@gitlab.com> | 2023-02-16 17:13:10 +0300 |
---|---|---|
committer | James Fargher <jfargher@gitlab.com> | 2023-04-19 02:08:58 +0300 |
commit | 403632d13fb5d63f2737e03657655fdd0b1e2d75 (patch) | |
tree | 6803cf7872e8b0993a55c3b654041e3a83f083cb | |
parent | b51c2093ecdd65450982b47a75c17c2b7983b375 (diff) |
blob: Generate repository with LFS test data
Currently tests in `lfs_pointers_test.go` rely on seeded repositories
for test data. This caused an issue when a seeded repository was updated
resulting in `TestListAllLFSPointers` consistently failing. This change
adds `setupWithLFS()` which configures a git repository with LFS
pointers for test data.
-rw-r--r-- | internal/gitaly/service/blob/lfs_pointers_test.go | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/internal/gitaly/service/blob/lfs_pointers_test.go b/internal/gitaly/service/blob/lfs_pointers_test.go index 5ff60c722..527f19ee8 100644 --- a/internal/gitaly/service/blob/lfs_pointers_test.go +++ b/internal/gitaly/service/blob/lfs_pointers_test.go @@ -4,6 +4,7 @@ package blob import ( "bytes" + "context" "io" "os" "path/filepath" @@ -16,6 +17,7 @@ import ( "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" + "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v15/internal/helper/text" "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" @@ -403,3 +405,58 @@ func lfsPointersEqual(tb testing.TB, expected, actual []*gitalypb.LFSPointer) { testhelper.ProtoEqual(tb, expected[i], actual[i]) } } + +func setupWithLFS(tb testing.TB, ctx context.Context) (config.Cfg, *gitalypb.Repository, string, gitalypb.BlobServiceClient) { + tb.Helper() + + cfg, client := setupWithoutRepo(tb, ctx) + repo, repoPath, _ := setupRepoWithLFS(tb, ctx, cfg) + + return cfg, repo, repoPath, client +} + +type lfsRepoInfo struct { + // defaultCommitID is the object ID of the commit pointed to by the default branch. + defaultCommitID git.ObjectID + // defaultTreeID is the object ID of the tree pointed to by the default branch. + defaultTreeID git.ObjectID +} + +// setRepoWithLFS configures a git repository with LFS pointers to be used in +// testing. The commit OID and root tree OID of the default branch are returned +// for use with some tests. +func setupRepoWithLFS(tb testing.TB, ctx context.Context, cfg config.Cfg) (*gitalypb.Repository, string, lfsRepoInfo) { + tb.Helper() + + repo, repoPath := gittest.CreateRepository(tb, ctx, cfg) + + masterTreeID := gittest.WriteTree(tb, cfg, repoPath, []gittest.TreeEntry{ + {Mode: "100644", Path: lfsPointer1, Content: string(lfsPointers[lfsPointer1].Data)}, + }) + masterCommitID := gittest.WriteCommit(tb, cfg, repoPath, + gittest.WithTree(masterTreeID), + gittest.WithBranch("master"), + ) + + _ = gittest.WriteCommit(tb, cfg, repoPath, + gittest.WithTreeEntries( + gittest.TreeEntry{Mode: "100644", Path: lfsPointer2, Content: string(lfsPointers[lfsPointer2].Data)}, + gittest.TreeEntry{Mode: "100644", Path: lfsPointer3, Content: string(lfsPointers[lfsPointer3].Data)}, + ), + gittest.WithBranch("foo"), + ) + + _ = gittest.WriteCommit(tb, cfg, repoPath, + gittest.WithTreeEntries( + gittest.TreeEntry{Mode: "100644", Path: lfsPointer4, Content: string(lfsPointers[lfsPointer4].Data)}, + gittest.TreeEntry{Mode: "100644", Path: lfsPointer5, Content: string(lfsPointers[lfsPointer5].Data)}, + gittest.TreeEntry{Mode: "100644", Path: lfsPointer6, Content: string(lfsPointers[lfsPointer6].Data)}, + ), + gittest.WithBranch("bar"), + ) + + return repo, repoPath, lfsRepoInfo{ + defaultCommitID: masterCommitID, + defaultTreeID: masterTreeID, + } +} |