diff options
author | Toon Claes <toon@gitlab.com> | 2020-11-02 16:46:46 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2021-02-17 18:12:20 +0300 |
commit | a5f6fc229cfd4c18a8b25d538ed25da66d5f79d1 (patch) | |
tree | b5f67e04e06d7b59135f441f270823a52044206b | |
parent | 191334b46ec1c14ebbb7b9d9ccf5fa394b314122 (diff) |
Add feature flag for GoUserCherryPick
Prepare the code and the tests for the Go implementation of
UserCherryPick.
The gitaly/service/operations package will test if the feature is
enabled and choose the Ruby or Go implementation based on that. The
latter is still empty for now.
For the tests it involves running the tests twice, once with the
GoUserCherryPick feature flag on, and once off.
Part of https://gitlab.com/gitlab-org/gitaly/-/issues/3071
-rw-r--r-- | internal/gitaly/service/operations/cherry_pick.go | 9 | ||||
-rw-r--r-- | internal/gitaly/service/operations/cherry_pick_test.go | 44 | ||||
-rw-r--r-- | internal/metadata/featureflag/feature_flags.go | 3 |
3 files changed, 39 insertions, 17 deletions
diff --git a/internal/gitaly/service/operations/cherry_pick.go b/internal/gitaly/service/operations/cherry_pick.go index 3c406abfd..f8e59f675 100644 --- a/internal/gitaly/service/operations/cherry_pick.go +++ b/internal/gitaly/service/operations/cherry_pick.go @@ -4,6 +4,7 @@ import ( "context" "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver" + "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -14,6 +15,10 @@ func (s *Server) UserCherryPick(ctx context.Context, req *gitalypb.UserCherryPic return nil, status.Errorf(codes.InvalidArgument, "UserCherryPick: %v", err) } + if featureflag.IsEnabled(ctx, featureflag.GoUserCherryPick) { + return s.userCherryPick(ctx, req) + } + client, err := s.ruby.OperationServiceClient(ctx) if err != nil { return nil, err @@ -26,3 +31,7 @@ func (s *Server) UserCherryPick(ctx context.Context, req *gitalypb.UserCherryPic return client.UserCherryPick(clientCtx, req) } + +func (s *Server) userCherryPick(ctx context.Context, req *gitalypb.UserCherryPickRequest) (*gitalypb.UserCherryPickResponse, error) { + return nil, nil +} diff --git a/internal/gitaly/service/operations/cherry_pick_test.go b/internal/gitaly/service/operations/cherry_pick_test.go index 635e80dcb..1b02d068f 100644 --- a/internal/gitaly/service/operations/cherry_pick_test.go +++ b/internal/gitaly/service/operations/cherry_pick_test.go @@ -9,6 +9,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" + "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -16,9 +17,10 @@ import ( ) func TestServer_UserCherryPick_successful(t *testing.T) { - ctxOuter, cancel := testhelper.Context() - defer cancel() + testWithFeature(t, featureflag.GoUserCherryPick, testServerUserCherryPickSuccessful) +} +func testServerUserCherryPickSuccessful(t *testing.T, ctxOuter context.Context) { serverSocketPath, stop := runOperationServiceServer(t) defer stop() @@ -153,6 +155,12 @@ func TestServer_UserCherryPick_successful(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.desc, func(t *testing.T) { md := testhelper.GitalyServersMetadata(t, serverSocketPath) + + mdFromCtx, ok := metadata.FromOutgoingContext(ctxOuter) + if ok { + md = metadata.Join(md, mdFromCtx) + } + ctx := metadata.NewOutgoingContext(ctxOuter, md) response, err := client.UserCherryPick(ctx, testCase.request) @@ -180,10 +188,7 @@ func TestServer_UserCherryPick_successful(t *testing.T) { } func TestServer_UserCherryPick_successful_git_hooks(t *testing.T) { - ctx, cancel := testhelper.Context() - defer cancel() - - testServerUserCherryPickSuccessfulGitHooks(t, ctx) + testWithFeature(t, featureflag.GoUserCherryPick, testServerUserCherryPickSuccessfulGitHooks) } func testServerUserCherryPickSuccessfulGitHooks(t *testing.T, ctxOuter context.Context) { @@ -232,6 +237,10 @@ func testServerUserCherryPickSuccessfulGitHooks(t *testing.T, ctxOuter context.C } func TestServer_UserCherryPick_stableID(t *testing.T) { + testWithFeature(t, featureflag.GoUserCherryPick, testServerUserCherryPickStableID) +} + +func testServerUserCherryPickStableID(t *testing.T, ctx context.Context) { serverSocketPath, stop := runOperationServiceServer(t) defer stop() @@ -242,9 +251,6 @@ func TestServer_UserCherryPick_stableID(t *testing.T) { defer cleanup() repo := localrepo.New(git.NewExecCommandFactory(config.Config), repoProto, config.Config) - ctx, cancel := testhelper.Context() - defer cancel() - destinationBranch := "cherry-picking-dst" testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master") @@ -297,9 +303,10 @@ func TestServer_UserCherryPick_stableID(t *testing.T) { } func TestServer_UserCherryPick_failed_validations(t *testing.T) { - ctxOuter, cancel := testhelper.Context() - defer cancel() + testWithFeature(t, featureflag.GoUserCherryPick, testServerUserCherryPickFailedValidations) +} +func testServerUserCherryPickFailedValidations(t *testing.T, ctxOuter context.Context) { serverSocketPath, stop := runOperationServiceServer(t) defer stop() @@ -378,9 +385,10 @@ func TestServer_UserCherryPick_failed_validations(t *testing.T) { } func TestServer_UserCherryPick_failed_with_PreReceiveError(t *testing.T) { - ctxOuter, cancel := testhelper.Context() - defer cancel() + testWithFeature(t, featureflag.GoUserCherryPick, testServerUserCherryPickFailedWithPreReceiveError) +} +func testServerUserCherryPickFailedWithPreReceiveError(t *testing.T, ctxOuter context.Context) { serverSocketPath, stop := runOperationServiceServer(t) defer stop() @@ -423,9 +431,10 @@ func TestServer_UserCherryPick_failed_with_PreReceiveError(t *testing.T) { } func TestServer_UserCherryPick_failed_with_CreateTreeError(t *testing.T) { - ctxOuter, cancel := testhelper.Context() - defer cancel() + testWithFeature(t, featureflag.GoUserCherryPick, testServerUserCherryPickFailedWithCreateTreeError) +} +func testServerUserCherryPickFailedWithCreateTreeError(t *testing.T, ctxOuter context.Context) { serverSocketPath, stop := runOperationServiceServer(t) defer stop() @@ -461,9 +470,10 @@ func TestServer_UserCherryPick_failed_with_CreateTreeError(t *testing.T) { } func TestServer_UserCherryPick_failed_with_CommitError(t *testing.T) { - ctxOuter, cancel := testhelper.Context() - defer cancel() + testWithFeature(t, featureflag.GoUserCherryPick, testServerUserCherryPickFailedWithCommitError) +} +func testServerUserCherryPickFailedWithCommitError(t *testing.T, ctxOuter context.Context) { serverSocketPath, stop := runOperationServiceServer(t) defer stop() diff --git a/internal/metadata/featureflag/feature_flags.go b/internal/metadata/featureflag/feature_flags.go index ecfc7d07a..096d0ddf3 100644 --- a/internal/metadata/featureflag/feature_flags.go +++ b/internal/metadata/featureflag/feature_flags.go @@ -17,6 +17,8 @@ var ( LogCommandStats = FeatureFlag{Name: "log_command_stats", OnByDefault: false} // GoUserFFBranch enables the Go implementation of UserFFBranch GoUserFFBranch = FeatureFlag{Name: "go_user_ff_branch", OnByDefault: true} + // GoUserCherryPick enables the Go implementation of UserCherryPick + GoUserCherryPick = FeatureFlag{Name: "go_user_cherry_pick", OnByDefault: false} // GoUserUpdateBranch enables the Go implementation of UserUpdateBranch GoUserUpdateBranch = FeatureFlag{Name: "go_user_update_branch", OnByDefault: false} // GoUserCommitFiles enables the Go implementation of UserCommitFiles @@ -103,6 +105,7 @@ var All = []FeatureFlag{ LogCommandStats, ReferenceTransactions, GoUserFFBranch, + GoUserCherryPick, GoUserUpdateBranch, GoUserCommitFiles, GoResolveConflicts, |