Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Okstad <pokstad@gitlab.com>2019-06-21 23:20:46 +0300
committerPaul Okstad <pokstad@gitlab.com>2019-06-21 23:20:53 +0300
commit9f426544fa3792ea8acc96f582e793122f64ed3b (patch)
tree468717b3c774315f65bda2789003c140e825676e
parent1c414abc11b4e55fed512a65e484a7b7c6d7f538 (diff)
DRY out ruby based testingpo-fix-worktree-cleanup
This change factors out the common code needed for running the Ruby-based operations service. This pattern allows for other services to borrow the same setup code when also interacting with the Ruby operations service.
-rw-r--r--internal/service/operations/apply_patch_test.go7
-rw-r--r--internal/service/operations/branches_test.go32
-rw-r--r--internal/service/operations/cherry_pick_test.go14
-rw-r--r--internal/service/operations/commit_files_test.go12
-rw-r--r--internal/service/operations/merge_test.go40
-rw-r--r--internal/service/operations/rebase_test.go20
-rw-r--r--internal/service/operations/revert_test.go12
-rw-r--r--internal/service/operations/squash_test.go20
-rw-r--r--internal/service/operations/submodules_test.go24
-rw-r--r--internal/service/operations/tags_test.go36
-rw-r--r--internal/service/operations/testhelper_test.go46
-rw-r--r--internal/service/operations/update_branches_test.go16
-rw-r--r--internal/service/repository/cleanup_test.go4
-rw-r--r--internal/service/repository/fetch_test.go2
-rw-r--r--internal/service/repository/rebase_in_progress.go6
-rw-r--r--internal/service/repository/rebase_in_progress_test.go6
-rw-r--r--internal/service/repository/squash_in_progress_test.go2
-rw-r--r--internal/service/repository/testhelper_test.go16
-rw-r--r--internal/testhelper/ruby_services.go63
19 files changed, 194 insertions, 184 deletions
diff --git a/internal/service/operations/apply_patch_test.go b/internal/service/operations/apply_patch_test.go
index dfa08ed69..e35bc872b 100644
--- a/internal/service/operations/apply_patch_test.go
+++ b/internal/service/operations/apply_patch_test.go
@@ -12,7 +12,6 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/internal/git/log"
- "gitlab.com/gitlab-org/gitaly/internal/service/operations"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/streamio"
"google.golang.org/grpc/codes"
@@ -22,7 +21,7 @@ func TestSuccessfulUserApplyPatch(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -143,7 +142,7 @@ func TestFailedPatchApplyPatch(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -178,7 +177,7 @@ func TestFailedValidationUserApplyPatch(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
diff --git a/internal/service/operations/branches_test.go b/internal/service/operations/branches_test.go
index 7b6597afd..125499c44 100644
--- a/internal/service/operations/branches_test.go
+++ b/internal/service/operations/branches_test.go
@@ -20,10 +20,10 @@ func TestSuccessfulUserCreateBranchRequest(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
startPoint := "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"
@@ -79,10 +79,10 @@ func TestSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
branchName := "new-branch"
@@ -117,10 +117,10 @@ func TestFailedUserCreateBranchDueToHooks(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
request := &gitalypb.UserCreateBranchRequest{
@@ -152,10 +152,10 @@ func TestFailedUserCreateBranchDueToHooks(t *testing.T) {
}
func TestFailedUserCreateBranchRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -224,10 +224,10 @@ func TestSuccessfulUserDeleteBranchRequest(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
branchNameInput := "to-be-deleted-soon-branch"
@@ -259,10 +259,10 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
branchNameInput := "to-be-deleted-soon-branch"
@@ -302,10 +302,10 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) {
}
func TestFailedUserDeleteBranchDueToValidation(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -364,10 +364,10 @@ func TestFailedUserDeleteBranchDueToHooks(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
branchNameInput := "to-be-deleted-soon-branch"
diff --git a/internal/service/operations/cherry_pick_test.go b/internal/service/operations/cherry_pick_test.go
index bc3609c72..366cdc8ee 100644
--- a/internal/service/operations/cherry_pick_test.go
+++ b/internal/service/operations/cherry_pick_test.go
@@ -23,7 +23,7 @@ func TestSuccessfulUserCherryPickRequest(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -130,7 +130,7 @@ func TestSuccessfulGitHooksForUserCherryPickRequest(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -182,7 +182,7 @@ func TestFailedUserCherryPickRequestDueToValidations(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
@@ -268,7 +268,7 @@ func TestFailedUserCherryPickRequestDueToPreReceiveError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -319,7 +319,7 @@ func TestFailedUserCherryPickRequestDueToCreateTreeError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -361,7 +361,7 @@ func TestFailedUserCherryPickRequestDueToCommitError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -399,7 +399,7 @@ func TestFailedUserCherryPickRequestDueToCommitError(t *testing.T) {
}
func runFullServer(t *testing.T) (*grpc.Server, string) {
- server := serverPkg.NewInsecure(operations.RubyServer)
+ server := serverPkg.NewInsecure(testhelper.RubyServer)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
listener, err := net.Listen("unix", serverSocketPath)
diff --git a/internal/service/operations/commit_files_test.go b/internal/service/operations/commit_files_test.go
index 19b8eeedd..352515784 100644
--- a/internal/service/operations/commit_files_test.go
+++ b/internal/service/operations/commit_files_test.go
@@ -28,7 +28,7 @@ func TestSuccessfulUserCommitFilesRequest(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -137,7 +137,7 @@ func TestSuccessfulUserCommitFilesRequestMove(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
ctxOuter, cancel := testhelper.Context()
@@ -200,7 +200,7 @@ func TestSuccessfulUserCommitFilesRequestForceCommit(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -252,7 +252,7 @@ func TestFailedUserCommitFilesRequestDueToHooks(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -295,7 +295,7 @@ func TestFailedUserCommitFilesRequestDueToIndexError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -367,7 +367,7 @@ func TestFailedUserCommitFilesRequest(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
diff --git a/internal/service/operations/merge_test.go b/internal/service/operations/merge_test.go
index b9a0be004..8a5926847 100644
--- a/internal/service/operations/merge_test.go
+++ b/internal/service/operations/merge_test.go
@@ -36,10 +36,10 @@ func TestSuccessfulMerge(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
mergeBidi, err := client.UserMergeBranch(ctx)
@@ -108,10 +108,10 @@ func TestAbortedMerge(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -179,10 +179,10 @@ func TestFailedMergeConcurrentUpdate(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
mergeBidi, err := client.UserMergeBranch(ctx)
@@ -223,10 +223,10 @@ func TestFailedMergeDueToHooks(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
prepareMergeBranch(t, testRepoPath)
@@ -283,10 +283,10 @@ func TestSuccessfulUserFFBranchRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -319,10 +319,10 @@ func TestSuccessfulUserFFBranchRequest(t *testing.T) {
}
func TestFailedUserFFBranchRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -414,10 +414,10 @@ func TestFailedUserFFBranchRequest(t *testing.T) {
}
func TestFailedUserFFBranchDueToHooks(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -454,10 +454,10 @@ func TestFailedUserFFBranchDueToHooks(t *testing.T) {
}
func TestSuccessfulUserMergeToRefRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -552,10 +552,10 @@ func TestSuccessfulUserMergeToRefRequest(t *testing.T) {
}
func TestFailedUserMergeToRefRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -654,10 +654,10 @@ func TestFailedUserMergeToRefRequest(t *testing.T) {
}
func TestUserMergeToRefIgnoreHooksRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
diff --git a/internal/service/operations/rebase_test.go b/internal/service/operations/rebase_test.go
index ba03ede41..84d36d2a3 100644
--- a/internal/service/operations/rebase_test.go
+++ b/internal/service/operations/rebase_test.go
@@ -35,7 +35,7 @@ func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -88,7 +88,7 @@ func TestFailedRebaseUserRebaseConfirmableRequestDueToInvalidHeader(t *testing.T
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -154,7 +154,7 @@ func TestAbortedUserRebaseConfirmable(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
@@ -222,7 +222,7 @@ func TestFailedUserRebaseConfirmableDueToApplyBeingFalse(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -268,7 +268,7 @@ func TestFailedUserRebaseConfirmableRequestDueToPreReceiveError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -330,7 +330,7 @@ func TestFailedUserRebaseConfirmableDueToGitError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -373,7 +373,7 @@ func TestSuccessfulUserRebaseRequest(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -414,7 +414,7 @@ func TestFailedUserRebaseRequestDueToPreReceiveError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -460,7 +460,7 @@ func TestFailedUserRebaseRequestDueToGitError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -498,7 +498,7 @@ func TestFailedUserRebaseRequestDueToValidations(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
diff --git a/internal/service/operations/revert_test.go b/internal/service/operations/revert_test.go
index 621b858de..ad58867eb 100644
--- a/internal/service/operations/revert_test.go
+++ b/internal/service/operations/revert_test.go
@@ -20,7 +20,7 @@ func TestSuccessfulUserRevertRequest(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -127,7 +127,7 @@ func TestSuccessfulGitHooksForUserRevertRequest(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -179,7 +179,7 @@ func TestFailedUserRevertRequestDueToValidations(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
@@ -265,7 +265,7 @@ func TestFailedUserRevertRequestDueToPreReceiveError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -316,7 +316,7 @@ func TestFailedUserRevertRequestDueToCreateTreeError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -358,7 +358,7 @@ func TestFailedUserRevertRequestDueToCommitError(t *testing.T) {
server, serverSocketPath := runFullServer(t)
defer server.Stop()
- client, conn := operations.NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
diff --git a/internal/service/operations/squash_test.go b/internal/service/operations/squash_test.go
index c0874f5cd..bed952af1 100644
--- a/internal/service/operations/squash_test.go
+++ b/internal/service/operations/squash_test.go
@@ -30,10 +30,10 @@ func TestSuccessfulUserSquashRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
@@ -81,10 +81,10 @@ func TestSuccessfulUserSquashRequestWith3wayMerge(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
@@ -151,10 +151,10 @@ func TestSplitIndex(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepoWithWorktree(t)
@@ -183,10 +183,10 @@ func TestFailedUserSquashRequestDueToGitError(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
@@ -212,10 +212,10 @@ func TestFailedUserSquashRequestDueToGitError(t *testing.T) {
}
func TestFailedUserSquashRequestDueToValidations(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
diff --git a/internal/service/operations/submodules_test.go b/internal/service/operations/submodules_test.go
index ec1b1ba5b..a86930f44 100644
--- a/internal/service/operations/submodules_test.go
+++ b/internal/service/operations/submodules_test.go
@@ -14,10 +14,10 @@ import (
)
func TestSuccessfulUserUpdateSubmoduleRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
@@ -81,10 +81,10 @@ func TestSuccessfulUserUpdateSubmoduleRequest(t *testing.T) {
}
func TestFailedUserUpdateSubmoduleRequestDueToValidations(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
@@ -209,10 +209,10 @@ func TestFailedUserUpdateSubmoduleRequestDueToInvalidBranch(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
@@ -236,10 +236,10 @@ func TestFailedUserUpdateSubmoduleRequestDueToInvalidSubmodule(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
@@ -263,10 +263,10 @@ func TestFailedUserUpdateSubmoduleRequestDueToSameReference(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.NewTestRepo(t)
@@ -293,10 +293,10 @@ func TestFailedUserUpdateSubmoduleRequestDueToRepositoryEmpty(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := NewOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanup := testhelper.InitRepoWithWorktree(t)
diff --git a/internal/service/operations/tags_test.go b/internal/service/operations/tags_test.go
index e8d10d1d4..af6d91500 100644
--- a/internal/service/operations/tags_test.go
+++ b/internal/service/operations/tags_test.go
@@ -17,10 +17,10 @@ func TestSuccessfulUserDeleteTagRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -52,10 +52,10 @@ func TestSuccessfulUserDeleteTagRequest(t *testing.T) {
}
func TestSuccessfulGitHooksForUserDeleteTagRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -101,10 +101,10 @@ func TestSuccessfulUserCreateTagRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -181,10 +181,10 @@ func TestSuccessfulUserCreateTagRequest(t *testing.T) {
}
func TestSuccessfulGitHooksForUserCreateTagRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -226,10 +226,10 @@ func TestSuccessfulGitHooksForUserCreateTagRequest(t *testing.T) {
}
func TestFailedUserDeleteTagRequestDueToValidation(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -285,10 +285,10 @@ func TestFailedUserDeleteTagRequestDueToValidation(t *testing.T) {
}
func TestFailedUserDeleteTagDueToHooks(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
@@ -332,10 +332,10 @@ func TestFailedUserDeleteTagDueToHooks(t *testing.T) {
}
func TestFailedUserCreateTagDueToHooks(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -371,10 +371,10 @@ func TestFailedUserCreateTagDueToHooks(t *testing.T) {
}
func TestFailedUserCreateTagRequestDueToTagExistence(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -412,10 +412,10 @@ func TestFailedUserCreateTagRequestDueToTagExistence(t *testing.T) {
}
func TestFailedUserCreateTagRequestDueToValidation(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
diff --git a/internal/service/operations/testhelper_test.go b/internal/service/operations/testhelper_test.go
index f9244d7fa..a5327f8f3 100644
--- a/internal/service/operations/testhelper_test.go
+++ b/internal/service/operations/testhelper_test.go
@@ -3,7 +3,6 @@ package operations
import (
"fmt"
"io/ioutil"
- "net"
"os"
"path"
"testing"
@@ -12,10 +11,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/internal/git/hooks"
- "gitlab.com/gitlab-org/gitaly/internal/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
- "google.golang.org/grpc"
- "google.golang.org/grpc/reflection"
)
var (
@@ -23,7 +19,6 @@ var (
gitlabPostHooks = []string{"post-receive"}
GitlabPreHooks = gitlabPreHooks
GitlabHooks []string
- RubyServer *rubyserver.Server
user = &gitalypb.User{
Name: []byte("Jane Doe"),
Email: []byte("janedoe@gitlab.com"),
@@ -42,8 +37,6 @@ func TestMain(m *testing.M) {
}
func testMain(m *testing.M) int {
- defer testhelper.MustHaveNoChildProcess()
-
hookDir, err := ioutil.TempDir("", "gitaly-tmp-hooks")
if err != nil {
log.Fatal(err)
@@ -54,46 +47,9 @@ func testMain(m *testing.M) int {
testhelper.ConfigureGitalySSH()
- RubyServer, err = rubyserver.Start()
- if err != nil {
- log.Fatal(err)
- }
- defer RubyServer.Stop()
-
- return m.Run()
-}
-
-func runOperationServiceServer(t *testing.T) (*grpc.Server, string) {
- grpcServer := testhelper.NewTestGrpcServer(t, nil, nil)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
-
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterOperationServiceServer(grpcServer, &server{RubyServer})
- reflection.Register(grpcServer)
-
- go grpcServer.Serve(listener)
-
- return grpcServer, "unix://" + serverSocketPath
-}
-
-func newOperationClient(t *testing.T, serverSocketPath string) (gitalypb.OperationServiceClient, *grpc.ClientConn) {
- connOpts := []grpc.DialOption{
- grpc.WithInsecure(),
- }
- conn, err := grpc.Dial(serverSocketPath, connOpts...)
- if err != nil {
- t.Fatal(err)
- }
-
- return gitalypb.NewOperationServiceClient(conn), conn
+ return testhelper.TestMainRuby(m)
}
-var NewOperationClient = newOperationClient
-
// The callee is responsible for clean up of the specific hook, testMain removes
// the hook dir
func WriteEnvToHook(t *testing.T, repoPath, hookName string) string {
diff --git a/internal/service/operations/update_branches_test.go b/internal/service/operations/update_branches_test.go
index 8dd910dc9..c313d712f 100644
--- a/internal/service/operations/update_branches_test.go
+++ b/internal/service/operations/update_branches_test.go
@@ -25,10 +25,10 @@ func TestSuccessfulUserUpdateBranchRequest(t *testing.T) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
request := &gitalypb.UserUpdateBranchRequest{
@@ -51,10 +51,10 @@ func TestSuccessfulUserUpdateBranchRequest(t *testing.T) {
}
func TestSuccessfulGitHooksForUserUpdateBranchRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
for _, hookName := range GitlabHooks {
@@ -91,10 +91,10 @@ func TestFailedUserUpdateBranchDueToHooks(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
request := &gitalypb.UserUpdateBranchRequest{
@@ -127,10 +127,10 @@ func TestFailedUserUpdateBranchDueToHooks(t *testing.T) {
}
func TestFailedUserUpdateBranchRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
+ server, serverSocketPath := testhelper.RunOpSvcServer(t, NewServer)
defer server.Stop()
- client, conn := newOperationClient(t, serverSocketPath)
+ client, conn := testhelper.NewOpSvcCli(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
diff --git a/internal/service/repository/cleanup_test.go b/internal/service/repository/cleanup_test.go
index cec59c4ec..efd281225 100644
--- a/internal/service/repository/cleanup_test.go
+++ b/internal/service/repository/cleanup_test.go
@@ -155,8 +155,8 @@ func TestCleanupDeletesStaleWorktrees(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
- defer cleanupFn()
+ testRepo, testRepoPath, _ := testhelper.NewTestRepo(t)
+ //defer cleanupFn()
req := &gitalypb.CleanupRequest{Repository: testRepo}
diff --git a/internal/service/repository/fetch_test.go b/internal/service/repository/fetch_test.go
index e6b069712..74fa9a8eb 100644
--- a/internal/service/repository/fetch_test.go
+++ b/internal/service/repository/fetch_test.go
@@ -183,7 +183,7 @@ func newTestRepo(t *testing.T, relativePath string) (*gitalypb.Repository, strin
}
func runFullServer(t *testing.T) (*grpc.Server, string) {
- server := serverPkg.NewInsecure(repository.RubyServer)
+ server := serverPkg.NewInsecure(testhelper.RubyServer)
serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
listener, err := net.Listen("unix", serverSocketPath)
diff --git a/internal/service/repository/rebase_in_progress.go b/internal/service/repository/rebase_in_progress.go
index 3cb5d8242..4e7f22750 100644
--- a/internal/service/repository/rebase_in_progress.go
+++ b/internal/service/repository/rebase_in_progress.go
@@ -16,7 +16,9 @@ import (
)
const (
- worktreePrefix = "gitlab-worktree"
+ // WorktreePrefix is subdirectory within the repo's directory where all
+ // rebase worktrees for merge requests are kept
+ WorktreePrefix = "gitlab-worktree"
rebaseWorktreePrefix = "rebase"
freshTimeout = 15 * time.Minute
)
@@ -39,7 +41,7 @@ func (s *server) IsRebaseInProgress(ctx context.Context, req *gitalypb.IsRebaseI
}
func freshWorktree(repoPath, prefix, id string) (bool, error) {
- worktreePath := path.Join(repoPath, worktreePrefix, fmt.Sprintf("%s-%s", prefix, id))
+ worktreePath := path.Join(repoPath, WorktreePrefix, fmt.Sprintf("%s-%s", prefix, id))
fs, err := os.Stat(worktreePath)
if err != nil {
diff --git a/internal/service/repository/rebase_in_progress_test.go b/internal/service/repository/rebase_in_progress_test.go
index 44d1bbe61..f68730d06 100644
--- a/internal/service/repository/rebase_in_progress_test.go
+++ b/internal/service/repository/rebase_in_progress_test.go
@@ -23,9 +23,9 @@ func TestSuccessfulIsRebaseInProgressRequest(t *testing.T) {
testRepo1, testRepo1Path, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", path.Join(testRepo1Path, worktreePrefix, fmt.Sprintf("%s-1", rebaseWorktreePrefix)), "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", path.Join(testRepo1Path, WorktreePrefix, fmt.Sprintf("%s-1", rebaseWorktreePrefix)), "master")
- brokenPath := path.Join(testRepo1Path, worktreePrefix, fmt.Sprintf("%s-2", rebaseWorktreePrefix))
+ brokenPath := path.Join(testRepo1Path, WorktreePrefix, fmt.Sprintf("%s-2", rebaseWorktreePrefix))
testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", brokenPath, "master")
os.Chmod(brokenPath, 0)
os.Chtimes(brokenPath, time.Now(), time.Now().Add(-16*time.Minute))
@@ -34,7 +34,7 @@ func TestSuccessfulIsRebaseInProgressRequest(t *testing.T) {
os.RemoveAll(brokenPath)
}()
- oldPath := path.Join(testRepo1Path, worktreePrefix, fmt.Sprintf("%s-3", rebaseWorktreePrefix))
+ oldPath := path.Join(testRepo1Path, WorktreePrefix, fmt.Sprintf("%s-3", rebaseWorktreePrefix))
testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", oldPath, "master")
os.Chtimes(oldPath, time.Now(), time.Now().Add(-16*time.Minute))
diff --git a/internal/service/repository/squash_in_progress_test.go b/internal/service/repository/squash_in_progress_test.go
index 2e262130c..e135261a1 100644
--- a/internal/service/repository/squash_in_progress_test.go
+++ b/internal/service/repository/squash_in_progress_test.go
@@ -20,7 +20,7 @@ func TestSuccessfulIsSquashInProgressRequest(t *testing.T) {
testRepo1, testRepo1Path, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", path.Join(testRepo1Path, worktreePrefix, "squash-1"), "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", testRepo1Path, "worktree", "add", "--detach", path.Join(testRepo1Path, WorktreePrefix, "squash-1"), "master")
testRepo2, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
diff --git a/internal/service/repository/testhelper_test.go b/internal/service/repository/testhelper_test.go
index b3dcab8fd..39ffc8581 100644
--- a/internal/service/repository/testhelper_test.go
+++ b/internal/service/repository/testhelper_test.go
@@ -12,7 +12,6 @@ import (
"gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
gitalyauth "gitlab.com/gitlab-org/gitaly/auth"
"gitlab.com/gitlab-org/gitaly/internal/config"
- "gitlab.com/gitlab-org/gitaly/internal/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/server/auth"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"google.golang.org/grpc"
@@ -23,8 +22,7 @@ import (
const testTimeString = "200601021504.05"
var (
- testTime = time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)
- RubyServer *rubyserver.Server
+ testTime = time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)
)
func newRepositoryClient(t *testing.T, serverSocketPath string) (gitalypb.RepositoryServiceClient, *grpc.ClientConn) {
@@ -54,7 +52,7 @@ func runRepoServer(t *testing.T) (*grpc.Server, string) {
t.Fatal(err)
}
- gitalypb.RegisterRepositoryServiceServer(server, NewServer(RubyServer))
+ gitalypb.RegisterRepositoryServiceServer(server, NewServer(testhelper.RubyServer))
reflection.Register(server)
go server.Serve(listener)
@@ -82,8 +80,6 @@ func TestMain(m *testing.M) {
}
func testMain(m *testing.M) int {
- defer testhelper.MustHaveNoChildProcess()
-
config.Config.Auth = config.Auth{Token: testhelper.RepositoryAuthToken}
var err error
@@ -94,11 +90,5 @@ func testMain(m *testing.M) int {
testhelper.ConfigureGitalySSH()
- RubyServer, err = rubyserver.Start()
- if err != nil {
- log.Fatal(err)
- }
- defer RubyServer.Stop()
-
- return m.Run()
+ return testhelper.TestMainRuby(m)
}
diff --git a/internal/testhelper/ruby_services.go b/internal/testhelper/ruby_services.go
new file mode 100644
index 000000000..cba626cfb
--- /dev/null
+++ b/internal/testhelper/ruby_services.go
@@ -0,0 +1,63 @@
+package testhelper
+
+import (
+ "net"
+ "testing"
+
+ log "github.com/sirupsen/logrus"
+ "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb"
+ "gitlab.com/gitlab-org/gitaly/internal/rubyserver"
+ "google.golang.org/grpc"
+ "google.golang.org/grpc/reflection"
+)
+
+var RubyServer *rubyserver.Server
+
+// testMainRuby should be used inside of TestMain for test suites that require
+// the ruby server
+func TestMainRuby(m *testing.M) int {
+ defer MustHaveNoChildProcess()
+
+ var err error
+ ConfigureRuby()
+ RubyServer, err = rubyserver.Start()
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer RubyServer.Stop()
+
+ return m.Run()
+}
+
+// RunOpSvcServer will run a ruby-based operation service. The factory function
+// must be provided as a param in order to avoid a cyclical dependency.
+func RunOpSvcServer(t *testing.T, newOpSvc func(*rubyserver.Server) gitalypb.OperationServiceServer) (*grpc.Server, string) {
+ grpcServer := NewTestGrpcServer(t, nil, nil)
+ serverSocketPath := GetTemporaryGitalySocketFileName()
+
+ listener, err := net.Listen("unix", serverSocketPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ gitalypb.RegisterOperationServiceServer(grpcServer, newOpSvc(RubyServer))
+ reflection.Register(grpcServer)
+
+ go grpcServer.Serve(listener)
+
+ return grpcServer, "unix://" + serverSocketPath
+}
+
+// NewOpSvcCli returns an insecure gRPC client for the operations service at
+// the provided socket path.
+func NewOpSvcCli(t *testing.T, serverSocketPath string) (gitalypb.OperationServiceClient, *grpc.ClientConn) {
+ connOpts := []grpc.DialOption{
+ grpc.WithInsecure(),
+ }
+ conn, err := grpc.Dial(serverSocketPath, connOpts...)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ return gitalypb.NewOperationServiceClient(conn), conn
+}