diff options
author | Mikhail Mazurskiy <mmazurskiy@gitlab.com> | 2021-04-23 13:38:42 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-06-11 09:11:14 +0300 |
commit | e3cd1aa63e59f6d4c7c323c64dba3fd29fe2c3b8 (patch) | |
tree | 7530496e814ae876a0c51dec33cdd180c8194657 | |
parent | 29f8bbbc18287ec1b4bcfa4ab3bcf8971e3ae491 (diff) |
Move helper to avoid import cycle
29 files changed, 83 insertions, 52 deletions
diff --git a/internal/gitaly/service/blob/get_blobs_test.go b/internal/gitaly/service/blob/get_blobs_test.go index ea76cb239..3897b23fa 100644 --- a/internal/gitaly/service/blob/get_blobs_test.go +++ b/internal/gitaly/service/blob/get_blobs_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -120,7 +121,7 @@ func TestSuccessfulGetBlobsRequest(t *testing.T) { expectedBlob.Data = expectedBlob.Data[:limit] } - testhelper.ProtoEqual(t, expectedBlob, receivedBlob) + testassert.ProtoEqual(t, expectedBlob, receivedBlob) } }) } diff --git a/internal/gitaly/service/commit/between_test.go b/internal/gitaly/service/commit/between_test.go index f371124a3..81b52850a 100644 --- a/internal/gitaly/service/commit/between_test.go +++ b/internal/gitaly/service/commit/between_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -104,7 +105,7 @@ func TestSuccessfulCommitsBetween(t *testing.T) { require.Len(t, commits, len(tc.expectedCommits)) for i, commit := range commits { - testhelper.ProtoEqual(t, tc.expectedCommits[i], commit) + testassert.ProtoEqual(t, tc.expectedCommits[i], commit) } }) } diff --git a/internal/gitaly/service/commit/commit_messages_test.go b/internal/gitaly/service/commit/commit_messages_test.go index 0b441f07d..48a751b4b 100644 --- a/internal/gitaly/service/commit/commit_messages_test.go +++ b/internal/gitaly/service/commit/commit_messages_test.go @@ -9,6 +9,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -51,8 +52,8 @@ func TestSuccessfulGetCommitMessagesRequest(t *testing.T) { fetchedMessages := readAllMessagesFromClient(t, c) require.Len(t, fetchedMessages, len(expectedMessages)) - testhelper.ProtoEqual(t, expectedMessages[0], fetchedMessages[0]) - testhelper.ProtoEqual(t, expectedMessages[1], fetchedMessages[1]) + testassert.ProtoEqual(t, expectedMessages[0], fetchedMessages[0]) + testassert.ProtoEqual(t, expectedMessages[1], fetchedMessages[1]) } func TestFailedGetCommitMessagesRequest(t *testing.T) { diff --git a/internal/gitaly/service/commit/commit_signatures_test.go b/internal/gitaly/service/commit/commit_signatures_test.go index 366066b00..6cdf7660f 100644 --- a/internal/gitaly/service/commit/commit_signatures_test.go +++ b/internal/gitaly/service/commit/commit_signatures_test.go @@ -10,6 +10,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -66,7 +67,7 @@ func TestSuccessfulGetCommitSignaturesRequest(t *testing.T) { require.Len(t, fetchedSignatures, len(expectedSignatures)) for i, expected := range expectedSignatures { - testhelper.ProtoEqual(t, expected, fetchedSignatures[i]) + testassert.ProtoEqual(t, expected, fetchedSignatures[i]) } } diff --git a/internal/gitaly/service/commit/commits_by_message_test.go b/internal/gitaly/service/commit/commits_by_message_test.go index 34a4f3759..9a0f23baf 100644 --- a/internal/gitaly/service/commit/commits_by_message_test.go +++ b/internal/gitaly/service/commit/commits_by_message_test.go @@ -6,6 +6,7 @@ import ( "github.com/golang/protobuf/ptypes/timestamp" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -149,7 +150,7 @@ func TestSuccessfulCommitsByMessageRequest(t *testing.T) { require.Equal(t, len(testCase.expectedCommits), len(receivedCommits), "number of commits received") for i, receivedCommit := range receivedCommits { - testhelper.ProtoEqual(t, testCase.expectedCommits[i], receivedCommit) + testassert.ProtoEqual(t, testCase.expectedCommits[i], receivedCommit) } }) } diff --git a/internal/gitaly/service/commit/find_all_commits_test.go b/internal/gitaly/service/commit/find_all_commits_test.go index fe83df8b1..4a519f2b6 100644 --- a/internal/gitaly/service/commit/find_all_commits_test.go +++ b/internal/gitaly/service/commit/find_all_commits_test.go @@ -9,6 +9,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git" "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service/ref" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -284,7 +285,7 @@ func TestSuccessfulFindAllCommitsRequest(t *testing.T) { require.Equal(t, len(testCase.expectedCommits), len(receivedCommits), "number of commits received") for i, receivedCommit := range receivedCommits { - testhelper.ProtoEqual(t, testCase.expectedCommits[i], receivedCommit) + testassert.ProtoEqual(t, testCase.expectedCommits[i], receivedCommit) } }) } diff --git a/internal/gitaly/service/commit/find_commit_test.go b/internal/gitaly/service/commit/find_commit_test.go index c583db597..42d0473c2 100644 --- a/internal/gitaly/service/commit/find_commit_test.go +++ b/internal/gitaly/service/commit/find_commit_test.go @@ -12,6 +12,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -247,7 +248,7 @@ func TestSuccessfulFindCommitRequest(t *testing.T) { response, err := client.FindCommit(ctx, request) require.NoError(t, err) - testhelper.ProtoEqual(t, testCase.commit, response.Commit) + testassert.ProtoEqual(t, testCase.commit, response.Commit) }) } } diff --git a/internal/gitaly/service/commit/find_commits_test.go b/internal/gitaly/service/commit/find_commits_test.go index 7e39582cb..1362d234a 100644 --- a/internal/gitaly/service/commit/find_commits_test.go +++ b/internal/gitaly/service/commit/find_commits_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -166,7 +167,7 @@ func TestFindCommitsFields(t *testing.T) { require.Equal(t, 1, len(resp.Commits), "expected exactly one commit in the first message") firstCommit := resp.Commits[0] - testhelper.ProtoEqual(t, tc.commit, firstCommit) + testassert.ProtoEqual(t, tc.commit, firstCommit) _, err = stream.Recv() require.Equal(t, io.EOF, err, "there should be no further messages in the stream") diff --git a/internal/gitaly/service/commit/last_commit_for_path_test.go b/internal/gitaly/service/commit/last_commit_for_path_test.go index b246d8e20..87ae7acab 100644 --- a/internal/gitaly/service/commit/last_commit_for_path_test.go +++ b/internal/gitaly/service/commit/last_commit_for_path_test.go @@ -7,6 +7,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git" "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -66,7 +67,7 @@ func TestSuccessfulLastCommitForPathRequest(t *testing.T) { response, err := client.LastCommitForPath(ctx, request) require.NoError(t, err) - testhelper.ProtoEqual(t, testCase.commit, response.GetCommit()) + testassert.ProtoEqual(t, testCase.commit, response.GetCommit()) }) } } diff --git a/internal/gitaly/service/conflicts/list_conflict_files_test.go b/internal/gitaly/service/conflicts/list_conflict_files_test.go index b268e5b36..bad91140e 100644 --- a/internal/gitaly/service/conflicts/list_conflict_files_test.go +++ b/internal/gitaly/service/conflicts/list_conflict_files_test.go @@ -14,6 +14,7 @@ import ( "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/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -85,7 +86,7 @@ end require.Len(t, receivedFiles, len(expectedFiles)) for i := 0; i < len(expectedFiles); i++ { - testhelper.ProtoEqual(t, receivedFiles[i].header, expectedFiles[i].header) + testassert.ProtoEqual(t, receivedFiles[i].header, expectedFiles[i].header) require.Equal(t, expectedFiles[i].content, receivedFiles[i].content) } } @@ -133,7 +134,7 @@ func TestSuccessfulListConflictFilesRequestWithAncestor(t *testing.T) { require.Len(t, receivedFiles, len(expectedFiles)) for i := 0; i < len(expectedFiles); i++ { - testhelper.ProtoEqual(t, receivedFiles[i].header, expectedFiles[i].header) + testassert.ProtoEqual(t, receivedFiles[i].header, expectedFiles[i].header) } } @@ -164,14 +165,14 @@ func TestListConflictFilesHugeDiff(t *testing.T) { receivedFiles := getConflictFiles(t, c) require.Len(t, receivedFiles, 2) - testhelper.ProtoEqual(t, &gitalypb.ConflictFileHeader{ + testassert.ProtoEqual(t, &gitalypb.ConflictFileHeader{ CommitOid: our, OurMode: int32(0100644), OurPath: []byte("a"), TheirPath: []byte("a"), }, receivedFiles[0].header) - testhelper.ProtoEqual(t, &gitalypb.ConflictFileHeader{ + testassert.ProtoEqual(t, &gitalypb.ConflictFileHeader{ CommitOid: our, OurMode: int32(0100644), OurPath: []byte("b"), diff --git a/internal/gitaly/service/conflicts/resolve_conflicts_test.go b/internal/gitaly/service/conflicts/resolve_conflicts_test.go index 80019b793..9305b1135 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts_test.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts_test.go @@ -15,6 +15,7 @@ import ( "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/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -490,7 +491,7 @@ func TestResolveConflictsIdenticalContent(t *testing.T) { response, err := stream.CloseAndRecv() require.NoError(t, err) - testhelper.ProtoEqual(t, &gitalypb.ResolveConflictsResponse{ + testassert.ProtoEqual(t, &gitalypb.ResolveConflictsResponse{ ResolutionError: "Resolved content has no changes for file files/ruby/popen.rb", }, response) } diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go index 84a460fa9..6cf6a1417 100644 --- a/internal/gitaly/service/operations/branches_test.go +++ b/internal/gitaly/service/operations/branches_test.go @@ -17,6 +17,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" @@ -453,7 +454,7 @@ func testSuccessfulUserDeleteBranchRequest(t *testing.T, ctx context.Context) { User: testCase.user, }) require.NoError(t, err) - testhelper.ProtoEqual(t, testCase.response, response) + testassert.ProtoEqual(t, testCase.response, response) refs := gittest.Exec(t, cfg, "-C", repoPath, "for-each-ref", "--", "refs/heads/"+testCase.branchNameInput) require.NotContains(t, string(refs), testCase.branchCommit, "branch deleted from refs") @@ -596,7 +597,7 @@ func TestFailedUserDeleteBranchDueToValidation(t *testing.T) { t.Run(testCase.desc, func(t *testing.T) { response, err := client.UserDeleteBranch(ctx, testCase.request) require.Equal(t, testCase.err, err) - testhelper.ProtoEqual(t, testCase.response, response) + testassert.ProtoEqual(t, testCase.response, response) }) } } diff --git a/internal/gitaly/service/operations/cherry_pick_test.go b/internal/gitaly/service/operations/cherry_pick_test.go index bad4c0013..514399021 100644 --- a/internal/gitaly/service/operations/cherry_pick_test.go +++ b/internal/gitaly/service/operations/cherry_pick_test.go @@ -10,6 +10,7 @@ import ( "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/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -160,7 +161,7 @@ func TestServer_UserCherryPick_successful(t *testing.T) { require.Empty(t, response.CreateTreeErrorCode) if testCase.request.DryRun { - testhelper.ProtoEqual(t, masterHeadCommit, headCommit) + testassert.ProtoEqual(t, masterHeadCommit, headCommit) } else { require.Equal(t, testCase.request.Message, headCommit.Subject) require.Equal(t, masterHeadCommit.Id, headCommit.ParentIds[0]) @@ -505,7 +506,7 @@ func TestServer_UserCherryPick_successfulWithGivenCommits(t *testing.T) { BranchUpdate: &gitalypb.OperationBranchUpdate{CommitId: newHead.Id}, } - testhelper.ProtoEqual(t, expectedResponse, response) + testassert.ProtoEqual(t, expectedResponse, response) require.Equal(t, request.Message, newHead.Subject) require.Equal(t, testCase.startRevision.String(), newHead.ParentIds[0]) diff --git a/internal/gitaly/service/operations/merge_test.go b/internal/gitaly/service/operations/merge_test.go index bd001ee66..3a58c5510 100644 --- a/internal/gitaly/service/operations/merge_test.go +++ b/internal/gitaly/service/operations/merge_test.go @@ -19,6 +19,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text" "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -87,7 +88,7 @@ func TestSuccessfulMerge(t *testing.T) { commit, err := repo.ReadCommit(ctx, git.Revision(mergeBranchName)) require.NoError(t, err, "look up git commit after call has finished") - require.Equal(t, gitalypb.OperationBranchUpdate{CommitId: commit.Id}, *(secondResponse.BranchUpdate)) + testassert.ProtoEqual(t, &gitalypb.OperationBranchUpdate{CommitId: commit.Id}, secondResponse.BranchUpdate) require.Equal(t, commit.ParentIds, []string{mergeBranchHeadBefore, commitToMerge}) @@ -279,7 +280,7 @@ func TestFailedMergeConcurrentUpdate(t *testing.T) { secondResponse, err := mergeBidi.Recv() require.NoError(t, err, "receive second response") - testhelper.ProtoEqual(t, secondResponse, &gitalypb.UserMergeBranchResponse{}) + testassert.ProtoEqual(t, secondResponse, &gitalypb.UserMergeBranchResponse{}) commit, err := repo.ReadCommit(ctx, git.Revision(mergeBranchName)) require.NoError(t, err, "get commit after RPC finished") @@ -424,7 +425,7 @@ func TestSuccessfulUserFFBranchRequest(t *testing.T) { resp, err := client.UserFFBranch(ctx, request) require.NoError(t, err) - testhelper.ProtoEqual(t, expectedResponse, resp) + testassert.ProtoEqual(t, expectedResponse, resp) newBranchHead := gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", branchName) require.Equal(t, commitID, text.ChompBytes(newBranchHead), "branch head not updated") } @@ -585,7 +586,7 @@ func TestUserFFBranch_ambiguousReference(t *testing.T) { resp, err := client.UserFFBranch(ctx, request) require.NoError(t, err) - testhelper.ProtoEqual(t, expectedResponse, resp) + testassert.ProtoEqual(t, expectedResponse, resp) newBranchHead := gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "refs/heads/"+branchName) require.Equal(t, commitID, text.ChompBytes(newBranchHead), "branch head not updated") } @@ -877,7 +878,7 @@ func TestUserMergeToRef_stableMergeID(t *testing.T) { commit, err := repo.ReadCommit(ctx, git.Revision("refs/merge-requests/x/written")) require.NoError(t, err, "look up git commit after call has finished") - require.Equal(t, &gitalypb.GitCommit{ + testassert.ProtoEqual(t, &gitalypb.GitCommit{ Subject: []byte("Merge message"), Body: []byte("Merge message"), BodySize: 13, diff --git a/internal/gitaly/service/operations/rebase_test.go b/internal/gitaly/service/operations/rebase_test.go index a7da5bdd5..9954990ef 100644 --- a/internal/gitaly/service/operations/rebase_test.go +++ b/internal/gitaly/service/operations/rebase_test.go @@ -19,6 +19,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" @@ -232,7 +233,7 @@ func TestUserRebaseConfirmableStableCommitIDs(t *testing.T) { commit, err := repo.ReadCommit(ctx, git.Revision(rebaseBranchName)) require.NoError(t, err, "look up git commit") - testhelper.ProtoEqual(t, &gitalypb.GitCommit{ + testassert.ProtoEqual(t, &gitalypb.GitCommit{ Subject: []byte("Add a directory with many files to allow testing of default 1,000 entry limit"), Body: []byte("Add a directory with many files to allow testing of default 1,000 entry limit\n\nFor performance reasons, GitLab will add a file viewer limit and only show\nthe first 1,000 entries in a directory. Having this directory with many\nempty files in the test project will make the test easy.\n"), BodySize: 283, diff --git a/internal/gitaly/service/operations/tags_test.go b/internal/gitaly/service/operations/tags_test.go index 8668a336c..1933df193 100644 --- a/internal/gitaly/service/operations/tags_test.go +++ b/internal/gitaly/service/operations/tags_test.go @@ -21,6 +21,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text" "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" @@ -379,7 +380,7 @@ func TestUserCreateTagWithTransaction(t *testing.T) { } require.Equal(t, targetOIDOK, targetRevision) - testhelper.ProtoEqual(t, &gitalypb.UserCreateTagResponse{ + testassert.ProtoEqual(t, &gitalypb.UserCreateTagResponse{ Tag: &gitalypb.Tag{ Name: []byte(tagName), Message: []byte(testCase.message), @@ -1045,7 +1046,7 @@ func TestFailedUserDeleteTagRequestDueToValidation(t *testing.T) { t.Run(testCase.desc, func(t *testing.T) { response, err := client.UserDeleteTag(ctx, testCase.request) require.Equal(t, testCase.err, err) - testhelper.ProtoEqual(t, testCase.response, response) + testassert.ProtoEqual(t, testCase.response, response) }) } } diff --git a/internal/gitaly/service/ref/refs_test.go b/internal/gitaly/service/ref/refs_test.go index 0f877c0a6..c7d03a85a 100644 --- a/internal/gitaly/service/ref/refs_test.go +++ b/internal/gitaly/service/ref/refs_test.go @@ -20,6 +20,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/updateref" "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -1442,7 +1443,7 @@ func TestSuccessfulFindTagRequest(t *testing.T) { resp, err := client.FindTag(ctx, rpcRequest) require.NoError(t, err) - testhelper.ProtoEqual(t, expectedTag, resp.GetTag()) + testassert.ProtoEqual(t, expectedTag, resp.GetTag()) } } diff --git a/internal/gitaly/service/ref/tag_messages_test.go b/internal/gitaly/service/ref/tag_messages_test.go index 7e50502ca..a6b11df99 100644 --- a/internal/gitaly/service/ref/tag_messages_test.go +++ b/internal/gitaly/service/ref/tag_messages_test.go @@ -9,6 +9,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" ) @@ -46,8 +47,8 @@ func TestSuccessfulGetTagMessagesRequest(t *testing.T) { fetchedMessages := readAllMessagesFromClient(t, c) require.Len(t, fetchedMessages, len(expectedMessages)) - testhelper.ProtoEqual(t, expectedMessages[0], fetchedMessages[0]) - testhelper.ProtoEqual(t, expectedMessages[1], fetchedMessages[1]) + testassert.ProtoEqual(t, expectedMessages[0], fetchedMessages[0]) + testassert.ProtoEqual(t, expectedMessages[1], fetchedMessages[1]) } func TestFailedGetTagMessagesRequest(t *testing.T) { diff --git a/internal/gitaly/service/ref/testhelper_test.go b/internal/gitaly/service/ref/testhelper_test.go index 92057f7ce..55683f095 100644 --- a/internal/gitaly/service/ref/testhelper_test.go +++ b/internal/gitaly/service/ref/testhelper_test.go @@ -12,6 +12,7 @@ import ( hookservice "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service/hook" "gitlab.com/gitlab-org/gitaly/v14/internal/helper/lines" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" @@ -100,7 +101,7 @@ func assertContainsLocalBranch(t *testing.T, branches []*gitalypb.FindLocalBranc t.Errorf("Expected branch\n%v\ngot\n%v", branch, b) } - testhelper.ProtoEqual(t, branch.Commit, b.Commit) + testassert.ProtoEqual(t, branch.Commit, b.Commit) return // Found the branch and it maches. Success! } } @@ -127,7 +128,7 @@ func assertContainsBranch(t *testing.T, branches []*gitalypb.FindAllBranchesResp for _, b := range branches { if bytes.Equal(branch.Name, b.Name) { - testhelper.ProtoEqual(t, b.Target, branch.Target) + testassert.ProtoEqual(t, b.Target, branch.Target) return // Found the branch and it maches. Success! } branchNames = append(branchNames, b.Name) diff --git a/internal/gitaly/service/remote/update_remote_mirror_test.go b/internal/gitaly/service/remote/update_remote_mirror_test.go index 97771bcc7..7eea363ea 100644 --- a/internal/gitaly/service/remote/update_remote_mirror_test.go +++ b/internal/gitaly/service/remote/update_remote_mirror_test.go @@ -795,7 +795,7 @@ func testUpdateRemoteMirrorInmemory(t *testing.T, cfg config.Cfg, rubySrv *rubys })) _, err = stream.CloseAndRecv() - require.Equal(t, status.Error(codes.InvalidArgument, "in-memory remotes require `gitaly_go_update_remote_mirror` feature flag"), err) + testassert.GrpcEqualErr(t, status.Error(codes.InvalidArgument, "in-memory remotes require `gitaly_go_update_remote_mirror` feature flag"), err) }) t.Run("Go implementation succeeds", func(t *testing.T) { @@ -813,7 +813,7 @@ func testUpdateRemoteMirrorInmemory(t *testing.T, cfg config.Cfg, rubySrv *rubys response, err := stream.CloseAndRecv() require.NoError(t, err) - testhelper.ProtoEqual(t, &gitalypb.UpdateRemoteMirrorResponse{}, response) + testassert.ProtoEqual(t, &gitalypb.UpdateRemoteMirrorResponse{}, response) localRefs := string(gittest.Exec(t, cfg, "-C", localPath, "for-each-ref")) remoteRefs := string(gittest.Exec(t, cfg, "-C", remotePath, "for-each-ref")) diff --git a/internal/gitaly/service/repository/create_from_snapshot_test.go b/internal/gitaly/service/repository/create_from_snapshot_test.go index f0b61c466..1ee7d69be 100644 --- a/internal/gitaly/service/repository/create_from_snapshot_test.go +++ b/internal/gitaly/service/repository/create_from_snapshot_test.go @@ -15,6 +15,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/archive" "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -98,7 +99,7 @@ func TestCreateRepositoryFromSnapshotSuccess(t *testing.T) { rsp, err := createFromSnapshot(t, req, cfg) require.NoError(t, err) - testhelper.ProtoEqual(t, rsp, &gitalypb.CreateRepositoryFromSnapshotResponse{}) + testassert.ProtoEqual(t, rsp, &gitalypb.CreateRepositoryFromSnapshotResponse{}) repoAbsolutePath := filepath.Join(cfg.Storages[0].Path, repoRelativePath) require.DirExists(t, repoAbsolutePath) diff --git a/internal/gitaly/service/repository/snapshot_test.go b/internal/gitaly/service/repository/snapshot_test.go index bfae3962c..44b8dee87 100644 --- a/internal/gitaly/service/repository/snapshot_test.go +++ b/internal/gitaly/service/repository/snapshot_test.go @@ -21,6 +21,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/archive" "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/v14/streamio" "google.golang.org/grpc/codes" @@ -249,7 +250,7 @@ func copyRepoUsingSnapshot(t *testing.T, cfg config.Cfg, client gitalypb.Reposit defer cancel() rsp, err := client.CreateRepositoryFromSnapshot(ctx, createRepoReq) require.NoError(t, err) - testhelper.ProtoEqual(t, rsp, &gitalypb.CreateRepositoryFromSnapshotResponse{}) + testassert.ProtoEqual(t, rsp, &gitalypb.CreateRepositoryFromSnapshotResponse{}) return repoCopy, repoCopyPath, cleanupCopy } diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go index 05fd18eab..ce0ae9846 100644 --- a/internal/gitaly/service/smarthttp/receive_pack_test.go +++ b/internal/gitaly/service/smarthttp/receive_pack_test.go @@ -26,6 +26,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" pconfig "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" @@ -78,7 +79,7 @@ func TestSuccessfulReceivePackRequest(t *testing.T) { // Compare the repository up front so that we can use require.Equal for // the remaining values. - testhelper.ProtoEqual(t, repo, payload.Repo) + testassert.ProtoEqual(t, repo, payload.Repo) payload.Repo = nil // If running tests with Praefect, then these would be set, but we have diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go index 4f019a4e2..0a85567c6 100644 --- a/internal/gitaly/service/ssh/receive_pack_test.go +++ b/internal/gitaly/service/ssh/receive_pack_test.go @@ -25,6 +25,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/helper" "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" @@ -117,7 +118,7 @@ func TestReceivePackPushSuccess(t *testing.T) { // Compare the repository up front so that we can use require.Equal for // the remaining values. - testhelper.ProtoEqual(t, &gitalypb.Repository{ + testassert.ProtoEqual(t, &gitalypb.Repository{ StorageName: cfg.Storages[0].Name, RelativePath: "gitlab-test-ssh-receive-pack.git", GlProjectPath: glProjectPath, diff --git a/internal/gitaly/service/wiki/write_page_test.go b/internal/gitaly/service/wiki/write_page_test.go index a9e14cbed..eed274221 100644 --- a/internal/gitaly/service/wiki/write_page_test.go +++ b/internal/gitaly/service/wiki/write_page_test.go @@ -11,6 +11,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/rubyserver" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -153,7 +154,7 @@ func testFailedWikiWritePageDueToDuplicatePage(t *testing.T, cfg config.Cfg, rub require.NoError(t, err) expectedResponse := &gitalypb.WikiWritePageResponse{DuplicateError: []byte("Cannot write //Installing-Gitaly.md, found //Installing-Gitaly.md.")} - testhelper.ProtoEqual(t, expectedResponse, response) + testassert.ProtoEqual(t, expectedResponse, response) } func testFailedWikiWritePageInPathDueToDuplicatePage(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) { @@ -194,7 +195,7 @@ func testFailedWikiWritePageInPathDueToDuplicatePage(t *testing.T, cfg config.Cf require.NoError(t, err) expectedResponse := &gitalypb.WikiWritePageResponse{DuplicateError: []byte("Cannot write foo/Installing-Gitaly.md, found foo/Installing-Gitaly.md.")} - testhelper.ProtoEqual(t, expectedResponse, response) + testassert.ProtoEqual(t, expectedResponse, response) } func TestFailedWikiWritePageDueToValidations(t *testing.T) { diff --git a/internal/praefect/protoregistry/protoregistry_test.go b/internal/praefect/protoregistry/protoregistry_test.go index 1fdb7e5eb..f83cc6d63 100644 --- a/internal/praefect/protoregistry/protoregistry_test.go +++ b/internal/praefect/protoregistry/protoregistry_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/protoregistry" - "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" ) @@ -214,7 +214,7 @@ func TestRequestFactory(t *testing.T) { pb, err := mInfo.UnmarshalRequestProto([]byte{}) require.NoError(t, err) - testhelper.ProtoEqual(t, &gitalypb.RepositoryExistsRequest{}, pb) + testassert.ProtoEqual(t, &gitalypb.RepositoryExistsRequest{}, pb) } func TestMethodInfoScope(t *testing.T) { diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go index b3167fd9e..d2b940d56 100644 --- a/internal/praefect/replicator_test.go +++ b/internal/praefect/replicator_test.go @@ -33,6 +33,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/storage" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/promtest" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testcfg" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" @@ -494,7 +495,7 @@ func waitForRequest(t *testing.T, ch chan proto.Message, expected proto.Message, defer timer.Stop() select { case req := <-ch: - testhelper.ProtoEqual(t, expected, req) + testassert.ProtoEqual(t, expected, req) close(ch) case <-timer.C: t.Fatal("timed out") diff --git a/internal/testhelper/grpc.go b/internal/testhelper/grpc.go index a67211df7..069a589d1 100644 --- a/internal/testhelper/grpc.go +++ b/internal/testhelper/grpc.go @@ -4,8 +4,6 @@ import ( "context" "testing" - "github.com/golang/protobuf/proto" - "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" @@ -63,10 +61,3 @@ func MergeIncomingMetadata(ctx context.Context, md ...metadata.MD) context.Conte return metadata.NewIncomingContext(ctx, metadata.Join(append(md, ctxmd)...)) } - -// ProtoEqual asserts that expected and actual protobuf messages are equal. -// This is required as comparing messages directly with `require.Equal` doesn't -// work. -func ProtoEqual(t testing.TB, expected proto.Message, actual proto.Message) { - require.True(t, proto.Equal(expected, actual), "proto messages not equal\nexpected: %v\ngot: %v", expected, actual) -} diff --git a/internal/testhelper/testassert/assert.go b/internal/testhelper/testassert/assert.go new file mode 100644 index 000000000..50a473082 --- /dev/null +++ b/internal/testhelper/testassert/assert.go @@ -0,0 +1,15 @@ +package testassert + +import ( + "testing" + + "github.com/golang/protobuf/proto" + "github.com/stretchr/testify/require" +) + +// ProtoEqual asserts that expected and actual protobuf messages are equal. +// This is required as comparing messages directly with `require.Equal` doesn't +// work. +func ProtoEqual(t testing.TB, expected proto.Message, actual proto.Message) { + require.True(t, proto.Equal(expected, actual), "proto messages not equal\nexpected: %v\ngot: %v", expected, actual) +} |