diff options
author | Mikhail Mazurskiy <mmazurskiy@gitlab.com> | 2021-04-23 14:26:26 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-06-11 09:11:14 +0300 |
commit | d32f88d89abe04a500ad64eabf8ea0d619f2259f (patch) | |
tree | 5474dd2a3ec1f752642d457e2e8cb2296ee93392 | |
parent | 62cb10ffed99c3c3a2e0dcaec9d673b90dda437a (diff) |
Fix issues in tests
Changelog: changed
38 files changed, 184 insertions, 124 deletions
diff --git a/client/dial_test.go b/client/dial_test.go index 4399cdfb3..ac8e26f0f 100644 --- a/client/dial_test.go +++ b/client/dial_test.go @@ -18,6 +18,7 @@ import ( gitalyauth "gitlab.com/gitlab-org/gitaly/v14/auth" proxytestdata "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/grpc-proxy/testdata" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" gitaly_x509 "gitlab.com/gitlab-org/gitaly/v14/internal/x509" "gitlab.com/gitlab-org/labkit/correlation" grpccorrelation "gitlab.com/gitlab-org/labkit/correlation/grpc" @@ -293,6 +294,7 @@ func TestDial_Tracing(t *testing.T) { t.Run("unary", func(t *testing.T) { reporter := jaeger.NewInMemoryReporter() tracer, tracerCloser := jaeger.NewTracer("", jaeger.NewConstSampler(true), reporter) + defer tracerCloser.Close() defer func(old opentracing.Tracer) { opentracing.SetGlobalTracer(old) }(opentracing.GlobalTracer()) opentracing.SetGlobalTracer(tracer) @@ -318,7 +320,6 @@ func TestDial_Tracing(t *testing.T) { require.NoError(t, err) span.Finish() - tracerCloser.Close() spans := reporter.GetSpans() require.Len(t, spans, 3) @@ -350,6 +351,7 @@ func TestDial_Tracing(t *testing.T) { t.Run("stream", func(t *testing.T) { reporter := jaeger.NewInMemoryReporter() tracer, tracerCloser := jaeger.NewTracer("", jaeger.NewConstSampler(true), reporter) + defer tracerCloser.Close() defer func(old opentracing.Tracer) { opentracing.SetGlobalTracer(old) }(opentracing.GlobalTracer()) opentracing.SetGlobalTracer(tracer) @@ -380,7 +382,6 @@ func TestDial_Tracing(t *testing.T) { require.Nil(t, resp) span.Finish() - tracerCloser.Close() spans := reporter.GetSpans() require.Len(t, spans, 3) @@ -526,9 +527,9 @@ func TestHealthCheckDialer(t *testing.T) { defer cancel() _, err := HealthCheckDialer(DialContext)(ctx, addr, nil) - require.Equal(t, status.Error(codes.Unauthenticated, "authentication required"), err, "should fail without token configured") + testassert.GrpcEqualErr(t, status.Error(codes.Unauthenticated, "authentication required"), err) cc, err := HealthCheckDialer(DialContext)(ctx, addr, []grpc.DialOption{grpc.WithPerRPCCredentials(gitalyauth.RPCCredentialsV2("token"))}) require.NoError(t, err) - cc.Close() + require.NoError(t, cc.Close()) } diff --git a/cmd/praefect/subcmd_pingnodes_test.go b/cmd/praefect/subcmd_pingnodes_test.go index 30d150f57..a207a4a80 100644 --- a/cmd/praefect/subcmd_pingnodes_test.go +++ b/cmd/praefect/subcmd_pingnodes_test.go @@ -40,7 +40,7 @@ func TestSubCmdDialNodes(t *testing.T) { decorateLogs := func(s []string) []string { for i, ss := range s { - s[i] = fmt.Sprintf("[unix:/%s]: %s\n", ln.Addr(), ss) + s[i] = fmt.Sprintf("[unix://%s]: %s\n", ln.Addr(), ss) } return s } @@ -60,7 +60,7 @@ func TestSubCmdDialNodes(t *testing.T) { Nodes: []*config.Node{ { Storage: "1", - Address: "unix:/" + ln.Addr().String(), + Address: "unix://" + ln.Addr().String(), }, }, }, @@ -69,7 +69,7 @@ func TestSubCmdDialNodes(t *testing.T) { Nodes: []*config.Node{ { Storage: "2", - Address: "unix:/" + ln.Addr().String(), + Address: "unix://" + ln.Addr().String(), }, }, }, diff --git a/cmd/praefect/subcmd_set_replication_factor_test.go b/cmd/praefect/subcmd_set_replication_factor_test.go index adefb3dc7..f2598f192 100644 --- a/cmd/praefect/subcmd_set_replication_factor_test.go +++ b/cmd/praefect/subcmd_set_replication_factor_test.go @@ -12,6 +12,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/service/info" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -104,7 +105,7 @@ func TestSetReplicationFactorSubcommand(t *testing.T) { err := cmd.Exec(fs, config.Config{ SocketPath: ln.Addr().String(), }) - require.Equal(t, tc.error, err) + testassert.GrpcEqualErr(t, tc.error, err) require.Equal(t, tc.stdout, stdout.String()) }) } diff --git a/internal/backchannel/backchannel_test.go b/internal/backchannel/backchannel_test.go index 283f0caf6..c8b8d1081 100644 --- a/internal/backchannel/backchannel_test.go +++ b/internal/backchannel/backchannel_test.go @@ -13,6 +13,7 @@ import ( "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -97,7 +98,7 @@ func TestBackchannel_concurrentRequestsFromMultipleClients(t *testing.T) { } resp, err := gitalypb.NewRefTransactionClient(client).VoteTransaction(ctx, &gitalypb.VoteTransactionRequest{}) - assert.Equal(t, err, errNonMultiplexed) + testassert.GrpcEqualErr(t, errNonMultiplexed, err) assert.Nil(t, resp) assert.NoError(t, client.Close()) @@ -112,7 +113,7 @@ func TestBackchannel_concurrentRequestsFromMultipleClients(t *testing.T) { srv := grpc.NewServer() gitalypb.RegisterRefTransactionServer(srv, mockTransactionServer{ voteTransactionFunc: func(ctx context.Context, req *gitalypb.VoteTransactionRequest) (*gitalypb.VoteTransactionResponse, error) { - assert.Equal(t, &gitalypb.VoteTransactionRequest{TransactionId: i}, req) + testassert.ProtoEqual(t, &gitalypb.VoteTransactionRequest{TransactionId: i}, req) return nil, expectedErr }, }) @@ -136,7 +137,7 @@ func TestBackchannel_concurrentRequestsFromMultipleClients(t *testing.T) { go func() { defer invocations.Done() resp, err := gitalypb.NewRefTransactionClient(client).VoteTransaction(ctx, &gitalypb.VoteTransactionRequest{TransactionId: i}) - assert.Equal(t, err, expectedErr) + testassert.GrpcEqualErr(t, expectedErr, err) assert.Nil(t, resp) }() } diff --git a/internal/gitaly/service/blob/get_blobs_test.go b/internal/gitaly/service/blob/get_blobs_test.go index 3897b23fa..fa8a23029 100644 --- a/internal/gitaly/service/blob/get_blobs_test.go +++ b/internal/gitaly/service/blob/get_blobs_test.go @@ -121,6 +121,10 @@ func TestSuccessfulGetBlobsRequest(t *testing.T) { expectedBlob.Data = expectedBlob.Data[:limit] } + // comparison of the huge blobs is not possible with testassert.ProtoEqual + // we compare them manually and override to use in testassert.ProtoEqual + require.Equal(t, expectedBlob.Data, receivedBlob.Data) + expectedBlob.Data, receivedBlob.Data = nil, nil testassert.ProtoEqual(t, expectedBlob, receivedBlob) } }) diff --git a/internal/gitaly/service/blob/lfs_pointers_test.go b/internal/gitaly/service/blob/lfs_pointers_test.go index 922f66932..0970e9ffe 100644 --- a/internal/gitaly/service/blob/lfs_pointers_test.go +++ b/internal/gitaly/service/blob/lfs_pointers_test.go @@ -19,6 +19,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/helper/chunk" "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/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -166,7 +167,7 @@ func TestListLFSPointers(t *testing.T) { if err == io.EOF { break } - require.Equal(t, err, tc.expectedErr) + testassert.GrpcEqualErr(t, tc.expectedErr, err) if err != nil { break } @@ -682,7 +683,7 @@ func lfsPointersEqual(tb testing.TB, expected, actual []*gitalypb.LFSPointer) { require.Equal(tb, len(expected), len(actual)) for i := range expected { - testhelper.ProtoEqual(tb, expected[i], actual[i]) + testassert.ProtoEqual(tb, expected[i], actual[i]) } } diff --git a/internal/gitaly/service/conflicts/resolve_conflicts_test.go b/internal/gitaly/service/conflicts/resolve_conflicts_test.go index 9305b1135..83fb7ce69 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts_test.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts_test.go @@ -396,7 +396,7 @@ func TestResolveConflictsNonOIDRequests(t *testing.T) { })) _, err = stream.CloseAndRecv() - require.Equal(t, status.Errorf(codes.Unknown, "Rugged::InvalidError: unable to parse OID - contains invalid characters"), err) + testassert.GrpcEqualErr(t, status.Errorf(codes.Unknown, "Rugged::InvalidError: unable to parse OID - contains invalid characters"), err) } func TestResolveConflictsIdenticalContent(t *testing.T) { diff --git a/internal/gitaly/service/diff/find_changed_paths_test.go b/internal/gitaly/service/diff/find_changed_paths_test.go index 7828de3da..a6bceb939 100644 --- a/internal/gitaly/service/diff/find_changed_paths_test.go +++ b/internal/gitaly/service/diff/find_changed_paths_test.go @@ -7,6 +7,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/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -161,7 +162,7 @@ func TestFindChangedPathsRequest_failing(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { _, err := stream.Recv() - require.Equal(t, tc.err, err) + testassert.GrpcEqualErr(t, tc.err, err) }) } } diff --git a/internal/gitaly/service/objectpool/create_test.go b/internal/gitaly/service/objectpool/create_test.go index dfd4404c0..b04a62c8d 100644 --- a/internal/gitaly/service/objectpool/create_test.go +++ b/internal/gitaly/service/objectpool/create_test.go @@ -11,9 +11,9 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v14/internal/git/objectpool" "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/testserver" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" - "google.golang.org/grpc/status" ) func TestCreate(t *testing.T) { @@ -142,7 +142,7 @@ func TestUnsuccessfulCreate(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { _, err := client.CreateObjectPool(ctx, tc.request) - require.Equal(t, status.Convert(tc.error).Err(), err) + testassert.GrpcEqualErr(t, tc.error, err) }) } } @@ -209,7 +209,7 @@ func TestDelete(t *testing.T) { RelativePath: tc.relativePath, }, }}) - require.Equal(t, status.Convert(tc.error).Err(), err) + testassert.GrpcEqualErr(t, tc.error, err) }) } } diff --git a/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go b/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go index a037b1f42..75dca79f4 100644 --- a/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go +++ b/internal/gitaly/service/objectpool/fetch_into_object_pool_test.go @@ -21,6 +21,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/objectpool" "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" "gitlab.com/gitlab-org/labkit/log" @@ -116,7 +117,7 @@ func TestFetchIntoObjectPool_hooks(t *testing.T) { } _, err = client.FetchIntoObjectPool(ctx, req) - require.Equal(t, status.Error(codes.Internal, "fetch into object pool: exit status 128, stderr: \"fatal: ref updates aborted by hook\\n\""), err) + testassert.GrpcEqualErr(t, status.Error(codes.Internal, "fetch into object pool: exit status 128, stderr: \"fatal: ref updates aborted by hook\\n\""), err) } func TestFetchIntoObjectPool_CollectLogStatistics(t *testing.T) { diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go index 6cf6a1417..d9fb4c936 100644 --- a/internal/gitaly/service/operations/branches_test.go +++ b/internal/gitaly/service/operations/branches_test.go @@ -312,7 +312,7 @@ func TestSuccessfulCreateBranchRequestWithStartPointRefPrefix(t *testing.T) { TargetCommit: targetCommitOK, }, } - require.Equal(t, responseOk, response) + testassert.ProtoEqual(t, responseOk, response) branches := gittest.Exec(t, cfg, "-C", repoPath, "for-each-ref", "--", "refs/heads/"+testCase.branchName) require.Contains(t, string(branches), "refs/heads/"+testCase.branchName) }) @@ -398,7 +398,7 @@ func TestFailedUserCreateBranchRequest(t *testing.T) { } response, err := client.UserCreateBranch(ctx, request) - require.Equal(t, testCase.err, err) + testassert.GrpcEqualErr(t, testCase.err, err) require.Empty(t, response) }) } @@ -596,7 +596,7 @@ func TestFailedUserDeleteBranchDueToValidation(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.desc, func(t *testing.T) { response, err := client.UserDeleteBranch(ctx, testCase.request) - require.Equal(t, testCase.err, err) + testassert.GrpcEqualErr(t, testCase.err, err) testassert.ProtoEqual(t, testCase.response, response) }) } diff --git a/internal/gitaly/service/operations/commit_files_test.go b/internal/gitaly/service/operations/commit_files_test.go index b8bb1bd01..d4838a4d3 100644 --- a/internal/gitaly/service/operations/commit_files_test.go +++ b/internal/gitaly/service/operations/commit_files_test.go @@ -17,6 +17,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/localrepo" "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" "google.golang.org/grpc/metadata" @@ -918,7 +919,7 @@ func TestUserCommitFiles(t *testing.T) { } resp, err := stream.CloseAndRecv() - require.Equal(t, step.error, err) + testassert.GrpcEqualErr(t, step.error, err) if step.error != nil { continue } diff --git a/internal/gitaly/service/operations/merge_test.go b/internal/gitaly/service/operations/merge_test.go index 8bd72252e..c91aabdc7 100644 --- a/internal/gitaly/service/operations/merge_test.go +++ b/internal/gitaly/service/operations/merge_test.go @@ -800,7 +800,7 @@ func TestConflictsOnUserMergeToRefRequest(t *testing.T) { request.AllowConflicts = false _, err := client.UserMergeToRef(ctx, request) - require.Equal(t, status.Error(codes.FailedPrecondition, "Failed to create merge commit for source_sha 1450cd639e0bc6721eb02800169e464f212cde06 and target_sha 824be604a34828eb682305f0d963056cfac87b2d at refs/merge-requests/x/written"), err) + testassert.GrpcEqualErr(t, status.Error(codes.FailedPrecondition, "Failed to create merge commit for source_sha 1450cd639e0bc6721eb02800169e464f212cde06 and target_sha 824be604a34828eb682305f0d963056cfac87b2d at refs/merge-requests/x/written"), err) }) targetRef := git.Revision("refs/merge-requests/foo") diff --git a/internal/gitaly/service/operations/server.go b/internal/gitaly/service/operations/server.go index 1a5c8abe1..2ebc184b5 100644 --- a/internal/gitaly/service/operations/server.go +++ b/internal/gitaly/service/operations/server.go @@ -13,7 +13,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/hook" "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/rubyserver" "gitlab.com/gitlab-org/gitaly/v14/internal/storage" - "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" + "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" ) type Server struct { diff --git a/internal/gitaly/service/operations/tags_test.go b/internal/gitaly/service/operations/tags_test.go index 1933df193..bfa690bff 100644 --- a/internal/gitaly/service/operations/tags_test.go +++ b/internal/gitaly/service/operations/tags_test.go @@ -244,7 +244,7 @@ func testSuccessfulUserCreateTagRequest(t *testing.T, ctx context.Context) { responseOk.Tag.Id = text.ChompBytes(id) } - require.Equal(t, responseOk, response) + testassert.ProtoEqual(t, responseOk, response) tag := gittest.Exec(t, cfg, "-C", repoPath, "tag") require.Contains(t, string(tag), inputTagName) @@ -486,7 +486,7 @@ func testSuccessfulUserCreateTagRequestAnnotatedLightweightDisambiguation(t *tes response, err := client.UserCreateTag(ctx, request) if testCase.err != nil { - require.Equal(t, testCase.err, err) + testassert.GrpcEqualErr(t, testCase.err, err) } else { defer gittest.Exec(t, cfg, "-C", repoPath, "tag", "-d", tagName) require.NoError(t, err) @@ -678,7 +678,7 @@ func TestSuccessfulUserCreateTagRequestToNonCommit(t *testing.T) { tagID := gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", inputTagName) responseOk.Tag.Id = text.ChompBytes(tagID) } - require.Equal(t, responseOk, response) + testassert.ProtoEqual(t, responseOk, response) peeledID := gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", inputTagName+"^{}") require.Equal(t, testCase.targetRevision, text.ChompBytes(peeledID)) @@ -770,7 +770,7 @@ func TestSuccessfulUserCreateTagNestedTags(t *testing.T) { responseOk.Tag.TargetCommit, err = repo.ReadCommit(ctx, git.Revision(testCase.targetObject)) require.NoError(t, err) } - require.Equal(t, responseOk, response) + testassert.ProtoEqual(t, responseOk, response) peeledID := gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", tagName+"^{}") peeledIDStr := text.ChompBytes(peeledID) @@ -805,7 +805,7 @@ func TestSuccessfulUserCreateTagNestedTags(t *testing.T) { MessageSize: 0, }, } - require.Equal(t, responseOk, response) + testassert.ProtoEqual(t, responseOk, response) createdIDLight := gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", tagNameLight) createdIDLightStr := text.ChompBytes(createdIDLight) @@ -880,8 +880,8 @@ func testUserDeleteTagsuccessfulDeletionOfPrefixedTag(t *testing.T, ctx context. } response, err := client.UserDeleteTag(ctx, request) - require.Equal(t, testCase.err, err) - require.Equal(t, testCase.response, response) + testassert.GrpcEqualErr(t, testCase.err, err) + testassert.ProtoEqual(t, testCase.response, response) refs := gittest.Exec(t, cfg, "-C", repoPath, "for-each-ref", "--", "refs/tags/"+testCase.tagNameInput) require.NotContains(t, string(refs), testCase.tagCommit, "tag kept because we stripped off refs/tags/*") @@ -925,7 +925,7 @@ func TestUserCreateTagsuccessfulCreationOfPrefixedTag(t *testing.T) { } response, err := client.UserCreateTag(ctx, request) - require.Equal(t, testCase.err, err) + testassert.GrpcEqualErr(t, testCase.err, err) commitOk, err := repo.ReadCommit(ctx, git.Revision(testCase.tagTargetRevisionInput)) require.NoError(t, err) @@ -937,7 +937,7 @@ func TestUserCreateTagsuccessfulCreationOfPrefixedTag(t *testing.T) { }, } - require.Equal(t, responseOk, response) + testassert.ProtoEqual(t, responseOk, response) refs := gittest.Exec(t, cfg, "-C", repoPath, "for-each-ref", "--", "refs/tags/"+testCase.tagNameInput) require.Contains(t, string(refs), testCase.tagTargetRevisionInput, "tag created, we did not strip off refs/tags/*") @@ -1045,7 +1045,7 @@ func TestFailedUserDeleteTagRequestDueToValidation(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.desc, func(t *testing.T) { response, err := client.UserDeleteTag(ctx, testCase.request) - require.Equal(t, testCase.err, err) + testassert.GrpcEqualErr(t, testCase.err, err) testassert.ProtoEqual(t, testCase.response, response) }) } @@ -1077,7 +1077,7 @@ func testFailedUserDeleteTagDueToHooks(t *testing.T, ctx context.Context) { gittest.WriteCustomHook(t, repoPath, hookName, hookContent) response, err := client.UserDeleteTag(ctx, request) - require.Nil(t, err) + require.NoError(t, err) require.Contains(t, response.PreReceiveError, "GL_ID="+gittest.TestUser.GlId) tags := gittest.Exec(t, cfg, "-C", repoPath, "tag") @@ -1105,7 +1105,7 @@ func TestFailedUserCreateTagDueToHooks(t *testing.T) { gittest.WriteCustomHook(t, repoPath, hookName, hookContent) response, err := client.UserCreateTag(ctx, request) - require.Nil(t, err) + require.NoError(t, err) require.Contains(t, response.PreReceiveError, "GL_ID="+gittest.TestUser.GlId) } } @@ -1155,8 +1155,8 @@ func TestFailedUserCreateTagRequestDueToTagExistence(t *testing.T) { } response, err := client.UserCreateTag(ctx, request) - require.Equal(t, testCase.err, err) - require.Equal(t, testCase.response, response) + testassert.GrpcEqualErr(t, testCase.err, err) + testassert.ProtoEqual(t, testCase.response, response) }) } } @@ -1273,8 +1273,8 @@ func TestFailedUserCreateTagRequestDueToValidation(t *testing.T) { } response, err := client.UserCreateTag(ctx, request) - require.Equal(t, testCase.err, err) - require.Equal(t, testCase.response, response) + testassert.GrpcEqualErr(t, testCase.err, err) + testassert.ProtoEqual(t, testCase.response, response) }) } } @@ -1351,7 +1351,7 @@ func testTagHookOutput(t *testing.T, ctx context.Context) { Exists: false, PreReceiveError: testCase.output, } - require.Equal(t, createResponseOk, createResponse) + testassert.ProtoEqual(t, createResponseOk, createResponse) defer gittest.Exec(t, cfg, "-C", repoPath, "tag", "-d", tagNameInput) gittest.Exec(t, cfg, "-C", repoPath, "tag", tagNameInput) @@ -1361,7 +1361,7 @@ func testTagHookOutput(t *testing.T, ctx context.Context) { deleteResponseOk := &gitalypb.UserDeleteTagResponse{ PreReceiveError: testCase.output, } - require.Equal(t, deleteResponseOk, deleteResponse) + testassert.ProtoEqual(t, deleteResponseOk, deleteResponse) }) } } diff --git a/internal/gitaly/service/operations/update_branches_test.go b/internal/gitaly/service/operations/update_branches_test.go index d92a37860..dcf058edc 100644 --- a/internal/gitaly/service/operations/update_branches_test.go +++ b/internal/gitaly/service/operations/update_branches_test.go @@ -12,6 +12,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/git/localrepo" "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" @@ -91,7 +92,7 @@ func testSuccessfulUserUpdateBranchRequest(t *testing.T, ctx context.Context) { } response, err := client.UserUpdateBranch(ctx, request) require.NoError(t, err) - require.Equal(t, responseOk, response) + testassert.ProtoEqual(t, responseOk, response) branchCommit, err := repo.ReadCommit(ctx, git.Revision(testCase.updateBranchName)) @@ -161,8 +162,8 @@ func TestSuccessfulUserUpdateBranchRequestToDelete(t *testing.T) { User: gittest.TestUser, } response, err := client.UserUpdateBranch(ctx, request) - require.Nil(t, err) - require.Equal(t, responseOk, response) + require.NoError(t, err) + testassert.ProtoEqual(t, responseOk, response) _, err = repo.ReadCommit(ctx, git.Revision(testCase.updateBranchName)) require.Equal(t, localrepo.ErrObjectNotFound, err, "expected 'not found' error got %v", err) @@ -199,7 +200,7 @@ func TestSuccessfulGitHooksForUserUpdateBranchRequest(t *testing.T) { require.NoError(t, err) require.Empty(t, response.PreReceiveError) - require.Equal(t, responseOk, response) + testassert.ProtoEqual(t, responseOk, response) output := string(testhelper.MustReadFile(t, hookOutputTempPath)) require.Contains(t, output, "GL_USERNAME="+gittest.TestUser.GlUsername) }) @@ -227,14 +228,14 @@ func TestFailedUserUpdateBranchDueToHooks(t *testing.T) { gittest.WriteCustomHook(t, repoPath, hookName, hookContent) response, err := client.UserUpdateBranch(ctx, request) - require.Nil(t, err) + require.NoError(t, err) require.Contains(t, response.PreReceiveError, "GL_USERNAME="+gittest.TestUser.GlUsername) require.Contains(t, response.PreReceiveError, "PWD="+repoPath) responseOk := &gitalypb.UserUpdateBranchResponse{ PreReceiveError: response.PreReceiveError, } - require.Equal(t, responseOk, response) + testassert.ProtoEqual(t, responseOk, response) } } @@ -366,8 +367,8 @@ func TestFailedUserUpdateBranchRequest(t *testing.T) { } response, err := client.UserUpdateBranch(ctx, request) - require.Equal(t, testCase.response, response) - require.Equal(t, testCase.err, err) + testassert.ProtoEqual(t, testCase.response, response) + testassert.GrpcEqualErr(t, testCase.err, err) branchCommit, err := repo.ReadCommit(ctx, git.Revision(testCase.branchName)) if testCase.expectNotFoundError { diff --git a/internal/gitaly/service/ref/util_test.go b/internal/gitaly/service/ref/util_test.go index 867214b0a..3aaee1697 100644 --- a/internal/gitaly/service/ref/util_test.go +++ b/internal/gitaly/service/ref/util_test.go @@ -4,8 +4,6 @@ import ( "testing" "github.com/golang/protobuf/ptypes/timestamp" - "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" ) diff --git a/internal/gitaly/service/remote/find_remote_root_ref_test.go b/internal/gitaly/service/remote/find_remote_root_ref_test.go index 6b967a542..46210d02a 100644 --- a/internal/gitaly/service/remote/find_remote_root_ref_test.go +++ b/internal/gitaly/service/remote/find_remote_root_ref_test.go @@ -7,6 +7,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" "google.golang.org/grpc/status" @@ -70,7 +71,7 @@ func TestFindRemoteRootRefWithUnbornRemoteHead(t *testing.T) { &gitalypb.FindRemoteRootRefRequest{Repository: remoteRepo, RemoteUrl: "file://" + clientRepoPath}, } { response, err := client.FindRemoteRootRef(ctx, request) - require.Equal(t, status.Error(codes.NotFound, "no remote HEAD found"), err) + testassert.GrpcEqualErr(t, status.Error(codes.NotFound, "no remote HEAD found"), err) require.Nil(t, response) } } @@ -138,7 +139,7 @@ func TestFindRemoteRootRefFailedDueToValidation(t *testing.T) { // proxy via Praefect or not. We thus simply assert that the actual error is // one of the possible errors, which is the same as equality for all the // other tests. - require.Contains(t, testCase.expectedErr, err) + testassert.ContainsGrpcError(t, testCase.expectedErr, err) }) } } diff --git a/internal/gitaly/service/remote/update_remote_mirror_test.go b/internal/gitaly/service/remote/update_remote_mirror_test.go index 7eea363ea..3142983f6 100644 --- a/internal/gitaly/service/remote/update_remote_mirror_test.go +++ b/internal/gitaly/service/remote/update_remote_mirror_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/testserver" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc" @@ -536,7 +537,7 @@ func testUpdateRemoteMirrorFeatured(t *testing.T, ctx context.Context, cfg confi } require.NoError(t, err) - require.Equal(t, tc.response, resp) + testassert.ProtoEqual(t, tc.response, resp) // Check that the refs on the mirror now refer to the correct commits. // This is done by checking the commit messages as the commits are otherwise diff --git a/internal/gitaly/service/repository/apply_gitattributes_test.go b/internal/gitaly/service/repository/apply_gitattributes_test.go index d35cddd80..5b8c054f6 100644 --- a/internal/gitaly/service/repository/apply_gitattributes_test.go +++ b/internal/gitaly/service/repository/apply_gitattributes_test.go @@ -17,6 +17,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service" "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" @@ -192,7 +193,7 @@ func TestApplyGitattributesWithTransaction(t *testing.T) { Repository: repo, Revision: tc.revision, }) - require.Equal(t, tc.expectedErr, err) + testassert.GrpcEqualErr(t, tc.expectedErr, err) path := filepath.Join(infoPath, "attributes") if tc.shouldExist { diff --git a/internal/gitaly/service/repository/commit_graph_test.go b/internal/gitaly/service/repository/commit_graph_test.go index 88a5c38a1..216f9c452 100644 --- a/internal/gitaly/service/repository/commit_graph_test.go +++ b/internal/gitaly/service/repository/commit_graph_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/internal/testhelper/testserver" "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -103,7 +104,7 @@ func TestWriteCommitGraph_validationChecks(t *testing.T) { } { t.Run(tc.desc, func(t *testing.T) { _, err := client.WriteCommitGraph(ctx, tc.req) - require.Equal(t, tc.expErr, err) + testassert.GrpcEqualErr(t, tc.expErr, err) }) } } diff --git a/internal/gitaly/service/repository/config_test.go b/internal/gitaly/service/repository/config_test.go index 0b7824d09..6cd0d44ba 100644 --- a/internal/gitaly/service/repository/config_test.go +++ b/internal/gitaly/service/repository/config_test.go @@ -18,6 +18,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/testserver" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/voting" @@ -73,7 +74,7 @@ func TestGetConfig(t *testing.T) { require.NoError(t, os.Remove(configPath)) config, err := getConfig(t, client, repo) - require.Equal(t, status.Errorf(codes.NotFound, "opening gitconfig: open %s: no such file or directory", configPath), err) + testassert.GrpcEqualErr(t, status.Errorf(codes.NotFound, "opening gitconfig: open %s: no such file or directory", configPath), err) require.Equal(t, "", config) }) } diff --git a/internal/gitaly/service/repository/create_from_bundle_test.go b/internal/gitaly/service/repository/create_from_bundle_test.go index dbfe8aa8c..16c6ba2fc 100644 --- a/internal/gitaly/service/repository/create_from_bundle_test.go +++ b/internal/gitaly/service/repository/create_from_bundle_test.go @@ -14,6 +14,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v14/internal/tempdir" "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" @@ -148,7 +149,7 @@ func TestServer_CreateRepositoryFromBundle_failed_existing_directory(t *testing. })) _, err = stream.CloseAndRecv() - require.Equal(t, status.Error(codes.FailedPrecondition, "CreateRepositoryFromBundle: target directory is non-empty"), err) + testassert.GrpcEqualErr(t, status.Error(codes.FailedPrecondition, "CreateRepositoryFromBundle: target directory is non-empty"), err) } func TestSanitizedError(t *testing.T) { diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go index cbdc49a1e..79b11781c 100644 --- a/internal/gitaly/service/repository/fetch_remote_test.go +++ b/internal/gitaly/service/repository/fetch_remote_test.go @@ -22,6 +22,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" @@ -511,7 +512,7 @@ func TestFetchRemote_force(t *testing.T) { tc.request.Repository = targetRepoProto _, err := client.FetchRemote(ctx, tc.request) - require.Equal(t, tc.expectedErr, err) + testassert.GrpcEqualErr(t, tc.expectedErr, err) updatedBranchOID, err := targetRepo.ResolveRevision(ctx, "refs/heads/master") require.NoError(t, err) diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go index 7b5976578..d3fd33eec 100644 --- a/internal/gitaly/service/repository/replicate_test.go +++ b/internal/gitaly/service/repository/replicate_test.go @@ -20,7 +20,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" - "google.golang.org/grpc/reflection" "google.golang.org/protobuf/proto" ) diff --git a/internal/gitaly/service/repository/server_test.go b/internal/gitaly/service/repository/server_test.go index ef4615c3b..572dd818a 100644 --- a/internal/gitaly/service/repository/server_test.go +++ b/internal/gitaly/service/repository/server_test.go @@ -19,7 +19,7 @@ func TestGetConnectionByStorage(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - storageName, address := "default", "unix://fake/address/wont/work" + storageName, address := "default", "unix:///fake/address/wont/work" injectedCtx, err := helper.InjectGitalyServers(ctx, storageName, address, "token") require.NoError(t, err) diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go index 89c9cbed9..fc3c9c116 100644 --- a/internal/gitaly/service/smarthttp/receive_pack_test.go +++ b/internal/gitaly/service/smarthttp/receive_pack_test.go @@ -497,7 +497,7 @@ func TestPostReceivePackToHooks(t *testing.T) { socket := runSmartHTTPServer(t, cfg) - client, conn := newSmartHTTPClient(t, "unix://"+socket, cfg.Auth.Token) + client, conn := newSmartHTTPClient(t, socket, cfg.Auth.Token) defer conn.Close() stream, err := client.PostReceivePack(ctx) diff --git a/internal/gitaly/transaction/manager_test.go b/internal/gitaly/transaction/manager_test.go index 633100998..64c381ace 100644 --- a/internal/gitaly/transaction/manager_test.go +++ b/internal/gitaly/transaction/manager_test.go @@ -12,6 +12,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/service" "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/transaction" "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" @@ -114,7 +115,7 @@ func TestPoolManager_Vote(t *testing.T) { } err := manager.Vote(ctx, tc.transaction, praefect, tc.vote) - require.Equal(t, tc.expectedErr, err) + testassert.GrpcEqualErr(t, tc.expectedErr, err) }) } } @@ -166,7 +167,7 @@ func TestPoolManager_Stop(t *testing.T) { } err := manager.Stop(ctx, tc.transaction, praefect) - require.Equal(t, tc.expectedErr, err) + testassert.GrpcEqualErr(t, tc.expectedErr, err) }) } } diff --git a/internal/middleware/cache/cache_test.go b/internal/middleware/cache/cache_test.go index 2ab697b52..2be2b91bb 100644 --- a/internal/middleware/cache/cache_test.go +++ b/internal/middleware/cache/cache_test.go @@ -16,6 +16,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/middleware/cache/testdata" "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" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -121,11 +122,11 @@ func TestInvalidators(t *testing.T) { require.Equal(t, 0, MethodErrCount.Method["/grpc.health.v1.Health/Check"]) _, err = testdata.NewInterceptedServiceClient(cc).IgnoredMethod(ctx, &testdata.Request{}) - require.Equal(t, status.Error(codes.Unimplemented, "method IgnoredMethod not implemented"), err) + testassert.GrpcEqualErr(t, status.Error(codes.Unimplemented, "method IgnoredMethod not implemented"), err) require.Equal(t, 0, MethodErrCount.Method["/testdata.InterceptedService/IgnoredMethod"]) - require.Equal(t, expectedInvalidations, mCache.(*mockCache).invalidatedRepos) - require.Equal(t, expectedSvcRequests, svc.repoRequests) + testassert.ProtoEqual(t, expectedInvalidations, mCache.(*mockCache).invalidatedRepos) + testassert.ProtoEqual(t, expectedSvcRequests, svc.repoRequests) require.Equal(t, 3, mCache.(*mockCache).endedLeases.count) } diff --git a/internal/middleware/limithandler/limithandler_test.go b/internal/middleware/limithandler/limithandler_test.go index ccd9fce64..743bb9d17 100644 --- a/internal/middleware/limithandler/limithandler_test.go +++ b/internal/middleware/limithandler/limithandler_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v14/internal/middleware/limithandler" pb "gitlab.com/gitlab-org/gitaly/v14/internal/middleware/limithandler/testdata" @@ -33,7 +34,7 @@ func fixedLockKey(ctx context.Context) string { func TestUnaryLimitHandler(t *testing.T) { s := &server{blockCh: make(chan struct{})} - limithandler.SetMaxRepoConcurrency(map[string]int{"/test.Test/Unary": 2}) + limithandler.SetMaxRepoConcurrency(map[string]int{"/test.limithandler.Test/Unary": 2}) lh := limithandler.New(fixedLockKey) interceptor := lh.UnaryInterceptor() srv, serverSocketPath := runServer(t, s, grpc.UnaryInterceptor(interceptor)) @@ -52,9 +53,13 @@ func TestUnaryLimitHandler(t *testing.T) { defer wg.Done() resp, err := client.Unary(ctx, &pb.UnaryRequest{}) - require.NotNil(t, resp) - require.NoError(t, err) - require.True(t, resp.Ok) + if !assert.NoError(t, err) { + return + } + if !assert.NotNil(t, resp) { + return + } + assert.True(t, resp.Ok) }() } @@ -76,15 +81,15 @@ func TestStreamLimitHandler(t *testing.T) { }{ { desc: "Single request, multiple responses", - fullname: "/test.Test/StreamOutput", + fullname: "/test.limithandler.Test/StreamOutput", f: func(t *testing.T, ctx context.Context, client pb.TestClient) { stream, err := client.StreamOutput(ctx, &pb.StreamOutputRequest{}) - require.NotNil(t, stream) require.NoError(t, err) + require.NotNil(t, stream) r, err := stream.Recv() - require.NotNil(t, r) require.NoError(t, err) + require.NotNil(t, r) require.True(t, r.Ok) }, maxConcurrency: 3, @@ -92,16 +97,16 @@ func TestStreamLimitHandler(t *testing.T) { }, { desc: "Multiple requests, single response", - fullname: "/test.Test/StreamInput", + fullname: "/test.limithandler.Test/StreamInput", f: func(t *testing.T, ctx context.Context, client pb.TestClient) { stream, err := client.StreamInput(ctx) - require.NotNil(t, stream) require.NoError(t, err) + require.NotNil(t, stream) require.NoError(t, stream.Send(&pb.StreamInputRequest{})) r, err := stream.CloseAndRecv() - require.NotNil(t, r) require.NoError(t, err) + require.NotNil(t, r) require.True(t, r.Ok) }, maxConcurrency: 3, @@ -109,18 +114,18 @@ func TestStreamLimitHandler(t *testing.T) { }, { desc: "Multiple requests, multiple responses", - fullname: "/test.Test/Bidirectional", + fullname: "/test.limithandler.Test/Bidirectional", f: func(t *testing.T, ctx context.Context, client pb.TestClient) { stream, err := client.Bidirectional(ctx) - require.NotNil(t, stream) require.NoError(t, err) + require.NotNil(t, stream) require.NoError(t, stream.Send(&pb.BidirectionalRequest{})) require.NoError(t, stream.CloseSend()) r, err := stream.Recv() - require.NotNil(t, r) require.NoError(t, err) + require.NotNil(t, r) require.True(t, r.Ok) }, maxConcurrency: 3, @@ -130,11 +135,11 @@ func TestStreamLimitHandler(t *testing.T) { // Make sure that _streams_ are limited but that _requests_ on each // allowed stream are not limited. desc: "Multiple requests with same id, multiple responses", - fullname: "/test.Test/Bidirectional", + fullname: "/test.limithandler.Test/Bidirectional", f: func(t *testing.T, ctx context.Context, client pb.TestClient) { stream, err := client.Bidirectional(ctx) - require.NotNil(t, stream) require.NoError(t, err) + require.NotNil(t, stream) // Since the concurrency id is fixed all requests have the same // id, but subsequent requests in a stream, even with the same @@ -145,8 +150,8 @@ func TestStreamLimitHandler(t *testing.T) { require.NoError(t, stream.CloseSend()) r, err := stream.Recv() - require.NotNil(t, r) require.NoError(t, err) + require.NotNil(t, r) require.True(t, r.Ok) }, maxConcurrency: 3, @@ -155,15 +160,15 @@ func TestStreamLimitHandler(t *testing.T) { }, { desc: "With a max concurrency of 0", - fullname: "/test.Test/StreamOutput", + fullname: "/test.limithandler.Test/StreamOutput", f: func(t *testing.T, ctx context.Context, client pb.TestClient) { stream, err := client.StreamOutput(ctx, &pb.StreamOutputRequest{}) - require.NotNil(t, stream) require.NoError(t, err) + require.NotNil(t, stream) r, err := stream.Recv() - require.NotNil(t, r) require.NoError(t, err) + require.NotNil(t, r) require.True(t, r.Ok) }, maxConcurrency: 0, diff --git a/internal/praefect/coordinator_test.go b/internal/praefect/coordinator_test.go index f3c6ec91e..016d1991f 100644 --- a/internal/praefect/coordinator_test.go +++ b/internal/praefect/coordinator_test.go @@ -33,6 +33,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/transactions" "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/internal/transaction/txinfo" @@ -1099,11 +1100,11 @@ func TestCoordinatorEnqueueFailure(t *testing.T) { Name: "praefect", Nodes: []*config.Node{ &config.Node{ - Address: "unix://woof", + Address: "unix:///woof", Storage: "praefect-internal-1", }, &config.Node{ - Address: "unix://meow", + Address: "unix:///meow", Storage: "praefect-internal-2", }}, }, @@ -1533,7 +1534,7 @@ func TestCoordinator_grpcErrorHandling(t *testing.T) { &gitalypb.UserCreateBranchRequest{ Repository: repoProto, }) - require.Equal(t, tc.expectedErr, err) + testassert.GrpcEqualErr(t, tc.expectedErr, err) for _, node := range gitalies { require.True(t, node.operationServer.called, "expected gitaly %q to have been called", node.mock.GetStorage()) diff --git a/internal/praefect/grpc-proxy/proxy/handler_ext_test.go b/internal/praefect/grpc-proxy/proxy/handler_ext_test.go index bce3948d2..eae61c388 100644 --- a/internal/praefect/grpc-proxy/proxy/handler_ext_test.go +++ b/internal/praefect/grpc-proxy/proxy/handler_ext_test.go @@ -30,6 +30,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/grpc-proxy/proxy" pb "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/grpc-proxy/testdata" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper/testassert" "go.uber.org/goleak" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -58,6 +59,7 @@ func TestMain(m *testing.M) { // asserting service is implemented on the server side and serves as a handler for stuff type assertingService struct { + pb.UnimplementedTestServiceServer t *testing.T } @@ -137,7 +139,7 @@ func (s *ProxyHappySuite) TestPingEmptyCarriesClientMetadata() { ctx := metadata.NewOutgoingContext(s.ctx(), metadata.Pairs(clientMdKey, "true")) out, err := s.testClient.PingEmpty(ctx, &pb.Empty{}) require.NoError(s.T(), err, "PingEmpty should succeed without errors") - require.Equal(s.T(), &pb.PingResponse{Value: pingDefaultValue, Counter: 42}, out) + testassert.ProtoEqual(s.T(), &pb.PingResponse{Value: pingDefaultValue, Counter: 42}, out) } func (s *ProxyHappySuite) TestPingEmpty_StressTest() { @@ -152,7 +154,7 @@ func (s *ProxyHappySuite) TestPingCarriesServerHeadersAndTrailers() { // This is an awkward calling convention... but meh. out, err := s.testClient.Ping(s.ctx(), &pb.PingRequest{Value: "foo"}, grpc.Header(&headerMd), grpc.Trailer(&trailerMd)) require.NoError(s.T(), err, "Ping should succeed without errors") - require.Equal(s.T(), &pb.PingResponse{Value: "foo", Counter: 42}, out) + testassert.ProtoEqual(s.T(), &pb.PingResponse{Value: "foo", Counter: 42}, out) assert.Contains(s.T(), headerMd, serverHeaderMdKey, "server response headers must contain server data") assert.Len(s.T(), trailerMd, 1, "server response trailers must contain server data") } @@ -364,7 +366,7 @@ func TestProxyErrorPropagation(t *testing.T) { requestFinalizerError: errRequestFinalizer, returnedError: errBackend, errHandler: func(err error) error { - require.Equal(t, errBackend, err) + testassert.GrpcEqualErr(t, errBackend, err) return errBackend }, }, @@ -373,7 +375,7 @@ func TestProxyErrorPropagation(t *testing.T) { backendError: errBackend, returnedError: io.EOF, errHandler: func(err error) error { - require.Equal(t, errBackend, err) + testassert.GrpcEqualErr(t, errBackend, err) return nil }, }, @@ -383,7 +385,7 @@ func TestProxyErrorPropagation(t *testing.T) { requestFinalizerError: errRequestFinalizer, returnedError: errRequestFinalizer, errHandler: func(err error) error { - require.Equal(t, errBackend, err) + testassert.GrpcEqualErr(t, errBackend, err) return nil }, }, @@ -439,7 +441,7 @@ func TestProxyErrorPropagation(t *testing.T) { }() resp, err := pb.NewTestServiceClient(proxyClientConn).Ping(ctx, &pb.PingRequest{}) - require.Equal(t, tc.returnedError, err) + testassert.GrpcEqualErr(t, tc.returnedError, err) require.Nil(t, resp) }) } @@ -519,5 +521,5 @@ func TestRegisterStreamHandlers(t *testing.T) { // since PingError was never registered with its own streamer, it should get sent to the UnknownServiceHandler _, err = testServiceClient.PingError(ctx, &pb.PingRequest{}) - require.Equal(t, status.Error(codes.Unknown, directorCalledError.Error()), err) + testassert.GrpcEqualErr(t, status.Error(codes.Unknown, directorCalledError.Error()), err) } diff --git a/internal/praefect/node_test.go b/internal/praefect/node_test.go index a083b3327..c4f170b87 100644 --- a/internal/praefect/node_test.go +++ b/internal/praefect/node_test.go @@ -31,7 +31,7 @@ func TestDialNodes(t *testing.T) { storage string token string status grpc_health_v1.HealthCheckResponse_ServingStatus - error error + error string } expectedNodes := []nodeAssertion{ @@ -68,7 +68,7 @@ func TestDialNodes(t *testing.T) { expectedNodes = append(expectedNodes, nodeAssertion{ storage: "invalid", - error: status.Error(codes.Unavailable, `connection error: desc = "transport: Error while dialing dial unix non-existent-socket: connect: no such file or directory"`), + error: status.Error(codes.Unavailable, `connection error: desc = "transport: Error while dialing dial unix non-existent-socket: connect: no such file or directory"`).Error(), }) nodeSet, err := DialNodes(ctx, @@ -92,10 +92,15 @@ func TestDialNodes(t *testing.T) { require.NotNil(t, conns[virtualStorage][node.Storage], "connection not found for storage %q", node.Storage) resp, err := healthClients[virtualStorage][node.Storage].Check(ctx, &grpc_health_v1.HealthCheckRequest{}) + var errStr string + if err != nil { + errStr = err.Error() + } + assertion := nodeAssertion{ storage: node.Storage, token: node.Token, - error: err, + error: errStr, } if resp != nil { diff --git a/internal/praefect/nodes/manager_test.go b/internal/praefect/nodes/manager_test.go index b6784765b..107e27638 100644 --- a/internal/praefect/nodes/manager_test.go +++ b/internal/praefect/nodes/manager_test.go @@ -143,7 +143,7 @@ func TestDialWithUnhealthyNode(t *testing.T) { require.NoError(t, err) primaryAddress := "unix://" + primaryLn.Addr().String() - const secondaryAddress = "unix://does-not-exist" + const secondaryAddress = "unix:///does-not-exist" const storageName = "default" conf := config.Config{ diff --git a/internal/praefect/repository_exists_test.go b/internal/praefect/repository_exists_test.go index bd825b5a9..df74f09a2 100644 --- a/internal/praefect/repository_exists_test.go +++ b/internal/praefect/repository_exists_test.go @@ -14,6 +14,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/grpc-proxy/proxy" "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" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -116,7 +117,7 @@ func TestRepositoryExistsStreamInterceptor(t *testing.T) { resp, err := client.RepositoryExists(ctx, &gitalypb.RepositoryExistsRequest{Repository: tc.repository}) require.Equal(t, tc.error, err) - require.Equal(t, tc.response, resp) + testassert.ProtoEqual(t, tc.response, resp) }) } } diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go index 0162b5492..1dc764fa7 100644 --- a/internal/praefect/server_test.go +++ b/internal/praefect/server_test.go @@ -37,6 +37,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/transactions" "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/internal/transaction/txinfo" @@ -98,7 +99,7 @@ func TestNewBackchannelServerFactory(t *testing.T) { defer nodeSet.Close() clientConn := nodeSet["default"]["gitaly-1"].Connection - require.Equal(t, + testassert.GrpcEqualErr(t, status.Error(codes.NotFound, "transaction not found: 0"), clientConn.Invoke(ctx, "/Service/Method", &gitalypb.CreateBranchRequest{}, &gitalypb.CreateBranchResponse{}), ) @@ -174,7 +175,7 @@ func TestGitalyServerInfo(t *testing.T) { { Storage: cfg.Storages[0].Name, Token: cfg.Auth.Token, - Address: "unix://invalid.addr", + Address: "unix:///invalid.addr", }, }, }, @@ -276,7 +277,7 @@ func TestHealthCheck(t *testing.T) { cc, _, cleanup := runPraefectServer(t, config.Config{VirtualStorages: []*config.VirtualStorage{ { Name: "praefect", - Nodes: []*config.Node{{Storage: "stub", Address: "unix://stub-address", Token: ""}}, + Nodes: []*config.Node{{Storage: "stub", Address: "unix:///stub-address", Token: ""}}, }, }}, buildOptions{}) defer cleanup() @@ -498,7 +499,7 @@ func TestRemoveRepository(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - virtualRepo := repos[0][0] + virtualRepo := proto.Clone(repos[0][0]).(*gitalypb.Repository) virtualRepo.StorageName = praefectCfg.VirtualStorages[0].Name _, err := gitalypb.NewRepositoryServiceClient(cc).RemoveRepository(ctx, &gitalypb.RemoveRepositoryRequest{ @@ -968,7 +969,7 @@ func TestErrorThreshold(t *testing.T) { require.True(t, healthy) _, err = handler(ctx, &mock.RepoRequest{Repo: repo}) - require.Equal(t, status.Error(codes.Internal, "something went wrong"), err) + testassert.GrpcEqualErr(t, status.Error(codes.Internal, "something went wrong"), err) } healthy, err := node.CheckHealth(ctx) diff --git a/internal/praefect/service/info/consistencycheck_test.go b/internal/praefect/service/info/consistencycheck_test.go index c4981dbbe..f0f0b8e9a 100644 --- a/internal/praefect/service/info/consistencycheck_test.go +++ b/internal/praefect/service/info/consistencycheck_test.go @@ -19,6 +19,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/nodes" "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" @@ -156,7 +157,7 @@ func TestServer_ConsistencyCheck(t *testing.T) { execAndVerify(t, req, func(t *testing.T, responses []*gitalypb.ConsistencyCheckResponse, err error) { require.NoError(t, err) - require.Equal(t, []*gitalypb.ConsistencyCheckResponse{ + testassert.ProtoEqual(t, []*gitalypb.ConsistencyCheckResponse{ { RepoRelativePath: firstRepoPath, ReferenceStorage: referenceStorageName, @@ -191,8 +192,8 @@ func TestServer_ConsistencyCheck(t *testing.T) { DisableReconcilliation: false, }, verify: func(t *testing.T, resp []*gitalypb.ConsistencyCheckResponse, err error) { - require.Equal(t, expErrStatus, err) - require.Equal(t, []*gitalypb.ConsistencyCheckResponse{ + testassert.GrpcEqualErr(t, expErrStatus, err) + testassert.ProtoEqual(t, []*gitalypb.ConsistencyCheckResponse{ { RepoRelativePath: firstRepoPath, TargetChecksum: checksum, @@ -228,7 +229,7 @@ func TestServer_ConsistencyCheck(t *testing.T) { }, verify: func(t *testing.T, resp []*gitalypb.ConsistencyCheckResponse, err error) { require.NoError(t, err) - require.Equal(t, []*gitalypb.ConsistencyCheckResponse{ + testassert.ProtoEqual(t, []*gitalypb.ConsistencyCheckResponse{ { RepoRelativePath: firstRepoPath, TargetChecksum: checksum, @@ -261,7 +262,7 @@ func TestServer_ConsistencyCheck(t *testing.T) { ReferenceStorage: targetStorageName, }, verify: func(t *testing.T, resp []*gitalypb.ConsistencyCheckResponse, err error) { - require.Equal(t, status.Error(codes.InvalidArgument, "missing target storage"), err) + testassert.GrpcEqualErr(t, status.Error(codes.InvalidArgument, "missing target storage"), err) }, }, { @@ -272,7 +273,7 @@ func TestServer_ConsistencyCheck(t *testing.T) { ReferenceStorage: targetStorageName, }, verify: func(t *testing.T, resp []*gitalypb.ConsistencyCheckResponse, err error) { - require.Equal(t, status.Error(codes.NotFound, `unable to find target storage "unknown"`), err) + testassert.GrpcEqualErr(t, status.Error(codes.NotFound, `unable to find target storage "unknown"`), err) }, }, { @@ -287,7 +288,7 @@ func TestServer_ConsistencyCheck(t *testing.T) { codes.InvalidArgument, fmt.Sprintf(`target storage %q is same as current primary, must provide alternate reference`, referenceStorageName), ) - require.Equal(t, expErr, err) + testassert.GrpcEqualErr(t, expErr, err) }, }, { @@ -302,7 +303,7 @@ func TestServer_ConsistencyCheck(t *testing.T) { codes.NotFound, fmt.Sprintf(`unable to find reference storage "unknown" in nodes for shard %q`, virtualStorage), ) - require.Equal(t, expErr, err) + testassert.GrpcEqualErr(t, expErr, err) }, }, { @@ -317,7 +318,7 @@ func TestServer_ConsistencyCheck(t *testing.T) { codes.InvalidArgument, fmt.Sprintf(`target storage %q cannot match reference storage %q`, referenceStorageName, referenceStorageName), ) - require.Equal(t, expErr, err) + testassert.GrpcEqualErr(t, expErr, err) }, }, { @@ -328,7 +329,7 @@ func TestServer_ConsistencyCheck(t *testing.T) { ReferenceStorage: targetStorageName, }, verify: func(t *testing.T, resp []*gitalypb.ConsistencyCheckResponse, err error) { - require.Equal(t, status.Error(codes.InvalidArgument, "missing virtual storage"), err) + testassert.GrpcEqualErr(t, status.Error(codes.InvalidArgument, "missing virtual storage"), err) }, }, { @@ -339,7 +340,7 @@ func TestServer_ConsistencyCheck(t *testing.T) { ReferenceStorage: "unknown", }, verify: func(t *testing.T, resp []*gitalypb.ConsistencyCheckResponse, err error) { - require.Equal(t, status.Error(codes.NotFound, "virtual storage does not exist"), err) + testassert.GrpcEqualErr(t, status.Error(codes.NotFound, "virtual storage does not exist"), err) }, }, } { @@ -361,12 +362,12 @@ func TestServer_ConsistencyCheck(t *testing.T) { execAndVerify(t, req, func(t *testing.T, responses []*gitalypb.ConsistencyCheckResponse, err error) { t.Helper() - require.Equal(t, expErrStatus, err) + testassert.GrpcEqualErr(t, expErrStatus, err) errs := []string{ fmt.Sprintf("rpc error: code = Unavailable desc = connection error: desc = \"transport: Error while dialing dial unix //%s: connect: no such file or directory\"", strings.TrimPrefix(targetGitaly.Address(), "unix://")), "rpc error: code = Canceled desc = context canceled", } - require.Equal(t, []*gitalypb.ConsistencyCheckResponse{ + testassert.ProtoEqual(t, []*gitalypb.ConsistencyCheckResponse{ { RepoRelativePath: firstRepoPath, ReferenceStorage: referenceStorageName, diff --git a/internal/testhelper/testassert/assert.go b/internal/testhelper/testassert/assert.go index 50a473082..8b00115ea 100644 --- a/internal/testhelper/testassert/assert.go +++ b/internal/testhelper/testassert/assert.go @@ -1,15 +1,41 @@ package testassert import ( + "fmt" "testing" - "github.com/golang/protobuf/proto" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/testing/protocmp" ) // ProtoEqual asserts that expected and actual protobuf messages are equal. +// It can accept not only proto.Message, but slices, maps, and structs too. // 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) +func ProtoEqual(t testing.TB, expected, actual interface{}) { + t.Helper() + require.Empty(t, cmp.Diff(expected, actual, protocmp.Transform())) +} + +// GrpcEqualErr asserts that expected and actual gRPC errors are equal. +// This is required as comparing messages directly with `require.Equal` doesn't +// work. +func GrpcEqualErr(t testing.TB, expected, actual error) { + t.Helper() + // .Proto() handles nil receiver + ProtoEqual(t, status.Convert(expected).Proto(), status.Convert(actual).Proto()) +} + +// ContainsGrpcError checks that an equal gRPC error is present in the slice of errors. +func ContainsGrpcError(t testing.TB, errs []error, err error) { + t.Helper() + errStatus := status.Convert(err).Proto() + for _, e := range errs { + if cmp.Equal(status.Convert(e).Proto(), errStatus, protocmp.Transform()) { + return + } + } + require.FailNow(t, fmt.Sprintf("%#v does not contain %#v", errs, err)) } |