diff options
author | Toon Claes <toon@gitlab.com> | 2021-04-12 13:49:47 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2021-04-22 15:55:19 +0300 |
commit | 38805e6d7532684ec4ba02f3364ffea8da910c4e (patch) | |
tree | 75de4e5b3df53b05de7575ef00076af26cdd04d1 | |
parent | b18032b131e55479a7b741c3716abdd6bd1dc36e (diff) |
operations: Return correct status code from rebase
There are a few error conditions that can happen when locating the
repository to do the rebase.
This change adds a few test cases to ensure the status codes for those
failures are identical in the Go and Ruby implementation.
-rw-r--r-- | internal/gitaly/service/operations/rebase.go | 8 | ||||
-rw-r--r-- | internal/gitaly/service/operations/rebase_test.go | 50 | ||||
-rw-r--r-- | internal/gitaly/service/operations/testhelper_test.go | 1 |
3 files changed, 55 insertions, 4 deletions
diff --git a/internal/gitaly/service/operations/rebase.go b/internal/gitaly/service/operations/rebase.go index 7a938be89..8438bd079 100644 --- a/internal/gitaly/service/operations/rebase.go +++ b/internal/gitaly/service/operations/rebase.go @@ -48,13 +48,13 @@ func (s *Server) userRebaseConfirmableGo(stream gitalypb.OperationService_UserRe repo := header.Repository repoPath, err := s.locator.GetPath(repo) if err != nil { - return fmt.Errorf("get path: %w", err) + return helper.ErrInvalidArgumentf("get path: %w", err) } branch := git.NewReferenceNameFromBranchName(string(header.Branch)) oldrev, err := git.NewObjectIDFromHex(header.BranchSha) if err != nil { - return fmt.Errorf("get oid: %w", err) + return helper.ErrNotFound(err) } committer := git2go.NewSignature(string(header.User.Name), string(header.User.Email), time.Now()) @@ -62,7 +62,7 @@ func (s *Server) userRebaseConfirmableGo(stream gitalypb.OperationService_UserRe if header.Timestamp != nil { committer.When, err = ptypes.Timestamp(header.Timestamp) if err != nil { - return fmt.Errorf("parse timestamp: %w", err) + return helper.ErrInvalidArgumentf("parse timestamp: %w", err) } } @@ -86,7 +86,7 @@ func (s *Server) userRebaseConfirmableGo(stream gitalypb.OperationService_UserRe secondRequest, err := stream.Recv() if err != nil { - return fmt.Errorf("recv: %w", err) + return helper.ErrInternalf("recv: %w", err) } if !secondRequest.GetApply() { diff --git a/internal/gitaly/service/operations/rebase_test.go b/internal/gitaly/service/operations/rebase_test.go index 972002738..8559b0f7e 100644 --- a/internal/gitaly/service/operations/rebase_test.go +++ b/internal/gitaly/service/operations/rebase_test.go @@ -627,6 +627,56 @@ func testRebaseOntoRemoteBranchFeatured(t *testing.T, ctx context.Context, cfg c require.True(t, secondResponse.GetRebaseApplied(), "the second rebase is applied") } +func testRebaseFailedWithCode(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) { + testWithFeature(t, featureflag.GoUserRebaseConfirmable, cfg, rubySrv, testRebaseFailedWithCodeFeatured) +} + +func testRebaseFailedWithCodeFeatured(t *testing.T, ctx context.Context, cfg config.Cfg, rubySrv *rubyserver.Server) { + ctx, _, repoProto, repoPath, client := setupOperationsServiceWithRuby(t, ctx, cfg, rubySrv) + + branchSha := getBranchSha(t, repoPath, rebaseBranchName) + + testCases := []struct { + desc string + buildHeaderRequest func() *gitalypb.UserRebaseConfirmableRequest + expectedCode codes.Code + }{ + { + desc: "non-existing storage", + buildHeaderRequest: func() *gitalypb.UserRebaseConfirmableRequest { + repo := *repoProto + repo.StorageName = "@this-storage-does-not-exist" + + return buildHeaderRequest(&repo, testhelper.TestUser, "1", rebaseBranchName, branchSha, &repo, "master") + }, + expectedCode: codes.InvalidArgument, + }, + { + desc: "missing repository path", + buildHeaderRequest: func() *gitalypb.UserRebaseConfirmableRequest { + repo := *repoProto + repo.RelativePath = "" + + return buildHeaderRequest(&repo, testhelper.TestUser, "1", rebaseBranchName, branchSha, &repo, "master") + }, + expectedCode: codes.InvalidArgument, + }, + } + + for _, tc := range testCases { + t.Run(tc.desc, func(t *testing.T) { + rebaseStream, err := client.UserRebaseConfirmable(ctx) + require.NoError(t, err) + + headerRequest := tc.buildHeaderRequest() + require.NoError(t, rebaseStream.Send(headerRequest), "send header") + + _, err = rebaseStream.Recv() + testhelper.RequireGrpcError(t, err, tc.expectedCode) + }) + } +} + func rebaseRecvTimeout(bidi gitalypb.OperationService_UserRebaseConfirmableClient, timeout time.Duration) (*gitalypb.UserRebaseConfirmableResponse, error) { type responseError struct { response *gitalypb.UserRebaseConfirmableResponse diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go index 9333823ac..ba6da0fdf 100644 --- a/internal/gitaly/service/operations/testhelper_test.go +++ b/internal/gitaly/service/operations/testhelper_test.go @@ -96,6 +96,7 @@ func TestWithRubySidecar(t *testing.T) { testFailedUserRebaseConfirmableDueToGitError, testRebaseRequestWithDeletedFile, testRebaseOntoRemoteBranch, + testRebaseFailedWithCode, testSuccessfulUserUpdateSubmoduleRequest, testUserUpdateSubmoduleStableID, testFailedUserUpdateSubmoduleRequestDueToValidations, |