diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-05-03 15:35:58 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-05-04 13:22:55 +0300 |
commit | c6de33d3ac276dfbab6827d3d961c7b1e236746c (patch) | |
tree | 43fd7da21f19049fc718de9276cbc099c92b8f19 | |
parent | 267b1005c59483c1541da7358c9d413ddd3963ff (diff) |
conflicts: Rewrite `ListConflictFiles()` tests to not use worktree
Rewrite `ListConflictFiles()` tests to not use a worktree. Tests should
instead use `gittest.WriteCommit()` and `gittest.WriteTree()` to set up
the repository state, which both don't require a worktree.
-rw-r--r-- | internal/gitaly/service/conflicts/list_conflict_files_test.go | 57 |
1 files changed, 15 insertions, 42 deletions
diff --git a/internal/gitaly/service/conflicts/list_conflict_files_test.go b/internal/gitaly/service/conflicts/list_conflict_files_test.go index bfe08d35f..e0ba4c8b7 100644 --- a/internal/gitaly/service/conflicts/list_conflict_files_test.go +++ b/internal/gitaly/service/conflicts/list_conflict_files_test.go @@ -1,18 +1,12 @@ package conflicts import ( - "bytes" - "context" "io" - "os" - "path/filepath" + "strings" "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/v14/internal/git" "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" - "gitlab.com/gitlab-org/gitaly/v14/internal/git/localrepo" - "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -26,7 +20,7 @@ type conflictFile struct { func TestSuccessfulListConflictFilesRequest(t *testing.T) { ctx := testhelper.Context(t) - _, repo, _, client := SetupConflictsService(ctx, t, false, nil) + _, repo, _, client := SetupConflictsService(ctx, t, true, nil) ourCommitOid := "1a35b5a77cf6af7edf6703f88e82f6aff613666f" theirCommitOid := "8309e68585b28d61eb85b7e2834849dda6bf1733" @@ -138,63 +132,42 @@ func TestSuccessfulListConflictFilesRequestWithAncestor(t *testing.T) { func TestListConflictFilesHugeDiff(t *testing.T) { ctx := testhelper.Context(t) - cfg, repo, repoPath, client := SetupConflictsService(ctx, t, false, nil) - - our := buildCommit(t, ctx, cfg, repo, repoPath, map[string][]byte{ - "a": bytes.Repeat([]byte("a\n"), 128*1024), - "b": bytes.Repeat([]byte("b\n"), 128*1024), - }) + cfg, repo, repoPath, client := SetupConflictsService(ctx, t, true, nil) - their := buildCommit(t, ctx, cfg, repo, repoPath, map[string][]byte{ - "a": bytes.Repeat([]byte("x\n"), 128*1024), - "b": bytes.Repeat([]byte("y\n"), 128*1024), - }) + ourCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "a", Mode: "100644", Content: strings.Repeat("a\n", 128*1024)}, + gittest.TreeEntry{Path: "b", Mode: "100644", Content: strings.Repeat("b\n", 128*1024)}, + )) + theirCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( + gittest.TreeEntry{Path: "a", Mode: "100644", Content: strings.Repeat("x\n", 128*1024)}, + gittest.TreeEntry{Path: "b", Mode: "100644", Content: strings.Repeat("y\n", 128*1024)}, + )) request := &gitalypb.ListConflictFilesRequest{ Repository: repo, - OurCommitOid: our, - TheirCommitOid: their, + OurCommitOid: ourCommitID.String(), + TheirCommitOid: theirCommitID.String(), } c, err := client.ListConflictFiles(ctx, request) require.NoError(t, err) receivedFiles := getConflictFiles(t, c) - require.Len(t, receivedFiles, 2) testhelper.ProtoEqual(t, &gitalypb.ConflictFileHeader{ - CommitOid: our, + CommitOid: ourCommitID.String(), OurMode: int32(0o100644), OurPath: []byte("a"), TheirPath: []byte("a"), }, receivedFiles[0].Header) testhelper.ProtoEqual(t, &gitalypb.ConflictFileHeader{ - CommitOid: our, + CommitOid: ourCommitID.String(), OurMode: int32(0o100644), OurPath: []byte("b"), TheirPath: []byte("b"), }, receivedFiles[1].Header) } -func buildCommit(t *testing.T, ctx context.Context, cfg config.Cfg, repo *gitalypb.Repository, repoPath string, files map[string][]byte) string { - t.Helper() - - for file, contents := range files { - filePath := filepath.Join(repoPath, file) - require.NoError(t, os.WriteFile(filePath, contents, 0o666)) - gittest.Exec(t, cfg, "-C", repoPath, "add", filePath) - } - - gittest.Exec(t, cfg, "-C", repoPath, "commit", "-m", "message") - - oid, err := localrepo.NewTestRepo(t, cfg, repo).ResolveRevision(ctx, git.Revision("HEAD")) - require.NoError(t, err) - - gittest.Exec(t, cfg, "-C", repoPath, "reset", "--hard", "HEAD~") - - return oid.String() -} - func TestListConflictFilesFailedPrecondition(t *testing.T) { ctx := testhelper.Context(t) |