diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-11-20 12:28:38 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-11-20 12:28:38 +0300 |
commit | 885a33cc30598448df0691c3b2ab28fb9bb8009e (patch) | |
tree | 4f87273727a9fb7a6cedb9fac4a4f3b782f6a0e8 | |
parent | 9191f8f0f17d3b7a958424f91527aa8d8b4c3fcb (diff) | |
parent | 75710b0fdf49fdce116afe624d5f1bfb73f9ac67 (diff) |
Merge branch 'avar/branches-test-refactor-for-testWithFeature' into 'master'
Branch tests: use less indent-y featureset idiom
See merge request gitlab-org/gitaly!2813
-rw-r--r-- | internal/gitaly/service/operations/branches_test.go | 112 |
1 files changed, 54 insertions, 58 deletions
diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go index 76ce28ebd..977b5e6e9 100644 --- a/internal/gitaly/service/operations/branches_test.go +++ b/internal/gitaly/service/operations/branches_test.go @@ -98,14 +98,6 @@ func testSuccessfulCreateBranchRequest(t *testing.T, ctx context.Context) { } } -func TestSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T) { - testhelper.NewFeatureSets([]featureflag.FeatureFlag{ - featureflag.GoUserCreateBranch, - }).Run(t, func(t *testing.T, ctx context.Context) { - testSuccessfulGitHooksForUserCreateBranchRequest(t, ctx) - }) -} - func TestUserCreateBranchWithTransaction(t *testing.T) { t.Run("with reftx hook", func(t *testing.T) { testUserCreateBranchWithTransaction(t, true) @@ -219,6 +211,10 @@ func testUserCreateBranchWithTransaction(t *testing.T, withRefTxHook bool) { } } +func TestSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T) { + testWithFeature(t, featureflag.GoUserCreateBranch, testSuccessfulGitHooksForUserCreateBranchRequest) +} + func testSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T, ctx context.Context) { testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() @@ -357,36 +353,36 @@ func testFailedUserCreateBranchRequest(t *testing.T, ctx context.Context) { } func TestSuccessfulUserDeleteBranchRequest(t *testing.T) { - testhelper.NewFeatureSets([]featureflag.FeatureFlag{ - featureflag.GoUserDeleteBranch, - }).Run(t, func(t *testing.T, ctx context.Context) { - testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t) - defer cleanupFn() + testWithFeature(t, featureflag.GoUserDeleteBranch, testSuccessfulUserDeleteBranchRequest) +} - serverSocketPath, stop := runOperationServiceServer(t) - defer stop() +func testSuccessfulUserDeleteBranchRequest(t *testing.T, ctx context.Context) { + testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t) + defer cleanupFn() - client, conn := newOperationClient(t, serverSocketPath) - defer conn.Close() + serverSocketPath, stop := runOperationServiceServer(t) + defer stop() - branchNameInput := "to-be-deleted-soon-branch" + client, conn := newOperationClient(t, serverSocketPath) + defer conn.Close() - defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchNameInput).Run() + branchNameInput := "to-be-deleted-soon-branch" - testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput) + defer exec.Command(command.GitPath(), "-C", testRepoPath, "branch", "-d", branchNameInput).Run() - request := &gitalypb.UserDeleteBranchRequest{ - Repository: testRepo, - BranchName: []byte(branchNameInput), - User: testhelper.TestUser, - } + testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput) - _, err := client.UserDeleteBranch(ctx, request) - require.NoError(t, err) + request := &gitalypb.UserDeleteBranchRequest{ + Repository: testRepo, + BranchName: []byte(branchNameInput), + User: testhelper.TestUser, + } - branches := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch") - require.NotContains(t, string(branches), branchNameInput, "branch name still exists in branches list") - }) + _, err := client.UserDeleteBranch(ctx, request) + require.NoError(t, err) + + branches := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch") + require.NotContains(t, string(branches), branchNameInput, "branch name still exists in branches list") } func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) { @@ -428,6 +424,10 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) { } func TestFailedUserDeleteBranchDueToValidation(t *testing.T) { + testWithFeature(t, featureflag.GoUserDeleteBranch, testFailedUserDeleteBranchDueToValidation) +} + +func testFailedUserDeleteBranchDueToValidation(t *testing.T, ctx context.Context) { serverSocketPath, stop := runOperationServiceServer(t) defer stop() @@ -469,19 +469,19 @@ func TestFailedUserDeleteBranchDueToValidation(t *testing.T) { }, } - testhelper.NewFeatureSets([]featureflag.FeatureFlag{ - featureflag.GoUserDeleteBranch, - }).Run(t, func(t *testing.T, ctx context.Context) { - for _, testCase := range testCases { - t.Run(testCase.desc, func(t *testing.T) { - _, err := client.UserDeleteBranch(ctx, testCase.request) - testhelper.RequireGrpcError(t, err, testCase.code) - }) - } - }) + for _, testCase := range testCases { + t.Run(testCase.desc, func(t *testing.T) { + _, err := client.UserDeleteBranch(ctx, testCase.request) + testhelper.RequireGrpcError(t, err, testCase.code) + }) + } } func TestFailedUserDeleteBranchDueToHooks(t *testing.T) { + testWithFeature(t, featureflag.GoUserDeleteBranch, testFailedUserDeleteBranchDueToHooks) +} + +func testFailedUserDeleteBranchDueToHooks(t *testing.T, ctx context.Context) { testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() @@ -503,22 +503,18 @@ func TestFailedUserDeleteBranchDueToHooks(t *testing.T) { hookContent := []byte("#!/bin/sh\necho GL_ID=$GL_ID\nexit 1") - testhelper.NewFeatureSets([]featureflag.FeatureFlag{ - featureflag.GoUserDeleteBranch, - }).Run(t, func(t *testing.T, ctx context.Context) { - for _, hookName := range gitlabPreHooks { - t.Run(hookName, func(t *testing.T) { - remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) - require.NoError(t, err) - defer remove() - - response, err := client.UserDeleteBranch(ctx, request) - require.NoError(t, err) - require.Contains(t, response.PreReceiveError, "GL_ID="+testhelper.TestUser.GlId) - - branches := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch") - require.Contains(t, string(branches), branchNameInput, "branch name does not exist in branches list") - }) - } - }) + for _, hookName := range gitlabPreHooks { + t.Run(hookName, func(t *testing.T) { + remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent) + require.NoError(t, err) + defer remove() + + response, err := client.UserDeleteBranch(ctx, request) + require.NoError(t, err) + require.Contains(t, response.PreReceiveError, "GL_ID="+testhelper.TestUser.GlId) + + branches := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch") + require.Contains(t, string(branches), branchNameInput, "branch name does not exist in branches list") + }) + } } |