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:
authorJohn Cai <jcai@gitlab.com>2020-03-16 22:11:38 +0300
committerJohn Cai <jcai@gitlab.com>2020-03-17 00:05:00 +0300
commit195dcd74fb98635bcfacf8ca49d11801c4372807 (patch)
tree89fb7e99e130a2bbe87775f6e10cd501f8767a3a
parent4bd9b1536b4776ae369b8e43388a25941e18a19e (diff)
Put service tests behind test server with praefect
-rw-r--r--internal/service/cleanup/apply_bfg_object_map_stream_test.go8
-rw-r--r--internal/service/cleanup/testhelper_test.go20
-rw-r--r--internal/service/commit/between_test.go8
-rw-r--r--internal/service/commit/commit_messages_test.go8
-rw-r--r--internal/service/commit/commit_signatures_test.go8
-rw-r--r--internal/service/commit/commits_by_message_test.go8
-rw-r--r--internal/service/commit/count_commits_test.go8
-rw-r--r--internal/service/commit/count_diverging_commits_test.go12
-rw-r--r--internal/service/commit/filter_shas_with_signatures.go4
-rw-r--r--internal/service/commit/filter_shas_with_signatures_test.go6
-rw-r--r--internal/service/commit/find_all_commits_test.go8
-rw-r--r--internal/service/commit/find_commit_test.go16
-rw-r--r--internal/service/commit/find_commits_test.go24
-rw-r--r--internal/service/commit/isancestor_test.go12
-rw-r--r--internal/service/commit/languages_test.go20
-rw-r--r--internal/service/commit/last_commit_for_path_test.go8
-rw-r--r--internal/service/commit/list_commits_by_oid_test.go8
-rw-r--r--internal/service/commit/list_commits_by_ref_name_test.go8
-rw-r--r--internal/service/commit/list_files_test.go12
-rw-r--r--internal/service/commit/list_last_commits_for_tree_test.go16
-rw-r--r--internal/service/commit/raw_blame_test.go8
-rw-r--r--internal/service/commit/stats_test.go8
-rw-r--r--internal/service/commit/testhelper_test.go21
-rw-r--r--internal/service/commit/tree_entries_test.go16
-rw-r--r--internal/service/commit/tree_entry_test.go8
-rw-r--r--internal/service/conflicts/list_conflict_files_test.go12
-rw-r--r--internal/service/conflicts/testhelper_test.go20
-rw-r--r--internal/service/diff/commit_test.go44
-rw-r--r--internal/service/diff/numstat_test.go8
-rw-r--r--internal/service/diff/raw_test.go16
-rw-r--r--internal/service/diff/testhelper_test.go20
-rw-r--r--internal/service/hooks/post_receive_test.go8
-rw-r--r--internal/service/hooks/pre_receive_test.go8
-rw-r--r--internal/service/hooks/testhelper_test.go24
-rw-r--r--internal/service/hooks/update_test.go8
-rw-r--r--internal/service/objectpool/alternates_test.go12
-rw-r--r--internal/service/objectpool/create.go14
-rw-r--r--internal/service/objectpool/create_test.go123
-rw-r--r--internal/service/objectpool/fetch_into_object_pool_test.go33
-rw-r--r--internal/service/objectpool/get_test.go12
-rw-r--r--internal/service/objectpool/link_test.go24
-rw-r--r--internal/service/objectpool/reduplicate_test.go4
-rw-r--r--internal/service/objectpool/testhelper_test.go28
-rw-r--r--internal/service/operations/branches_test.go40
-rw-r--r--internal/service/operations/cherry_pick_test.go4
-rw-r--r--internal/service/operations/commit_files_test.go2
-rw-r--r--internal/service/operations/merge_test.go48
-rw-r--r--internal/service/operations/rebase_test.go6
-rw-r--r--internal/service/operations/revert_test.go4
-rw-r--r--internal/service/operations/squash_test.go24
-rw-r--r--internal/service/operations/submodules_test.go24
-rw-r--r--internal/service/operations/tags_test.go44
-rw-r--r--internal/service/operations/testhelper_test.go53
-rw-r--r--internal/service/operations/update_branches_test.go20
-rw-r--r--internal/service/ref/branches_test.go8
-rw-r--r--internal/service/ref/delete_refs_test.go12
-rw-r--r--internal/service/ref/list_new_blobs_test.go4
-rw-r--r--internal/service/ref/list_new_commits_test.go4
-rw-r--r--internal/service/ref/pack_refs_test.go4
-rw-r--r--internal/service/ref/refexists_test.go4
-rw-r--r--internal/service/ref/refname_test.go20
-rw-r--r--internal/service/ref/refs_test.go96
-rw-r--r--internal/service/ref/remote_branches_test.go8
-rw-r--r--internal/service/ref/tag_messages_test.go8
-rw-r--r--internal/service/ref/testhelper_test.go19
-rw-r--r--internal/service/remote/find_remote_root_ref_test.go12
-rw-r--r--internal/service/remote/remotes_test.go32
-rw-r--r--internal/service/remote/testhelper_test.go20
-rw-r--r--internal/service/remote/update_remote_mirror_test.go16
-rw-r--r--internal/service/smarthttp/inforefs.go6
-rw-r--r--internal/service/smarthttp/inforefs_test.go69
-rw-r--r--internal/service/smarthttp/receive_pack_test.go24
-rw-r--r--internal/service/smarthttp/testhelper_test.go20
-rw-r--r--internal/service/smarthttp/upload_pack.go5
-rw-r--r--internal/service/smarthttp/upload_pack_test.go24
-rw-r--r--internal/service/ssh/receive_pack_test.go28
-rw-r--r--internal/service/ssh/testhelper_test.go20
-rw-r--r--internal/service/ssh/upload_archive_test.go12
-rw-r--r--internal/service/ssh/upload_pack_test.go25
-rw-r--r--internal/service/wiki/delete_page_test.go8
-rw-r--r--internal/service/wiki/find_file_test.go8
-rw-r--r--internal/service/wiki/find_page_test.go16
-rw-r--r--internal/service/wiki/get_all_pages_test.go12
-rw-r--r--internal/service/wiki/get_page_versions_test.go8
-rw-r--r--internal/service/wiki/list_pages_test.go8
-rw-r--r--internal/service/wiki/testhelper_test.go19
-rw-r--r--internal/service/wiki/update_page_test.go8
-rw-r--r--internal/service/wiki/write_page_test.go16
88 files changed, 690 insertions, 883 deletions
diff --git a/internal/service/cleanup/apply_bfg_object_map_stream_test.go b/internal/service/cleanup/apply_bfg_object_map_stream_test.go
index 9eb19da78..2a004b905 100644
--- a/internal/service/cleanup/apply_bfg_object_map_stream_test.go
+++ b/internal/service/cleanup/apply_bfg_object_map_stream_test.go
@@ -17,8 +17,8 @@ import (
)
func TestApplyBfgObjectMapStreamSuccess(t *testing.T) {
- server, serverSocketPath := runCleanupServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runCleanupServiceServer(t)
+ defer stop()
client, conn := newCleanupServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -81,8 +81,8 @@ func requireEntry(t *testing.T, entry *gitalypb.ApplyBfgObjectMapStreamResponse_
}
func TestApplyBfgObjectMapStreamFailsOnInvalidInput(t *testing.T) {
- server, serverSocketPath := runCleanupServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runCleanupServiceServer(t)
+ defer stop()
client, conn := newCleanupServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/cleanup/testhelper_test.go b/internal/service/cleanup/testhelper_test.go
index 1ad6230f2..112153ab8 100644
--- a/internal/service/cleanup/testhelper_test.go
+++ b/internal/service/cleanup/testhelper_test.go
@@ -1,30 +1,24 @@
package cleanup
import (
- "net"
"testing"
+ "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
-func runCleanupServiceServer(t *testing.T) (*grpc.Server, string) {
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
- grpcServer := testhelper.NewTestGrpcServer(t, nil, nil)
+func runCleanupServiceServer(t *testing.T) (string, func()) {
+ srv := testhelper.NewServer(t, nil, nil)
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterCleanupServiceServer(grpcServer, NewServer())
- reflection.Register(grpcServer)
+ gitalypb.RegisterCleanupServiceServer(srv.GrpcServer(), NewServer())
+ reflection.Register(srv.GrpcServer())
- go grpcServer.Serve(listener)
+ require.NoError(t, srv.Start())
- return grpcServer, "unix://" + serverSocketPath
+ return "unix://" + srv.Socket(), srv.Stop
}
func newCleanupServiceClient(t *testing.T, serverSocketPath string) (gitalypb.CleanupServiceClient, *grpc.ClientConn) {
diff --git a/internal/service/commit/between_test.go b/internal/service/commit/between_test.go
index 78f678aaf..0c7c9afd9 100644
--- a/internal/service/commit/between_test.go
+++ b/internal/service/commit/between_test.go
@@ -13,8 +13,8 @@ import (
)
func TestSuccessfulCommitsBetween(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -198,8 +198,8 @@ func TestSuccessfulCommitsBetween(t *testing.T) {
}
func TestFailedCommitsBetweenRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/commit_messages_test.go b/internal/service/commit/commit_messages_test.go
index 7d6b97e0c..c19646db8 100644
--- a/internal/service/commit/commit_messages_test.go
+++ b/internal/service/commit/commit_messages_test.go
@@ -13,8 +13,8 @@ import (
)
func TestSuccessfulGetCommitMessagesRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -55,8 +55,8 @@ func TestSuccessfulGetCommitMessagesRequest(t *testing.T) {
}
func TestFailedGetCommitMessagesRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/commit_signatures_test.go b/internal/service/commit/commit_signatures_test.go
index 09493afa1..fe6ee1799 100644
--- a/internal/service/commit/commit_signatures_test.go
+++ b/internal/service/commit/commit_signatures_test.go
@@ -11,8 +11,8 @@ import (
)
func TestSuccessfulGetCommitSignaturesRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -61,8 +61,8 @@ func TestSuccessfulGetCommitSignaturesRequest(t *testing.T) {
}
func TestFailedGetCommitSignaturesRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/commits_by_message_test.go b/internal/service/commit/commits_by_message_test.go
index ad08176ad..881dcaa1e 100644
--- a/internal/service/commit/commits_by_message_test.go
+++ b/internal/service/commit/commits_by_message_test.go
@@ -13,8 +13,8 @@ import (
)
func TestSuccessfulCommitsByMessageRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -155,8 +155,8 @@ func TestSuccessfulCommitsByMessageRequest(t *testing.T) {
}
func TestFailedCommitsByMessageRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/count_commits_test.go b/internal/service/commit/count_commits_test.go
index b609366fb..b0a70aa0e 100644
--- a/internal/service/commit/count_commits_test.go
+++ b/internal/service/commit/count_commits_test.go
@@ -14,8 +14,8 @@ import (
)
func TestSuccessfulCountCommitsRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -163,8 +163,8 @@ func TestSuccessfulCountCommitsRequest(t *testing.T) {
}
func TestFailedCountCommitsRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/count_diverging_commits_test.go b/internal/service/commit/count_diverging_commits_test.go
index 928a9143a..920d8f971 100644
--- a/internal/service/commit/count_diverging_commits_test.go
+++ b/internal/service/commit/count_diverging_commits_test.go
@@ -59,8 +59,8 @@ func createRepoWithDivergentBranches(t *testing.T, leftCommits, rightCommits int
}
func TestSuccessfulCountDivergentCommitsRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -137,8 +137,8 @@ func TestSuccessfulCountDivergentCommitsRequest(t *testing.T) {
}
func TestSuccessfulCountDivergentCommitsRequestWithMaxCount(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -186,8 +186,8 @@ func TestSuccessfulCountDivergentCommitsRequestWithMaxCount(t *testing.T) {
}
func TestFailedCountDivergentCommitsRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/filter_shas_with_signatures.go b/internal/service/commit/filter_shas_with_signatures.go
index 8cd2f24fc..d02519630 100644
--- a/internal/service/commit/filter_shas_with_signatures.go
+++ b/internal/service/commit/filter_shas_with_signatures.go
@@ -1,9 +1,9 @@
package commit
import (
- "errors"
"io"
+ "gitlab.com/gitlab-org/gitaly/internal/errors"
"gitlab.com/gitlab-org/gitaly/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/helper"
@@ -28,7 +28,7 @@ func (s *server) FilterShasWithSignatures(bidi gitalypb.CommitService_FilterShas
func validateFirstFilterShasWithSignaturesRequest(in *gitalypb.FilterShasWithSignaturesRequest) error {
if in.Repository == nil {
- return errors.New("no repository given")
+ return errors.ErrEmptyRepository
}
return nil
}
diff --git a/internal/service/commit/filter_shas_with_signatures_test.go b/internal/service/commit/filter_shas_with_signatures_test.go
index 877a58f5b..4f7915024 100644
--- a/internal/service/commit/filter_shas_with_signatures_test.go
+++ b/internal/service/commit/filter_shas_with_signatures_test.go
@@ -13,8 +13,8 @@ func TestFilterShasWithSignaturesSuccessful(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -66,7 +66,7 @@ func TestFilterShasWithSignaturesSuccessful(t *testing.T) {
func TestFilterShasWithSignaturesValidationError(t *testing.T) {
err := validateFirstFilterShasWithSignaturesRequest(&gitalypb.FilterShasWithSignaturesRequest{})
- require.Contains(t, err.Error(), "no repository given")
+ require.Contains(t, err.Error(), "empty Repository")
}
func recvFSWS(stream gitalypb.CommitService_FilterShasWithSignaturesClient) ([][]byte, error) {
diff --git a/internal/service/commit/find_all_commits_test.go b/internal/service/commit/find_all_commits_test.go
index e79b1ae45..fad553156 100644
--- a/internal/service/commit/find_all_commits_test.go
+++ b/internal/service/commit/find_all_commits_test.go
@@ -25,8 +25,8 @@ func TestSuccessfulFindAllCommitsRequest(t *testing.T) {
}, nil
}
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -285,8 +285,8 @@ func TestSuccessfulFindAllCommitsRequest(t *testing.T) {
}
func TestFailedFindAllCommitsRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/find_commit_test.go b/internal/service/commit/find_commit_test.go
index 96367f559..d4ac876ed 100644
--- a/internal/service/commit/find_commit_test.go
+++ b/internal/service/commit/find_commit_test.go
@@ -24,8 +24,8 @@ func TestSuccessfulFindCommitRequest(t *testing.T) {
windows1251Message, err := ioutil.ReadFile("testdata/commit-c809470461118b7bcab850f6e9a7ca97ac42f8ea-message.txt")
require.NoError(t, err)
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -270,8 +270,8 @@ func TestSuccessfulFindCommitRequest(t *testing.T) {
}
func TestFailedFindCommitRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -320,8 +320,8 @@ func benchmarkFindCommit(withCache bool, b *testing.B) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := startTestServices(b)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(b)
+ defer stop()
client, conn := newCommitServiceClient(b, serverSocketPath)
defer conn.Close()
@@ -367,8 +367,8 @@ func TestFindCommitWithCache(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/find_commits_test.go b/internal/service/commit/find_commits_test.go
index 29a7eee95..435e1007b 100644
--- a/internal/service/commit/find_commits_test.go
+++ b/internal/service/commit/find_commits_test.go
@@ -20,8 +20,8 @@ func TestFindCommitsFields(t *testing.T) {
windows1251Message, err := ioutil.ReadFile("testdata/commit-c809470461118b7bcab850f6e9a7ca97ac42f8ea-message.txt")
require.NoError(t, err)
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -179,8 +179,8 @@ func TestFindCommitsFields(t *testing.T) {
}
func TestSuccessfulFindCommitsRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -422,8 +422,8 @@ func TestSuccessfulFindCommitsRequest(t *testing.T) {
}
func TestSuccessfulFindCommitsRequestWithAltGitObjectDirs(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -492,8 +492,8 @@ func TestSuccessfulFindCommitsRequestWithAltGitObjectDirs(t *testing.T) {
}
func TestSuccessfulFindCommitsRequestWithAmbiguousRef(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -538,8 +538,8 @@ func TestSuccessfulFindCommitsRequestWithAmbiguousRef(t *testing.T) {
}
func TestFailureFindCommitsRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -589,8 +589,8 @@ func TestFailureFindCommitsRequest(t *testing.T) {
}
func TestFindCommitsRequestWithFollowAndOffset(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/isancestor_test.go b/internal/service/commit/isancestor_test.go
index b1d22eae9..7b0bc6528 100644
--- a/internal/service/commit/isancestor_test.go
+++ b/internal/service/commit/isancestor_test.go
@@ -14,8 +14,8 @@ import (
)
func TestCommitIsAncestorFailure(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -80,8 +80,8 @@ func TestCommitIsAncestorFailure(t *testing.T) {
}
func TestCommitIsAncestorSuccess(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -177,8 +177,8 @@ func TestCommitIsAncestorSuccess(t *testing.T) {
}
func TestSuccessfulIsAncestorRequestWithAltGitObjectDirs(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/languages_test.go b/internal/service/commit/languages_test.go
index eaf526925..154ffe4c6 100644
--- a/internal/service/commit/languages_test.go
+++ b/internal/service/commit/languages_test.go
@@ -13,8 +13,8 @@ import (
)
func TestLanguages(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -56,8 +56,8 @@ func TestLanguages(t *testing.T) {
}
func TestFileCountIsZeroWhenFeatureIsDisabled(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -93,8 +93,8 @@ func requireLanguageEqual(t *testing.T, expected, actual *gitalypb.CommitLanguag
}
func TestLanguagesEmptyRevision(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -123,8 +123,8 @@ func TestLanguagesEmptyRevision(t *testing.T) {
}
func TestInvalidCommitLanguagesRequestRevision(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -143,8 +143,8 @@ func TestInvalidCommitLanguagesRequestRevision(t *testing.T) {
}
func TestAmbiguousRefCommitLanguagesRequestRevision(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/last_commit_for_path_test.go b/internal/service/commit/last_commit_for_path_test.go
index 484d0ed9e..c3cf3e645 100644
--- a/internal/service/commit/last_commit_for_path_test.go
+++ b/internal/service/commit/last_commit_for_path_test.go
@@ -12,8 +12,8 @@ import (
)
func TestSuccessfulLastCommitForPathRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -93,8 +93,8 @@ func TestSuccessfulLastCommitForPathRequest(t *testing.T) {
}
func TestFailedLastCommitForPathRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/list_commits_by_oid_test.go b/internal/service/commit/list_commits_by_oid_test.go
index 7b3435350..94352299b 100644
--- a/internal/service/commit/list_commits_by_oid_test.go
+++ b/internal/service/commit/list_commits_by_oid_test.go
@@ -11,8 +11,8 @@ import (
)
func TestSuccessfulListCommitsByOidRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -176,8 +176,8 @@ var masterCommitids = []string{
}
func TestSuccessfulListCommitsByOidLargeRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/list_commits_by_ref_name_test.go b/internal/service/commit/list_commits_by_ref_name_test.go
index a0a2d3969..4e626cdb7 100644
--- a/internal/service/commit/list_commits_by_ref_name_test.go
+++ b/internal/service/commit/list_commits_by_ref_name_test.go
@@ -10,8 +10,8 @@ import (
)
func TestSuccessfulListCommitsByRefNameRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -189,8 +189,8 @@ var repositoryRefNames = map[string]string{
}
func TestSuccessfulListCommitsByRefNameLargeRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/list_files_test.go b/internal/service/commit/list_files_test.go
index 1efcf4428..3946cc4b6 100644
--- a/internal/service/commit/list_files_test.go
+++ b/internal/service/commit/list_files_test.go
@@ -49,8 +49,8 @@ func TestListFilesSuccess(t *testing.T) {
defaultBranchName = ref.DefaultBranchName
}()
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -136,8 +136,8 @@ func TestListFilesSuccess(t *testing.T) {
}
func TestListFilesFailure(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -186,8 +186,8 @@ func drainListFilesResponse(c gitalypb.CommitService_ListFilesClient) error {
}
func TestInvalidListFilesRequestRevision(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/list_last_commits_for_tree_test.go b/internal/service/commit/list_last_commits_for_tree_test.go
index c7b611dba..a74b12abe 100644
--- a/internal/service/commit/list_last_commits_for_tree_test.go
+++ b/internal/service/commit/list_last_commits_for_tree_test.go
@@ -20,10 +20,10 @@ type commitInfo struct {
}
func TestSuccessfulListLastCommitsForTreeRequest(t *testing.T) {
- server, serverSockerPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
- client, conn := newCommitServiceClient(t, serverSockerPath)
+ client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
@@ -210,8 +210,8 @@ func TestSuccessfulListLastCommitsForTreeRequest(t *testing.T) {
}
func TestFailedListLastCommitsForTreeRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -306,10 +306,10 @@ func TestFailedListLastCommitsForTreeRequest(t *testing.T) {
}
func TestNonUtf8ListLastCommitsForTreeRequest(t *testing.T) {
- server, serverSockerPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
- client, conn := newCommitServiceClient(t, serverSockerPath)
+ client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
ctx, cancel := testhelper.Context()
diff --git a/internal/service/commit/raw_blame_test.go b/internal/service/commit/raw_blame_test.go
index 034b9f1ce..3c3e319cb 100644
--- a/internal/service/commit/raw_blame_test.go
+++ b/internal/service/commit/raw_blame_test.go
@@ -14,8 +14,8 @@ import (
)
func TestSuccessfulRawBlameRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -74,8 +74,8 @@ func TestSuccessfulRawBlameRequest(t *testing.T) {
}
func TestFailedRawBlameRequest(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/stats_test.go b/internal/service/commit/stats_test.go
index 2d9236754..fe03ce01e 100644
--- a/internal/service/commit/stats_test.go
+++ b/internal/service/commit/stats_test.go
@@ -12,8 +12,8 @@ import (
)
func TestCommitStatsSuccess(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -83,8 +83,8 @@ func TestCommitStatsSuccess(t *testing.T) {
}
func TestCommitStatsFailure(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/testhelper_test.go b/internal/service/commit/testhelper_test.go
index b4621af6a..ee90ac0ef 100644
--- a/internal/service/commit/testhelper_test.go
+++ b/internal/service/commit/testhelper_test.go
@@ -1,19 +1,17 @@
package commit
import (
- "net"
"os"
"testing"
"github.com/golang/protobuf/ptypes/timestamp"
+ "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
-var ()
-
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
@@ -24,20 +22,15 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func startTestServices(t testing.TB) (*grpc.Server, string) {
- server := testhelper.NewTestGrpcServer(t, nil, nil)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
+func startTestServices(t testing.TB) (string, func()) {
+ srv := testhelper.NewServer(t, nil, nil)
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal("failed to start server")
- }
+ gitalypb.RegisterCommitServiceServer(srv.GrpcServer(), NewServer())
+ reflection.Register(srv.GrpcServer())
- gitalypb.RegisterCommitServiceServer(server, NewServer())
- reflection.Register(server)
+ require.NoError(t, srv.Start())
- go server.Serve(listener)
- return server, "unix://" + serverSocketPath
+ return "unix://" + srv.Socket(), srv.Stop
}
func newCommitServiceClient(t testing.TB, serviceSocketPath string) (gitalypb.CommitServiceClient, *grpc.ClientConn) {
diff --git a/internal/service/commit/tree_entries_test.go b/internal/service/commit/tree_entries_test.go
index 6c7af65e7..7ef2d23e6 100644
--- a/internal/service/commit/tree_entries_test.go
+++ b/internal/service/commit/tree_entries_test.go
@@ -17,8 +17,8 @@ import (
)
func TestSuccessfulGetTreeEntriesWithCurlyBraces(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -86,8 +86,8 @@ func TestSuccessfulGetTreeEntries(t *testing.T) {
commitID := "d25b6d94034242f3930dfcfeb6d8d9aac3583992"
rootOid := "21bdc8af908562ae485ed46d71dd5426c08b084a"
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -410,8 +410,8 @@ func getTreeEntriesFromTreeEntryClient(t *testing.T, client gitalypb.CommitServi
}
func TestSuccessfulGetTreeEntries_FlatPathMaxDeep_SingleFoldersStructure(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -463,8 +463,8 @@ func TestSuccessfulGetTreeEntries_FlatPathMaxDeep_SingleFoldersStructure(t *test
}
func TestFailedGetTreeEntriesRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/commit/tree_entry_test.go b/internal/service/commit/tree_entry_test.go
index 32a68a970..79076e9ff 100644
--- a/internal/service/commit/tree_entry_test.go
+++ b/internal/service/commit/tree_entry_test.go
@@ -21,8 +21,8 @@ type treeEntry struct {
}
func TestSuccessfulTreeEntry(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -160,8 +160,8 @@ func TestSuccessfulTreeEntry(t *testing.T) {
}
func TestFailedTreeEntryRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := startTestServices(t)
- defer server.Stop()
+ serverSocketPath, stop := startTestServices(t)
+ defer stop()
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/conflicts/list_conflict_files_test.go b/internal/service/conflicts/list_conflict_files_test.go
index 074234caa..b384f8b8c 100644
--- a/internal/service/conflicts/list_conflict_files_test.go
+++ b/internal/service/conflicts/list_conflict_files_test.go
@@ -17,8 +17,8 @@ type conflictFile struct {
}
func TestSuccessfulListConflictFilesRequest(t *testing.T) {
- server, serverSocketPath := runConflictsServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runConflictsServer(t)
+ defer stop()
client, conn := NewConflictsClient(t, serverSocketPath)
defer conn.Close()
@@ -93,8 +93,8 @@ end
}
func TestListConflictFilesFailedPrecondition(t *testing.T) {
- server, serverSocketPath := runConflictsServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runConflictsServer(t)
+ defer stop()
client, conn := NewConflictsClient(t, serverSocketPath)
defer conn.Close()
@@ -158,8 +158,8 @@ func TestListConflictFilesFailedPrecondition(t *testing.T) {
}
func TestFailedListConflictFilesRequestDueToValidation(t *testing.T) {
- server, serverSocketPath := runConflictsServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runConflictsServer(t)
+ defer stop()
client, conn := NewConflictsClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/conflicts/testhelper_test.go b/internal/service/conflicts/testhelper_test.go
index f2a05721d..2b956b0fb 100644
--- a/internal/service/conflicts/testhelper_test.go
+++ b/internal/service/conflicts/testhelper_test.go
@@ -2,11 +2,11 @@ package conflicts
import (
"io/ioutil"
- "net"
"os"
"testing"
log "github.com/sirupsen/logrus"
+ "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/git/hooks"
"gitlab.com/gitlab-org/gitaly/internal/rubyserver"
@@ -42,21 +42,15 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func runConflictsServer(t *testing.T) (*grpc.Server, string) {
- server := testhelper.NewTestGrpcServer(t, nil, nil)
+func runConflictsServer(t *testing.T) (string, func()) {
+ srv := testhelper.NewServer(t, nil, nil)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterConflictsServiceServer(server, NewServer(RubyServer))
- reflection.Register(server)
+ gitalypb.RegisterConflictsServiceServer(srv.GrpcServer(), NewServer(RubyServer))
+ reflection.Register(srv.GrpcServer())
- go server.Serve(listener)
+ require.NoError(t, srv.Start())
- return server, "unix://" + serverSocketPath
+ return "unix://" + srv.Socket(), srv.Stop
}
func NewConflictsClient(t *testing.T, serverSocketPath string) (gitalypb.ConflictsServiceClient, *grpc.ClientConn) {
diff --git a/internal/service/diff/commit_test.go b/internal/service/diff/commit_test.go
index 9953d276a..5b168ba76 100644
--- a/internal/service/diff/commit_test.go
+++ b/internal/service/diff/commit_test.go
@@ -15,8 +15,8 @@ import (
)
func TestSuccessfulCommitDiffRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -192,8 +192,8 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
}
func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -270,8 +270,8 @@ func TestSuccessfulCommitDiffRequestWithPaths(t *testing.T) {
}
func TestSuccessfulCommitDiffRequestWithTypeChangeDiff(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -321,8 +321,8 @@ func TestSuccessfulCommitDiffRequestWithTypeChangeDiff(t *testing.T) {
}
func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -435,8 +435,8 @@ func TestSuccessfulCommitDiffRequestWithIgnoreWhitespaceChange(t *testing.T) {
}
func TestSuccessfulCommitDiffRequestWithLimits(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -657,8 +657,8 @@ func TestSuccessfulCommitDiffRequestWithLimits(t *testing.T) {
}
func TestFailedCommitDiffRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -692,8 +692,8 @@ func TestFailedCommitDiffRequestDueToValidationError(t *testing.T) {
}
func TestFailedCommitDiffRequestWithNonExistentCommit(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -717,8 +717,8 @@ func TestFailedCommitDiffRequestWithNonExistentCommit(t *testing.T) {
}
func TestSuccessfulCommitDeltaRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -840,8 +840,8 @@ func TestSuccessfulCommitDeltaRequest(t *testing.T) {
}
func TestSuccessfulCommitDeltaRequestWithPaths(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -909,8 +909,8 @@ func TestSuccessfulCommitDeltaRequestWithPaths(t *testing.T) {
}
func TestFailedCommitDeltaRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -944,8 +944,8 @@ func TestFailedCommitDeltaRequestDueToValidationError(t *testing.T) {
}
func TestFailedCommitDeltaRequestWithNonExistentCommit(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/diff/numstat_test.go b/internal/service/diff/numstat_test.go
index 073e1323c..0a42b37d5 100644
--- a/internal/service/diff/numstat_test.go
+++ b/internal/service/diff/numstat_test.go
@@ -13,8 +13,8 @@ import (
)
func TestSuccessfulDiffStatsRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -128,8 +128,8 @@ func TestSuccessfulDiffStatsRequest(t *testing.T) {
}
func TestFailedDiffStatsRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/diff/raw_test.go b/internal/service/diff/raw_test.go
index 4e3ce322a..71aa8ebfc 100644
--- a/internal/service/diff/raw_test.go
+++ b/internal/service/diff/raw_test.go
@@ -12,8 +12,8 @@ import (
)
func TestSuccessfulRawDiffRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -56,8 +56,8 @@ func TestSuccessfulRawDiffRequest(t *testing.T) {
}
func TestFailedRawDiffRequestDueToValidations(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -111,8 +111,8 @@ func TestFailedRawDiffRequestDueToValidations(t *testing.T) {
}
func TestSuccessfulRawPatchRequest(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
@@ -148,8 +148,8 @@ func TestSuccessfulRawPatchRequest(t *testing.T) {
}
func TestFailedRawPatchRequestDueToValidations(t *testing.T) {
- server, serverSocketPath := runDiffServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runDiffServer(t)
+ defer stop()
client, conn := newDiffClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/diff/testhelper_test.go b/internal/service/diff/testhelper_test.go
index c8bb4219c..098b136c7 100644
--- a/internal/service/diff/testhelper_test.go
+++ b/internal/service/diff/testhelper_test.go
@@ -1,10 +1,10 @@
package diff
import (
- "net"
"os"
"testing"
+ "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
@@ -21,21 +21,15 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func runDiffServer(t *testing.T) (*grpc.Server, string) {
- server := testhelper.NewTestGrpcServer(t, nil, nil)
+func runDiffServer(t *testing.T) (string, func()) {
+ srv := testhelper.NewServer(t, nil, nil)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterDiffServiceServer(server, NewServer())
- reflection.Register(server)
+ gitalypb.RegisterDiffServiceServer(srv.GrpcServer(), NewServer())
+ reflection.Register(srv.GrpcServer())
- go server.Serve(listener)
+ require.NoError(t, srv.Start())
- return server, "unix://" + serverSocketPath
+ return "unix://" + srv.Socket(), srv.Stop
}
func newDiffClient(t *testing.T, serverSocketPath string) (gitalypb.DiffServiceClient, *grpc.ClientConn) {
diff --git a/internal/service/hooks/post_receive_test.go b/internal/service/hooks/post_receive_test.go
index 1dfee6948..a85128967 100644
--- a/internal/service/hooks/post_receive_test.go
+++ b/internal/service/hooks/post_receive_test.go
@@ -18,8 +18,8 @@ import (
)
func TestPostReceiveInvalidArgument(t *testing.T) {
- server, serverSocketPath := runHooksServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runHooksServer(t)
+ defer stop()
client, conn := newHooksClient(t, serverSocketPath)
defer conn.Close()
@@ -45,8 +45,8 @@ func TestPostReceive(t *testing.T) {
require.NoError(t, err)
config.Config.Ruby.Dir = filepath.Join(cwd, "testdata")
- server, serverSocketPath := runHooksServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runHooksServer(t)
+ defer stop()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
diff --git a/internal/service/hooks/pre_receive_test.go b/internal/service/hooks/pre_receive_test.go
index 08af19aee..8b2d5c943 100644
--- a/internal/service/hooks/pre_receive_test.go
+++ b/internal/service/hooks/pre_receive_test.go
@@ -18,8 +18,8 @@ import (
)
func TestPreReceiveInvalidArgument(t *testing.T) {
- server, serverSocketPath := runHooksServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runHooksServer(t)
+ defer stop()
client, conn := newHooksClient(t, serverSocketPath)
defer conn.Close()
@@ -45,8 +45,8 @@ func TestPreReceive(t *testing.T) {
require.NoError(t, err)
config.Config.Ruby.Dir = filepath.Join(cwd, "testdata")
- server, serverSocketPath := runHooksServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runHooksServer(t)
+ defer stop()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
diff --git a/internal/service/hooks/testhelper_test.go b/internal/service/hooks/testhelper_test.go
index 72367ac75..2d72ba16c 100644
--- a/internal/service/hooks/testhelper_test.go
+++ b/internal/service/hooks/testhelper_test.go
@@ -1,12 +1,11 @@
package hook
import (
- "net"
"testing"
+ "github.com/stretchr/testify/require"
gitalyauth "gitlab.com/gitlab-org/gitaly/auth"
"gitlab.com/gitlab-org/gitaly/internal/config"
- "gitlab.com/gitlab-org/gitaly/internal/server/auth"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
@@ -26,22 +25,13 @@ func newHooksClient(t *testing.T, serverSocketPath string) (gitalypb.HookService
return gitalypb.NewHookServiceClient(conn), conn
}
-func runHooksServer(t *testing.T) (*grpc.Server, string) {
- streamInt := []grpc.StreamServerInterceptor{auth.StreamServerInterceptor(config.Config.Auth)}
- unaryInt := []grpc.UnaryServerInterceptor{auth.UnaryServerInterceptor(config.Config.Auth)}
+func runHooksServer(t *testing.T) (string, func()) {
+ srv := testhelper.NewServer(t, nil, nil)
- server := testhelper.NewTestGrpcServer(t, streamInt, unaryInt)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
+ gitalypb.RegisterHookServiceServer(srv.GrpcServer(), NewServer())
+ reflection.Register(srv.GrpcServer())
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterHookServiceServer(server, NewServer())
- reflection.Register(server)
-
- go server.Serve(listener)
+ require.NoError(t, srv.Start())
- return server, "unix://" + serverSocketPath
+ return "unix://" + srv.Socket(), srv.Stop
}
diff --git a/internal/service/hooks/update_test.go b/internal/service/hooks/update_test.go
index 7319be1b6..0a581f4fe 100644
--- a/internal/service/hooks/update_test.go
+++ b/internal/service/hooks/update_test.go
@@ -17,8 +17,8 @@ import (
)
func TestUpdateInvalidArgument(t *testing.T) {
- server, serverSocketPath := runHooksServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runHooksServer(t)
+ defer stop()
client, conn := newHooksClient(t, serverSocketPath)
defer conn.Close()
@@ -43,8 +43,8 @@ func TestUpdate(t *testing.T) {
require.NoError(t, err)
config.Config.Ruby.Dir = filepath.Join(cwd, "testdata")
- server, serverSocketPath := runHooksServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runHooksServer(t)
+ defer stop()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
diff --git a/internal/service/objectpool/alternates_test.go b/internal/service/objectpool/alternates_test.go
index cba9ea7d5..d70d7910c 100644
--- a/internal/service/objectpool/alternates_test.go
+++ b/internal/service/objectpool/alternates_test.go
@@ -14,8 +14,8 @@ import (
)
func TestDisconnectGitAlternates(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -63,8 +63,8 @@ func TestDisconnectGitAlternates(t *testing.T) {
}
func TestDisconnectGitAlternatesNoAlternates(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -86,8 +86,8 @@ func TestDisconnectGitAlternatesNoAlternates(t *testing.T) {
}
func TestDisconnectGitAlternatesUnexpectedAlternates(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/objectpool/create.go b/internal/service/objectpool/create.go
index e0c377403..4affaa1c5 100644
--- a/internal/service/objectpool/create.go
+++ b/internal/service/objectpool/create.go
@@ -4,14 +4,11 @@ import (
"context"
"gitlab.com/gitlab-org/gitaly/internal/git/objectpool"
- "gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
-var errInvalidPoolDir = helper.ErrInvalidArgument(objectpool.ErrInvalidPoolDir)
-
func (s *server) CreateObjectPool(ctx context.Context, in *gitalypb.CreateObjectPoolRequest) (*gitalypb.CreateObjectPoolResponse, error) {
if in.GetOrigin() == nil {
return nil, status.Errorf(codes.InvalidArgument, "no origin repository")
@@ -58,14 +55,5 @@ func poolForRequest(req poolRequest) (*objectpool.ObjectPool, error) {
return nil, status.Errorf(codes.InvalidArgument, "no object pool repository")
}
- pool, err := objectpool.NewObjectPool(poolRepo.GetStorageName(), poolRepo.GetRelativePath())
- if err != nil {
- if err == objectpool.ErrInvalidPoolDir {
- return nil, errInvalidPoolDir
- }
-
- return nil, helper.ErrInternal(err)
- }
-
- return pool, nil
+ return objectpool.NewObjectPool(poolRepo.GetStorageName(), poolRepo.GetRelativePath())
}
diff --git a/internal/service/objectpool/create_test.go b/internal/service/objectpool/create_test.go
index f7a0e971c..3d8ac4ee0 100644
--- a/internal/service/objectpool/create_test.go
+++ b/internal/service/objectpool/create_test.go
@@ -3,8 +3,6 @@ package objectpool
import (
"os"
"path"
- "path/filepath"
- "strings"
"testing"
"github.com/stretchr/testify/assert"
@@ -17,8 +15,8 @@ import (
)
func TestCreate(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -63,8 +61,8 @@ func TestCreate(t *testing.T) {
}
func TestUnsuccessfulCreate(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -75,8 +73,7 @@ func TestUnsuccessfulCreate(t *testing.T) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- validPoolPath := testhelper.NewTestObjectPoolName(t)
- pool, err := objectpool.NewObjectPool("default", validPoolPath)
+ pool, err := objectpool.NewObjectPool("default", testhelper.NewTestObjectPoolName(t))
require.NoError(t, err)
defer pool.Remove(ctx)
@@ -99,45 +96,6 @@ func TestUnsuccessfulCreate(t *testing.T) {
},
code: codes.InvalidArgument,
},
- {
- desc: "outside pools directory",
- request: &gitalypb.CreateObjectPoolRequest{
- Origin: testRepo,
- ObjectPool: &gitalypb.ObjectPool{
- Repository: &gitalypb.Repository{
- StorageName: "default",
- RelativePath: "outside-pools",
- },
- },
- },
- code: codes.InvalidArgument,
- },
- {
- desc: "path must be lowercase",
- request: &gitalypb.CreateObjectPoolRequest{
- Origin: testRepo,
- ObjectPool: &gitalypb.ObjectPool{
- Repository: &gitalypb.Repository{
- StorageName: "default",
- RelativePath: strings.ToUpper(validPoolPath),
- },
- },
- },
- code: codes.InvalidArgument,
- },
- {
- desc: "subdirectories must match first four pool digits",
- request: &gitalypb.CreateObjectPoolRequest{
- Origin: testRepo,
- ObjectPool: &gitalypb.ObjectPool{
- Repository: &gitalypb.Repository{
- StorageName: "default",
- RelativePath: "@pools/aa/bb/ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.git",
- },
- },
- },
- code: codes.InvalidArgument,
- },
}
for _, tc := range testCases {
@@ -148,9 +106,9 @@ func TestUnsuccessfulCreate(t *testing.T) {
}
}
-func TestDelete(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+func TestRemove(t *testing.T) {
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -161,63 +119,18 @@ func TestDelete(t *testing.T) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- validPoolPath := testhelper.NewTestObjectPoolName(t)
- pool, err := objectpool.NewObjectPool("default", validPoolPath)
+ pool, err := objectpool.NewObjectPool("default", testhelper.NewTestObjectPoolName(t))
require.NoError(t, err)
require.NoError(t, pool.Create(ctx, testRepo))
- for _, tc := range []struct {
- desc string
- relativePath string
- error error
- }{
- {
- desc: "deleting outside pools directory fails",
- relativePath: ".",
- error: errInvalidPoolDir,
- },
- {
- desc: "deleting pools directory fails",
- relativePath: "@pools",
- error: errInvalidPoolDir,
- },
- {
- desc: "deleting first level subdirectory fails",
- relativePath: "@pools/ab",
- error: errInvalidPoolDir,
- },
- {
- desc: "deleting second level subdirectory fails",
- relativePath: "@pools/ab/cd",
- error: errInvalidPoolDir,
- },
- {
- desc: "deleting pool subdirectory fails",
- relativePath: filepath.Join(validPoolPath, "objects"),
- error: errInvalidPoolDir,
- },
- {
- desc: "path traversing fails",
- relativePath: validPoolPath + "/../../../../..",
- error: errInvalidPoolDir,
- },
- {
- desc: "deleting pool succeeds",
- relativePath: validPoolPath,
- },
- {
- desc: "deleting non-existent pool succeeds",
- relativePath: validPoolPath,
- },
- } {
- t.Run(tc.desc, func(t *testing.T) {
- _, err := client.DeleteObjectPool(ctx, &gitalypb.DeleteObjectPoolRequest{ObjectPool: &gitalypb.ObjectPool{
- Repository: &gitalypb.Repository{
- StorageName: "default",
- RelativePath: tc.relativePath,
- },
- }})
- require.Equal(t, tc.error, err)
- })
+ req := &gitalypb.DeleteObjectPoolRequest{
+ ObjectPool: pool.ToProto(),
}
+
+ _, err = client.DeleteObjectPool(ctx, req)
+ require.NoError(t, err)
+
+ // Removing again should be possible
+ _, err = client.DeleteObjectPool(ctx, req)
+ require.NoError(t, err)
}
diff --git a/internal/service/objectpool/fetch_into_object_pool_test.go b/internal/service/objectpool/fetch_into_object_pool_test.go
index 5f31a4159..a8262b908 100644
--- a/internal/service/objectpool/fetch_into_object_pool_test.go
+++ b/internal/service/objectpool/fetch_into_object_pool_test.go
@@ -20,8 +20,8 @@ import (
)
func TestFetchIntoObjectPool_Success(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -78,8 +78,8 @@ func TestFetchIntoObjectPool_CollectLogStatistics(t *testing.T) {
defer cancel()
ctx = ctxlogrus.ToContext(ctx, log.WithField("test", "logging"))
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -135,32 +135,28 @@ func TestFetchIntoObjectPool_Failure(t *testing.T) {
description string
request *gitalypb.FetchIntoObjectPoolRequest
code codes.Code
- errMsg string
}{
{
- description: "empty origin",
+ description: "origin and pool do not share the same storage",
request: &gitalypb.FetchIntoObjectPoolRequest{
- ObjectPool: pool.ToProto(),
+ Origin: testRepo,
+ ObjectPool: poolWithDifferentStorage,
},
- code: codes.InvalidArgument,
- errMsg: "origin is empty",
+ code: codes.InvalidArgument,
},
{
- description: "empty pool",
+ description: "empty origin",
request: &gitalypb.FetchIntoObjectPoolRequest{
- Origin: testRepo,
+ ObjectPool: pool.ToProto(),
},
- code: codes.InvalidArgument,
- errMsg: "object pool is empty",
+ code: codes.InvalidArgument,
},
{
- description: "origin and pool do not share the same storage",
+ description: "empty pool",
request: &gitalypb.FetchIntoObjectPoolRequest{
- Origin: testRepo,
- ObjectPool: poolWithDifferentStorage,
+ Origin: testRepo,
},
- code: codes.InvalidArgument,
- errMsg: "origin has different storage than object pool",
+ code: codes.InvalidArgument,
},
}
for _, tc := range testCases {
@@ -168,7 +164,6 @@ func TestFetchIntoObjectPool_Failure(t *testing.T) {
_, err := server.FetchIntoObjectPool(ctx, tc.request)
require.Error(t, err)
testhelper.RequireGrpcError(t, err, tc.code)
- assert.Contains(t, err.Error(), tc.errMsg)
})
}
}
diff --git a/internal/service/objectpool/get_test.go b/internal/service/objectpool/get_test.go
index 392758fd3..3ace93ea4 100644
--- a/internal/service/objectpool/get_test.go
+++ b/internal/service/objectpool/get_test.go
@@ -13,8 +13,8 @@ import (
)
func TestGetObjectPoolSuccess(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -45,8 +45,8 @@ func TestGetObjectPoolSuccess(t *testing.T) {
}
func TestGetObjectPoolNoFile(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -66,8 +66,8 @@ func TestGetObjectPoolNoFile(t *testing.T) {
}
func TestGetObjectPoolBadFile(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/objectpool/link_test.go b/internal/service/objectpool/link_test.go
index 3eafd62dd..1ffec07fe 100644
--- a/internal/service/objectpool/link_test.go
+++ b/internal/service/objectpool/link_test.go
@@ -16,8 +16,8 @@ import (
)
func TestLink(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -89,8 +89,8 @@ func TestLink(t *testing.T) {
}
func TestLinkIdempotent(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -119,8 +119,8 @@ func TestLinkIdempotent(t *testing.T) {
}
func TestLinkNoClobber(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -158,8 +158,8 @@ func TestLinkNoClobber(t *testing.T) {
}
func TestLinkNoPool(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -190,8 +190,8 @@ func TestLinkNoPool(t *testing.T) {
}
func TestUnlink(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
@@ -302,8 +302,8 @@ func TestUnlink(t *testing.T) {
}
func TestUnlinkIdempotent(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/objectpool/reduplicate_test.go b/internal/service/objectpool/reduplicate_test.go
index d1d9f560c..f5250c650 100644
--- a/internal/service/objectpool/reduplicate_test.go
+++ b/internal/service/objectpool/reduplicate_test.go
@@ -12,8 +12,8 @@ import (
)
func TestReduplicate(t *testing.T) {
- server, serverSocketPath := runObjectPoolServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runObjectPoolServer(t)
+ defer stop()
client, conn := newObjectPoolClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/objectpool/testhelper_test.go b/internal/service/objectpool/testhelper_test.go
index 448e3d60d..9e8797df2 100644
--- a/internal/service/objectpool/testhelper_test.go
+++ b/internal/service/objectpool/testhelper_test.go
@@ -1,11 +1,12 @@
package objectpool
import (
- "context"
- "net"
"os"
"testing"
+ "github.com/stretchr/testify/require"
+ gitalyauth "gitlab.com/gitlab-org/gitaly/auth"
+ "gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
@@ -22,30 +23,21 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func runObjectPoolServer(t *testing.T) (*grpc.Server, string) {
- server := testhelper.NewTestGrpcServer(t, nil, nil)
+func runObjectPoolServer(t *testing.T) (string, func()) {
+ srv := testhelper.NewServer(t, nil, nil)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterObjectPoolServiceServer(server, NewServer())
- reflection.Register(server)
+ gitalypb.RegisterObjectPoolServiceServer(srv.GrpcServer(), NewServer())
+ reflection.Register(srv.GrpcServer())
- go server.Serve(listener)
+ require.NoError(t, srv.Start())
- return server, serverSocketPath
+ return "unix://" + srv.Socket(), srv.Stop
}
func newObjectPoolClient(t *testing.T, serverSocketPath string) (gitalypb.ObjectPoolServiceClient, *grpc.ClientConn) {
connOpts := []grpc.DialOption{
grpc.WithInsecure(),
- grpc.WithContextDialer(func(ctx context.Context, addr string) (conn net.Conn, err error) {
- d := net.Dialer{}
- return d.DialContext(ctx, "unix", addr)
- }),
+ grpc.WithPerRPCCredentials(gitalyauth.RPCCredentials(config.Config.Auth.Token)),
}
conn, err := grpc.Dial(serverSocketPath, connOpts...)
diff --git a/internal/service/operations/branches_test.go b/internal/service/operations/branches_test.go
index c377d4a09..db470d537 100644
--- a/internal/service/operations/branches_test.go
+++ b/internal/service/operations/branches_test.go
@@ -19,8 +19,8 @@ func TestSuccessfulUserCreateBranchRequest(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -84,8 +84,8 @@ func TestSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T) {
cleanupSrv := SetupAndStartGitlabServer(t, user.GlId, testRepo.GlRepository)
defer cleanupSrv()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -102,7 +102,7 @@ func TestSuccessfulGitHooksForUserCreateBranchRequest(t *testing.T) {
t.Run(hookName, func(t *testing.T) {
defer exec.Command("git", "-C", testRepoPath, "branch", "-D", branchName).Run()
- hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
+ hookOutputTempPath, cleanup := WriteEnvToCustomHook(t, testRepoPath, hookName)
defer cleanup()
ctx, cancel := testhelper.Context()
@@ -125,8 +125,8 @@ func TestFailedUserCreateBranchDueToHooks(t *testing.T) {
cleanupSrv := SetupAndStartGitlabServer(t, user.GlId, testRepo.GlRepository)
defer cleanupSrv()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -142,7 +142,7 @@ func TestFailedUserCreateBranchDueToHooks(t *testing.T) {
hookContent := []byte("#!/bin/sh\nprintenv | paste -sd ' ' -\nexit 1")
for _, hookName := range gitlabPreHooks {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
@@ -156,8 +156,8 @@ func TestFailedUserCreateBranchDueToHooks(t *testing.T) {
}
func TestFailedUserCreateBranchRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -231,8 +231,8 @@ func TestSuccessfulUserDeleteBranchRequest(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -269,8 +269,8 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -298,7 +298,7 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) {
t.Run(hookName, func(t *testing.T) {
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", branchNameInput)
- hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
+ hookOutputTempPath, cleanup := WriteEnvToCustomHook(t, testRepoPath, hookName)
defer cleanup()
ctx, cancel := testhelper.Context()
@@ -314,8 +314,8 @@ func TestSuccessfulGitHooksForUserDeleteBranchRequest(t *testing.T) {
}
func TestFailedUserDeleteBranchDueToValidation(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -376,8 +376,8 @@ func TestFailedUserDeleteBranchDueToHooks(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -405,7 +405,7 @@ func TestFailedUserDeleteBranchDueToHooks(t *testing.T) {
for _, hookName := range gitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
diff --git a/internal/service/operations/cherry_pick_test.go b/internal/service/operations/cherry_pick_test.go
index 509a28327..fb3a18cf8 100644
--- a/internal/service/operations/cherry_pick_test.go
+++ b/internal/service/operations/cherry_pick_test.go
@@ -165,7 +165,7 @@ func TestSuccessfulGitHooksForUserCherryPickRequest(t *testing.T) {
var hookOutputFiles []string
for _, hookName := range operations.GitlabHooks {
- hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
+ hookOutputTempPath, cleanup := operations.WriteEnvToCustomHook(t, testRepoPath, hookName)
defer cleanup()
hookOutputFiles = append(hookOutputFiles, hookOutputTempPath)
}
@@ -309,7 +309,7 @@ func TestFailedUserCherryPickRequestDueToPreReceiveError(t *testing.T) {
for _, hookName := range operations.GitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := operations.WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
diff --git a/internal/service/operations/commit_files_test.go b/internal/service/operations/commit_files_test.go
index 915312b0a..ad073dfa4 100644
--- a/internal/service/operations/commit_files_test.go
+++ b/internal/service/operations/commit_files_test.go
@@ -434,7 +434,7 @@ func TestFailedUserCommitFilesRequestDueToHooks(t *testing.T) {
for _, hookName := range operations.GitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := operations.WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
diff --git a/internal/service/operations/merge_test.go b/internal/service/operations/merge_test.go
index 51d9e0709..07261ce57 100644
--- a/internal/service/operations/merge_test.go
+++ b/internal/service/operations/merge_test.go
@@ -35,8 +35,8 @@ func TestSuccessfulMerge(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -50,7 +50,7 @@ func TestSuccessfulMerge(t *testing.T) {
hookTempfiles := make([]string, len(hooks))
for i, h := range hooks {
var cleanup func()
- hookTempfiles[i], cleanup = testhelper.WriteEnvToCustomHook(t, testRepoPath, h)
+ hookTempfiles[i], cleanup = WriteEnvToCustomHook(t, testRepoPath, h)
defer cleanup()
}
@@ -111,8 +111,8 @@ func TestAbortedMerge(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -182,8 +182,8 @@ func TestFailedMergeConcurrentUpdate(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -226,8 +226,8 @@ func TestFailedMergeDueToHooks(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -241,7 +241,7 @@ func TestFailedMergeDueToHooks(t *testing.T) {
for _, hookName := range gitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
@@ -288,8 +288,8 @@ func TestSuccessfulUserFFBranchRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -327,8 +327,8 @@ func TestSuccessfulUserFFBranchRequest(t *testing.T) {
}
func TestFailedUserFFBranchRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -422,8 +422,8 @@ func TestFailedUserFFBranchRequest(t *testing.T) {
}
func TestFailedUserFFBranchDueToHooks(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -450,7 +450,7 @@ func TestFailedUserFFBranchDueToHooks(t *testing.T) {
for _, hookName := range gitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
@@ -465,8 +465,8 @@ func TestFailedUserFFBranchDueToHooks(t *testing.T) {
}
func TestSuccessfulUserMergeToRefRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -574,8 +574,8 @@ func TestSuccessfulUserMergeToRefRequest(t *testing.T) {
}
func TestFailedUserMergeToRefRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -676,8 +676,8 @@ func TestFailedUserMergeToRefRequest(t *testing.T) {
}
func TestUserMergeToRefIgnoreHooksRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -703,7 +703,7 @@ func TestUserMergeToRefIgnoreHooksRequest(t *testing.T) {
for _, hookName := range gitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
diff --git a/internal/service/operations/rebase_test.go b/internal/service/operations/rebase_test.go
index 228284530..7d1a75677 100644
--- a/internal/service/operations/rebase_test.go
+++ b/internal/service/operations/rebase_test.go
@@ -57,8 +57,8 @@ func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) {
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
- preReceiveHookOutputPath, removePreReceive := testhelper.WriteEnvToCustomHook(t, testRepoPath, "pre-receive")
- postReceiveHookOutputPath, removePostReceive := testhelper.WriteEnvToCustomHook(t, testRepoPath, "post-receive")
+ preReceiveHookOutputPath, removePreReceive := operations.WriteEnvToCustomHook(t, testRepoPath, "pre-receive")
+ postReceiveHookOutputPath, removePostReceive := operations.WriteEnvToCustomHook(t, testRepoPath, "post-receive")
defer removePreReceive()
defer removePostReceive()
@@ -317,7 +317,7 @@ func TestFailedUserRebaseConfirmableRequestDueToPreReceiveError(t *testing.T) {
for i, hookName := range operations.GitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := operations.WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err, "set up hooks override")
defer remove()
diff --git a/internal/service/operations/revert_test.go b/internal/service/operations/revert_test.go
index f4494e161..716e8f1b3 100644
--- a/internal/service/operations/revert_test.go
+++ b/internal/service/operations/revert_test.go
@@ -163,7 +163,7 @@ func TestSuccessfulGitHooksForUserRevertRequest(t *testing.T) {
var hookOutputFiles []string
for _, hookName := range operations.GitlabHooks {
- hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
+ hookOutputTempPath, cleanup := operations.WriteEnvToCustomHook(t, testRepoPath, hookName)
defer cleanup()
hookOutputFiles = append(hookOutputFiles, hookOutputTempPath)
}
@@ -307,7 +307,7 @@ func TestFailedUserRevertRequestDueToPreReceiveError(t *testing.T) {
for _, hookName := range operations.GitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := operations.WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
diff --git a/internal/service/operations/squash_test.go b/internal/service/operations/squash_test.go
index 7115f7977..a7ca7752d 100644
--- a/internal/service/operations/squash_test.go
+++ b/internal/service/operations/squash_test.go
@@ -30,8 +30,8 @@ func TestSuccessfulUserSquashRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -80,8 +80,8 @@ func TestSuccessfulUserSquashRequestWith3wayMerge(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -128,8 +128,8 @@ func TestSplitIndex(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -159,8 +159,8 @@ func TestSquashRequestWithRenamedFiles(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -221,8 +221,8 @@ func TestSuccessfulUserSquashRequestWithMissingFileOnTargetBranch(t *testing.T)
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -248,8 +248,8 @@ func TestSuccessfulUserSquashRequestWithMissingFileOnTargetBranch(t *testing.T)
}
func TestFailedUserSquashRequestDueToValidations(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/operations/submodules_test.go b/internal/service/operations/submodules_test.go
index 71e81b13f..d85632567 100644
--- a/internal/service/operations/submodules_test.go
+++ b/internal/service/operations/submodules_test.go
@@ -14,8 +14,8 @@ import (
)
func TestSuccessfulUserUpdateSubmoduleRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -84,8 +84,8 @@ func TestSuccessfulUserUpdateSubmoduleRequest(t *testing.T) {
}
func TestFailedUserUpdateSubmoduleRequestDueToValidations(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -212,8 +212,8 @@ func TestFailedUserUpdateSubmoduleRequestDueToInvalidBranch(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -239,8 +239,8 @@ func TestFailedUserUpdateSubmoduleRequestDueToInvalidSubmodule(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -266,8 +266,8 @@ func TestFailedUserUpdateSubmoduleRequestDueToSameReference(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -299,8 +299,8 @@ func TestFailedUserUpdateSubmoduleRequestDueToRepositoryEmpty(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := NewOperationClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/operations/tags_test.go b/internal/service/operations/tags_test.go
index ec47dad02..b27e0e455 100644
--- a/internal/service/operations/tags_test.go
+++ b/internal/service/operations/tags_test.go
@@ -16,8 +16,8 @@ func TestSuccessfulUserDeleteTagRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -54,8 +54,8 @@ func TestSuccessfulUserDeleteTagRequest(t *testing.T) {
}
func TestSuccessfulGitHooksForUserDeleteTagRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -86,7 +86,7 @@ func TestSuccessfulGitHooksForUserDeleteTagRequest(t *testing.T) {
t.Run(hookName, func(t *testing.T) {
testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", tagNameInput)
- hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
+ hookOutputTempPath, cleanup := WriteEnvToCustomHook(t, testRepoPath, hookName)
defer cleanup()
ctx, cancel := testhelper.Context()
@@ -105,8 +105,8 @@ func TestSuccessfulUserCreateTagRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -188,8 +188,8 @@ func TestSuccessfulUserCreateTagRequest(t *testing.T) {
}
func TestSuccessfulGitHooksForUserCreateTagRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -219,7 +219,7 @@ func TestSuccessfulGitHooksForUserCreateTagRequest(t *testing.T) {
t.Run(hookName, func(t *testing.T) {
defer exec.Command("git", "-C", testRepoPath, "tag", "-d", tagName).Run()
- hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
+ hookOutputTempPath, cleanup := WriteEnvToCustomHook(t, testRepoPath, hookName)
defer cleanup()
ctx, cancel := testhelper.Context()
@@ -236,8 +236,8 @@ func TestSuccessfulGitHooksForUserCreateTagRequest(t *testing.T) {
}
func TestFailedUserDeleteTagRequestDueToValidation(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -295,8 +295,8 @@ func TestFailedUserDeleteTagRequestDueToValidation(t *testing.T) {
}
func TestFailedUserDeleteTagDueToHooks(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -327,7 +327,7 @@ func TestFailedUserDeleteTagDueToHooks(t *testing.T) {
for _, hookName := range gitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
@@ -345,8 +345,8 @@ func TestFailedUserDeleteTagDueToHooks(t *testing.T) {
}
func TestFailedUserCreateTagDueToHooks(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -374,7 +374,7 @@ func TestFailedUserCreateTagDueToHooks(t *testing.T) {
hookContent := []byte("#!/bin/sh\necho GL_ID=$GL_ID\nexit 1")
for _, hookName := range gitlabPreHooks {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
@@ -388,8 +388,8 @@ func TestFailedUserCreateTagDueToHooks(t *testing.T) {
}
func TestFailedUserCreateTagRequestDueToTagExistence(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -432,8 +432,8 @@ func TestFailedUserCreateTagRequestDueToTagExistence(t *testing.T) {
}
func TestFailedUserCreateTagRequestDueToValidation(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/operations/testhelper_test.go b/internal/service/operations/testhelper_test.go
index 56d48ab56..dbee4f7a7 100644
--- a/internal/service/operations/testhelper_test.go
+++ b/internal/service/operations/testhelper_test.go
@@ -1,12 +1,14 @@
package operations
import (
- "net"
+ "fmt"
+ "io/ioutil"
"os"
"path/filepath"
"testing"
log "github.com/sirupsen/logrus"
+ "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -64,21 +66,15 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func runOperationServiceServer(t *testing.T) (*grpc.Server, string) {
- grpcServer := testhelper.NewTestGrpcServer(t, nil, nil)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
+func runOperationServiceServer(t *testing.T) (string, func()) {
+ srv := testhelper.NewServer(t, nil, nil)
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterOperationServiceServer(grpcServer, &server{ruby: RubyServer})
- reflection.Register(grpcServer)
+ gitalypb.RegisterOperationServiceServer(srv.GrpcServer(), &server{ruby: RubyServer})
+ reflection.Register(srv.GrpcServer())
- go grpcServer.Serve(listener)
+ require.NoError(t, srv.Start())
- return grpcServer, "unix://" + serverSocketPath
+ return "unix://" + srv.Socket(), srv.Stop
}
func newOperationClient(t *testing.T, serverSocketPath string) (gitalypb.OperationServiceClient, *grpc.ClientConn) {
@@ -95,6 +91,37 @@ func newOperationClient(t *testing.T, serverSocketPath string) (gitalypb.Operati
var NewOperationClient = newOperationClient
+// The callee is responsible for clean up of the specific hook, testMain removes
+// the hook dir
+func WriteEnvToCustomHook(t *testing.T, repoPath, hookName string) (string, func()) {
+ hookOutputTemp, err := ioutil.TempFile("", "")
+ require.NoError(t, err)
+ require.NoError(t, hookOutputTemp.Close())
+
+ hookContent := fmt.Sprintf("#!/bin/sh\n/usr/bin/env > %s\n", hookOutputTemp.Name())
+
+ cleanupCustomHook, err := WriteCustomHook(repoPath, hookName, []byte(hookContent))
+ require.NoError(t, err)
+
+ return hookOutputTemp.Name(), func() {
+ cleanupCustomHook()
+ os.Remove(hookOutputTemp.Name())
+ }
+}
+
+// write a hook in the repo/path.git/custom_hooks directory
+func WriteCustomHook(repoPath, name string, content []byte) (func(), error) {
+ fullPath := filepath.Join(repoPath, "custom_hooks", name)
+ fullpathDir := filepath.Dir(fullPath)
+ if err := os.MkdirAll(fullpathDir, 0755); err != nil {
+ return func() {}, err
+ }
+
+ return func() {
+ os.RemoveAll(fullpathDir)
+ }, ioutil.WriteFile(fullPath, content, 0755)
+}
+
func SetupAndStartGitlabServer(t *testing.T, glID, glRepository string, gitPushOptions ...string) func() {
return testhelper.SetupAndStartGitlabServer(t, &testhelper.GitlabTestServerOptions{
SecretToken: "secretToken",
diff --git a/internal/service/operations/update_branches_test.go b/internal/service/operations/update_branches_test.go
index 44f9427de..139276128 100644
--- a/internal/service/operations/update_branches_test.go
+++ b/internal/service/operations/update_branches_test.go
@@ -29,8 +29,8 @@ func TestSuccessfulUserUpdateBranchRequest(t *testing.T) {
cleanupSrv := SetupAndStartGitlabServer(t, user.GlId, testRepo.GlRepository)
defer cleanupSrv()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -55,8 +55,8 @@ func TestSuccessfulUserUpdateBranchRequest(t *testing.T) {
}
func TestSuccessfulGitHooksForUserUpdateBranchRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -69,7 +69,7 @@ func TestSuccessfulGitHooksForUserUpdateBranchRequest(t *testing.T) {
cleanupSrv := SetupAndStartGitlabServer(t, user.GlId, testRepo.GlRepository)
defer cleanupSrv()
- hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
+ hookOutputTempPath, cleanup := WriteEnvToCustomHook(t, testRepoPath, hookName)
defer cleanup()
ctx, cancel := testhelper.Context()
@@ -100,8 +100,8 @@ func TestFailedUserUpdateBranchDueToHooks(t *testing.T) {
cleanupSrv := SetupAndStartGitlabServer(t, user.GlId, testRepo.GlRepository)
defer cleanupSrv()
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
@@ -118,7 +118,7 @@ func TestFailedUserUpdateBranchDueToHooks(t *testing.T) {
hookContent := []byte("#!/bin/sh\nprintenv | paste -sd ' ' -\nexit 1")
for _, hookName := range gitlabPreHooks {
- remove, err := testhelper.WriteCustomHook(testRepoPath, hookName, hookContent)
+ remove, err := WriteCustomHook(testRepoPath, hookName, hookContent)
require.NoError(t, err)
defer remove()
@@ -133,8 +133,8 @@ func TestFailedUserUpdateBranchDueToHooks(t *testing.T) {
}
func TestFailedUserUpdateBranchRequest(t *testing.T) {
- server, serverSocketPath := runOperationServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/branches_test.go b/internal/service/ref/branches_test.go
index b0f6147af..354cbdf14 100644
--- a/internal/service/ref/branches_test.go
+++ b/internal/service/ref/branches_test.go
@@ -15,8 +15,8 @@ func TestSuccessfulFindBranchRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -78,8 +78,8 @@ func TestSuccessfulFindBranchRequest(t *testing.T) {
}
func TestFailedFindBranchRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/delete_refs_test.go b/internal/service/ref/delete_refs_test.go
index 3c4faab6f..73a88f7fc 100644
--- a/internal/service/ref/delete_refs_test.go
+++ b/internal/service/ref/delete_refs_test.go
@@ -11,8 +11,8 @@ import (
)
func TestSuccessfulDeleteRefs(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -64,8 +64,8 @@ func TestSuccessfulDeleteRefs(t *testing.T) {
}
func TestFailedDeleteRefsRequestDueToGitError(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -88,8 +88,8 @@ func TestFailedDeleteRefsRequestDueToGitError(t *testing.T) {
}
func TestFailedDeleteRefsDueToValidation(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/list_new_blobs_test.go b/internal/service/ref/list_new_blobs_test.go
index 568053862..6e16e8c5d 100644
--- a/internal/service/ref/list_new_blobs_test.go
+++ b/internal/service/ref/list_new_blobs_test.go
@@ -15,8 +15,8 @@ func TestListNewBlobs(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/list_new_commits_test.go b/internal/service/ref/list_new_commits_test.go
index f0b5cdffc..a75ed8c68 100644
--- a/internal/service/ref/list_new_commits_test.go
+++ b/internal/service/ref/list_new_commits_test.go
@@ -15,8 +15,8 @@ func TestListNewCommits(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/pack_refs_test.go b/internal/service/ref/pack_refs_test.go
index ad479415e..6eff598fe 100644
--- a/internal/service/ref/pack_refs_test.go
+++ b/internal/service/ref/pack_refs_test.go
@@ -19,8 +19,8 @@ func TestPackRefsSuccessfulRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/refexists_test.go b/internal/service/ref/refexists_test.go
index 2998461f8..557699fda 100644
--- a/internal/service/ref/refexists_test.go
+++ b/internal/service/ref/refexists_test.go
@@ -41,8 +41,8 @@ func TestRefExists(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/refname_test.go b/internal/service/ref/refname_test.go
index cdc5a61a9..d69df4b9d 100644
--- a/internal/service/ref/refname_test.go
+++ b/internal/service/ref/refname_test.go
@@ -13,8 +13,8 @@ import (
)
func TestFindRefNameSuccess(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -43,8 +43,8 @@ func TestFindRefNameSuccess(t *testing.T) {
}
func TestFindRefNameEmptyCommit(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -75,8 +75,8 @@ func TestFindRefNameEmptyCommit(t *testing.T) {
}
func TestFindRefNameInvalidRepo(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -104,8 +104,8 @@ func TestFindRefNameInvalidRepo(t *testing.T) {
}
func TestFindRefNameInvalidPrefix(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -131,8 +131,8 @@ func TestFindRefNameInvalidPrefix(t *testing.T) {
}
func TestFindRefNameInvalidObject(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/refs_test.go b/internal/service/ref/refs_test.go
index ae14a2054..c71efba88 100644
--- a/internal/service/ref/refs_test.go
+++ b/internal/service/ref/refs_test.go
@@ -32,8 +32,8 @@ func containsRef(refs [][]byte, ref string) bool {
}
func TestSuccessfulFindAllBranchNames(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -68,8 +68,8 @@ func TestSuccessfulFindAllBranchNames(t *testing.T) {
}
func TestFindAllBranchNamesVeryLargeResponse(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -124,8 +124,8 @@ func TestFindAllBranchNamesVeryLargeResponse(t *testing.T) {
}
func TestEmptyFindAllBranchNamesRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -149,8 +149,8 @@ func TestEmptyFindAllBranchNamesRequest(t *testing.T) {
}
func TestInvalidRepoFindAllBranchNamesRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -175,8 +175,8 @@ func TestInvalidRepoFindAllBranchNamesRequest(t *testing.T) {
}
func TestSuccessfulFindAllTagNames(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -213,8 +213,8 @@ func TestSuccessfulFindAllTagNames(t *testing.T) {
}
func TestEmptyFindAllTagNamesRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -238,8 +238,8 @@ func TestEmptyFindAllTagNamesRequest(t *testing.T) {
}
func TestInvalidRepoFindAllTagNamesRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -374,8 +374,8 @@ func TestDefaultBranchName(t *testing.T) {
}
func TestSuccessfulFindDefaultBranchName(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -398,8 +398,8 @@ func TestSuccessfulFindDefaultBranchName(t *testing.T) {
}
func TestEmptyFindDefaultBranchNameRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -415,8 +415,8 @@ func TestEmptyFindDefaultBranchNameRequest(t *testing.T) {
}
func TestInvalidRepoFindDefaultBranchNameRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -433,8 +433,8 @@ func TestInvalidRepoFindDefaultBranchNameRequest(t *testing.T) {
}
func TestSuccessfulFindAllTagsRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
testRepoCopy, testRepoCopyPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
defer cleanupFn()
@@ -671,8 +671,8 @@ func TestSuccessfulFindAllTagsRequest(t *testing.T) {
}
func TestFindAllTagNestedTags(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
testRepoCopy, testRepoCopyPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
defer cleanupFn()
@@ -779,8 +779,8 @@ func TestFindAllTagNestedTags(t *testing.T) {
}
func TestInvalidFindAllTagsRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -823,8 +823,8 @@ func TestInvalidFindAllTagsRequest(t *testing.T) {
}
func TestSuccessfulFindLocalBranches(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -916,8 +916,8 @@ func TestFindLocalBranchesSort(t *testing.T) {
},
}
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -958,8 +958,8 @@ func TestFindLocalBranchesSort(t *testing.T) {
}
func TestEmptyFindLocalBranchesRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -983,8 +983,8 @@ func TestEmptyFindLocalBranchesRequest(t *testing.T) {
}
func TestSuccessfulFindAllBranchesRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
remoteBranch := &gitalypb.FindAllBranchesResponse_Branch{
Name: []byte("refs/remotes/origin/fake-remote-branch"),
@@ -1042,8 +1042,8 @@ func TestSuccessfulFindAllBranchesRequest(t *testing.T) {
}
func TestSuccessfulFindAllBranchesRequestWithMergedBranches(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
@@ -1135,8 +1135,8 @@ func TestSuccessfulFindAllBranchesRequestWithMergedBranches(t *testing.T) {
}
func TestInvalidFindAllBranchesRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -1193,8 +1193,8 @@ func readFindAllBranchesResponsesFromClient(t *testing.T, c gitalypb.RefService_
}
func TestListTagNamesContainingCommit(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -1270,8 +1270,8 @@ func TestListTagNamesContainingCommit(t *testing.T) {
}
func TestListBranchNamesContainingCommit(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -1364,8 +1364,8 @@ func TestListBranchNamesContainingCommit(t *testing.T) {
}
func TestSuccessfulFindTagRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
testRepoCopy, testRepoCopyPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
defer cleanupFn()
@@ -1591,8 +1591,8 @@ func TestSuccessfulFindTagRequest(t *testing.T) {
}
func TestFindTagNestedTag(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
testRepoCopy, testRepoCopyPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
defer cleanupFn()
@@ -1680,8 +1680,8 @@ func TestFindTagNestedTag(t *testing.T) {
}
func TestInvalidFindTagRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/remote_branches_test.go b/internal/service/ref/remote_branches_test.go
index 2fd0c78ab..f62a5f5bb 100644
--- a/internal/service/ref/remote_branches_test.go
+++ b/internal/service/ref/remote_branches_test.go
@@ -16,8 +16,8 @@ func TestSuccessfulFindAllRemoteBranchesRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -79,8 +79,8 @@ func TestSuccessfulFindAllRemoteBranchesRequest(t *testing.T) {
}
func TestInvalidFindAllRemoteBranchesRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/tag_messages_test.go b/internal/service/ref/tag_messages_test.go
index fbd8ebac0..8c512c912 100644
--- a/internal/service/ref/tag_messages_test.go
+++ b/internal/service/ref/tag_messages_test.go
@@ -13,8 +13,8 @@ import (
)
func TestSuccessfulGetTagMessagesRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -55,8 +55,8 @@ func TestSuccessfulGetTagMessagesRequest(t *testing.T) {
}
func TestFailedGetTagMessagesRequest(t *testing.T) {
- server, serverSocketPath := runRefServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runRefServiceServer(t)
+ defer stop()
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/ref/testhelper_test.go b/internal/service/ref/testhelper_test.go
index 2faeb3d0e..0dd3b9018 100644
--- a/internal/service/ref/testhelper_test.go
+++ b/internal/service/ref/testhelper_test.go
@@ -2,7 +2,6 @@ package ref
import (
"bytes"
- "net"
"os"
"testing"
@@ -92,21 +91,15 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func runRefServiceServer(t *testing.T) (*grpc.Server, string) {
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
- grpcServer := testhelper.NewTestGrpcServer(t, nil, nil)
+func runRefServiceServer(t *testing.T) (func(), string) {
+ srv := testhelper.NewServer(t, nil, nil)
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterRefServiceServer(grpcServer, &server{})
- reflection.Register(grpcServer)
+ gitalypb.RegisterRefServiceServer(srv.GrpcServer(), &server{})
+ reflection.Register(srv.GrpcServer())
- go grpcServer.Serve(listener)
+ require.NoError(t, srv.Start())
- return grpcServer, "unix://" + serverSocketPath
+ return srv.Stop, "unix://" + srv.Socket()
}
func newRefServiceClient(t *testing.T, serverSocketPath string) (gitalypb.RefServiceClient, *grpc.ClientConn) {
diff --git a/internal/service/remote/find_remote_root_ref_test.go b/internal/service/remote/find_remote_root_ref_test.go
index a8c418abb..b26037ea5 100644
--- a/internal/service/remote/find_remote_root_ref_test.go
+++ b/internal/service/remote/find_remote_root_ref_test.go
@@ -10,8 +10,8 @@ import (
)
func TestFindRemoteRootRefSuccess(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -29,8 +29,8 @@ func TestFindRemoteRootRefSuccess(t *testing.T) {
}
func TestFindRemoteRootRefFailedDueToValidation(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -77,8 +77,8 @@ func TestFindRemoteRootRefFailedDueToValidation(t *testing.T) {
}
func TestFindRemoteRootRefFailedDueToInvalidRemote(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/remote/remotes_test.go b/internal/service/remote/remotes_test.go
index 763be1211..da16e0759 100644
--- a/internal/service/remote/remotes_test.go
+++ b/internal/service/remote/remotes_test.go
@@ -16,8 +16,8 @@ import (
)
func TestSuccessfulAddRemote(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -100,8 +100,8 @@ func TestSuccessfulAddRemote(t *testing.T) {
}
func TestFailedAddRemoteDueToValidation(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -147,8 +147,8 @@ func TestFailedAddRemoteDueToValidation(t *testing.T) {
}
func TestSuccessfulRemoveRemote(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -197,8 +197,8 @@ func TestSuccessfulRemoveRemote(t *testing.T) {
}
func TestFailedRemoveRemoteDueToValidation(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -216,8 +216,8 @@ func TestFailedRemoveRemoteDueToValidation(t *testing.T) {
}
func TestFindRemoteRepository(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -239,8 +239,8 @@ func TestFindRemoteRepository(t *testing.T) {
}
func TestFailedFindRemoteRepository(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -272,8 +272,8 @@ func TestFailedFindRemoteRepository(t *testing.T) {
}
func TestListDifferentPushUrlRemote(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -319,8 +319,8 @@ func TestListDifferentPushUrlRemote(t *testing.T) {
}
func TestListRemotes(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/remote/testhelper_test.go b/internal/service/remote/testhelper_test.go
index 481be3f97..36601f71c 100644
--- a/internal/service/remote/testhelper_test.go
+++ b/internal/service/remote/testhelper_test.go
@@ -2,10 +2,10 @@ package remote
import (
"log"
- "net"
"os"
"testing"
+ "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -32,21 +32,15 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func runRemoteServiceServer(t *testing.T) (*grpc.Server, string) {
- grpcServer := testhelper.NewTestGrpcServer(t, nil, nil)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
+func runRemoteServiceServer(t *testing.T) (string, func()) {
+ srv := testhelper.NewServer(t, nil, nil)
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterRemoteServiceServer(grpcServer, &server{ruby: RubyServer})
- reflection.Register(grpcServer)
+ gitalypb.RegisterRemoteServiceServer(srv.GrpcServer(), &server{ruby: RubyServer})
+ reflection.Register(srv.GrpcServer())
- go grpcServer.Serve(listener)
+ require.NoError(t, srv.Start())
- return grpcServer, "unix://" + serverSocketPath
+ return "unix://" + srv.Socket(), srv.Stop
}
func NewRemoteClient(t *testing.T, serverSocketPath string) (gitalypb.RemoteServiceClient, *grpc.ClientConn) {
diff --git a/internal/service/remote/update_remote_mirror_test.go b/internal/service/remote/update_remote_mirror_test.go
index 87e51eb8c..01da8db32 100644
--- a/internal/service/remote/update_remote_mirror_test.go
+++ b/internal/service/remote/update_remote_mirror_test.go
@@ -12,8 +12,8 @@ import (
)
func TestSuccessfulUpdateRemoteMirrorRequest(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -96,8 +96,8 @@ func TestSuccessfulUpdateRemoteMirrorRequest(t *testing.T) {
}
func TestSuccessfulUpdateRemoteMirrorRequestWithWildcards(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -173,8 +173,8 @@ func TestSuccessfulUpdateRemoteMirrorRequestWithWildcards(t *testing.T) {
}
func TestSuccessfulUpdateRemoteMirrorRequestWithKeepDivergentRefs(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
@@ -229,8 +229,8 @@ func TestSuccessfulUpdateRemoteMirrorRequestWithKeepDivergentRefs(t *testing.T)
}
func TestFailedUpdateRemoteMirrorRequestDueToValidation(t *testing.T) {
- server, serverSocketPath := runRemoteServiceServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runRemoteServiceServer(t)
+ defer stop()
client, conn := NewRemoteClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/smarthttp/inforefs.go b/internal/service/smarthttp/inforefs.go
index 1d3fe52f9..e56745824 100644
--- a/internal/service/smarthttp/inforefs.go
+++ b/internal/service/smarthttp/inforefs.go
@@ -10,7 +10,6 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/pktline"
"gitlab.com/gitlab-org/gitaly/internal/helper"
- "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/streamio"
"google.golang.org/grpc/codes"
@@ -55,11 +54,6 @@ func handleInfoRefs(ctx context.Context, service string, req *gitalypb.InfoRefsR
if service == "receive-pack" {
globalOpts = append(globalOpts, git.ReceivePackConfig()...)
}
-
- if service == "upload-pack" && featureflag.IsEnabled(ctx, featureflag.UploadPackFilter) {
- globalOpts = append(globalOpts, git.UploadPackFilterConfig()...)
- }
-
for _, o := range req.GitConfigOptions {
globalOpts = append(globalOpts, git.ValueFlag{"-c", o})
}
diff --git a/internal/service/smarthttp/inforefs_test.go b/internal/service/smarthttp/inforefs_test.go
index 46935e9ee..adf1c3b32 100644
--- a/internal/service/smarthttp/inforefs_test.go
+++ b/internal/service/smarthttp/inforefs_test.go
@@ -1,7 +1,6 @@
package smarthttp
import (
- "bytes"
"context"
"fmt"
"io"
@@ -16,7 +15,6 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/objectpool"
- "gitlab.com/gitlab-org/gitaly/internal/git/stats"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/internal/tempdir"
@@ -28,8 +26,8 @@ import (
)
func TestSuccessfulInfoRefsUploadPack(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
@@ -44,44 +42,9 @@ func TestSuccessfulInfoRefsUploadPack(t *testing.T) {
})
}
-func TestSuccessfulInfoRefsUploadWithPartialClone(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
-
- ctx, cancel := testhelper.Context()
- defer cancel()
-
- testRepo := testhelper.TestRepository()
-
- request := &gitalypb.InfoRefsRequest{
- Repository: testRepo,
- }
-
- fullResponse, err := makeInfoRefsUploadPackRequest(ctx, t, serverSocketPath, request)
- require.NoError(t, err)
- fullRefs := stats.Get{}
- err = fullRefs.Parse(bytes.NewReader(fullResponse))
- require.NoError(t, err)
-
- ctx = featureflag.OutgoingCtxWithFeatureFlag(ctx, featureflag.UploadPackFilter)
-
- partialResponse, err := makeInfoRefsUploadPackRequest(ctx, t, serverSocketPath, request)
- require.NoError(t, err)
- partialRefs := stats.Get{}
- err = partialRefs.Parse(bytes.NewReader(partialResponse))
- require.NoError(t, err)
-
- require.Equal(t, fullRefs.Refs(), partialRefs.Refs())
-
- for _, c := range []string{"allow-tip-sha1-in-want", "allow-reachable-sha1-in-want", "filter"} {
- require.Contains(t, partialRefs.Caps(), c)
- require.NotContains(t, fullRefs.Caps(), c)
- }
-}
-
func TestSuccessfulInfoRefsUploadPackWithGitConfigOptions(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
@@ -102,8 +65,8 @@ func TestSuccessfulInfoRefsUploadPackWithGitProtocol(t *testing.T) {
restore := testhelper.EnableGitProtocolV2Support()
defer restore()
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
@@ -153,8 +116,8 @@ func makeInfoRefsUploadPackRequest(ctx context.Context, t *testing.T, serverSock
}
func TestSuccessfulInfoRefsReceivePack(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
client, conn := newSmartHTTPClient(t, serverSocketPath)
defer conn.Close()
@@ -186,8 +149,8 @@ func TestSuccessfulInfoRefsReceivePack(t *testing.T) {
}
func TestObjectPoolRefAdvertisementHiding(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
client, conn := newSmartHTTPClient(t, serverSocketPath)
defer conn.Close()
@@ -223,8 +186,8 @@ func TestObjectPoolRefAdvertisementHiding(t *testing.T) {
}
func TestFailureRepoNotFoundInfoRefsReceivePack(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
client, conn := newSmartHTTPClient(t, serverSocketPath)
defer conn.Close()
@@ -245,8 +208,8 @@ func TestFailureRepoNotFoundInfoRefsReceivePack(t *testing.T) {
}
func TestFailureRepoNotSetInfoRefsReceivePack(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
client, conn := newSmartHTTPClient(t, serverSocketPath)
defer conn.Close()
@@ -287,8 +250,8 @@ func assertGitRefAdvertisement(t *testing.T, rpc, responseBody string, firstLine
func TestCacheInfoRefsUploadPack(t *testing.T) {
clearCache(t)
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
diff --git a/internal/service/smarthttp/receive_pack_test.go b/internal/service/smarthttp/receive_pack_test.go
index f1074ef06..bd34823fe 100644
--- a/internal/service/smarthttp/receive_pack_test.go
+++ b/internal/service/smarthttp/receive_pack_test.go
@@ -31,8 +31,8 @@ func TestSuccessfulReceivePackRequest(t *testing.T) {
hookOutputFile, cleanup := testhelper.CaptureHookEnv(t)
defer cleanup()
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
repo, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
@@ -73,8 +73,8 @@ func TestSuccessfulReceivePackRequestWithGitProtocol(t *testing.T) {
restore := testhelper.EnableGitProtocolV2Support()
defer restore()
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
repo, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
@@ -102,8 +102,8 @@ func TestSuccessfulReceivePackRequestWithGitProtocol(t *testing.T) {
}
func TestFailedReceivePackRequestWithGitOpts(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
repo, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
@@ -138,8 +138,8 @@ func TestFailedReceivePackRequestDueToHooksFailure(t *testing.T) {
hookContent := []byte("#!/bin/sh\nexit 1")
ioutil.WriteFile(path.Join(hooks.Path(), "pre-receive"), hookContent, 0755)
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
repo, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
@@ -244,8 +244,8 @@ func createCommit(t *testing.T, repoPath string, fileContents []byte) (oldHead s
}
func TestFailedReceivePackRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
client, conn := newSmartHTTPClient(t, serverSocketPath)
defer conn.Close()
@@ -278,8 +278,8 @@ func TestPostReceivePackToHooks(t *testing.T) {
glRepository := "some_repo"
glID := "key-123"
- server, socket := runSmartHTTPServer(t)
- defer server.Stop()
+ socket, stop := runSmartHTTPServer(t)
+ defer stop()
client, conn := newSmartHTTPClient(t, "unix://"+socket)
defer conn.Close()
diff --git a/internal/service/smarthttp/testhelper_test.go b/internal/service/smarthttp/testhelper_test.go
index ed5eff8d3..aef5803ce 100644
--- a/internal/service/smarthttp/testhelper_test.go
+++ b/internal/service/smarthttp/testhelper_test.go
@@ -1,10 +1,10 @@
package smarthttp
import (
- "net"
"os"
"testing"
+ "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git/hooks"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -28,21 +28,15 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func runSmartHTTPServer(t *testing.T) (*grpc.Server, string) {
- server := testhelper.NewTestGrpcServer(t, nil, nil)
+func runSmartHTTPServer(t *testing.T) (string, func()) {
+ srv := testhelper.NewServer(t, nil, nil)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterSmartHTTPServiceServer(server, NewServer())
- reflection.Register(server)
+ gitalypb.RegisterSmartHTTPServiceServer(srv.GrpcServer(), NewServer())
+ reflection.Register(srv.GrpcServer())
- go server.Serve(listener)
+ require.NoError(t, srv.Start())
- return server, "unix://" + serverSocketPath
+ return "unix://" + srv.Socket(), srv.Stop
}
func newSmartHTTPClient(t *testing.T, serverSocketPath string) (gitalypb.SmartHTTPServiceClient, *grpc.ClientConn) {
diff --git a/internal/service/smarthttp/upload_pack.go b/internal/service/smarthttp/upload_pack.go
index 7ed467281..6d20eb0cd 100644
--- a/internal/service/smarthttp/upload_pack.go
+++ b/internal/service/smarthttp/upload_pack.go
@@ -82,7 +82,10 @@ func (s *server) PostUploadPack(stream gitalypb.SmartHTTPService_PostUploadPackS
var globalOpts []git.Option
if featureflag.IsEnabled(ctx, featureflag.UploadPackFilter) {
- globalOpts = append(globalOpts, git.UploadPackFilterConfig()...)
+ globalOpts = append(globalOpts,
+ git.ValueFlag{"-c", "uploadpack.allowFilter=true"},
+ git.ValueFlag{"-c", "uploadpack.allowAnySHA1InWant=true"},
+ )
}
for _, o := range req.GitConfigOptions {
diff --git a/internal/service/smarthttp/upload_pack_test.go b/internal/service/smarthttp/upload_pack_test.go
index 808ace220..aa1282e67 100644
--- a/internal/service/smarthttp/upload_pack_test.go
+++ b/internal/service/smarthttp/upload_pack_test.go
@@ -29,8 +29,8 @@ const (
)
func TestSuccessfulUploadPackRequest(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
ctx, cancel := testhelper.Context()
defer cancel()
@@ -95,8 +95,8 @@ func TestSuccessfulUploadPackRequest(t *testing.T) {
}
func TestUploadPackRequestWithGitConfigOptions(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
ctx, cancel := testhelper.Context()
defer cancel()
@@ -167,8 +167,8 @@ func TestUploadPackRequestWithGitProtocol(t *testing.T) {
restore := testhelper.EnableGitProtocolV2Support()
defer restore()
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
ctx, cancel := testhelper.Context()
defer cancel()
@@ -213,8 +213,8 @@ func TestUploadPackRequestWithGitProtocol(t *testing.T) {
// on 'deepen' requests even though the request is being handled just
// fine from the client perspective.
func TestSuccessfulUploadPackDeepenRequest(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
ctx, cancel := testhelper.Context()
defer cancel()
@@ -235,8 +235,8 @@ func TestSuccessfulUploadPackDeepenRequest(t *testing.T) {
}
func TestFailedUploadPackRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
rpcRequests := []gitalypb.PostUploadPackRequest{
{Repository: &gitalypb.Repository{StorageName: "fake", RelativePath: "path"}}, // Repository doesn't exist
@@ -324,8 +324,8 @@ func extractPackDataFromResponse(t *testing.T, buf *bytes.Buffer) ([]byte, int,
}
func TestUploadPackRequestForPartialCloneSuccess(t *testing.T) {
- server, serverSocketPath := runSmartHTTPServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSmartHTTPServer(t)
+ defer stop()
testRepo := testhelper.TestRepository()
testRepoPath, err := helper.GetRepoPath(testRepo)
diff --git a/internal/service/ssh/receive_pack_test.go b/internal/service/ssh/receive_pack_test.go
index 7e4ad6fb3..2506c4620 100644
--- a/internal/service/ssh/receive_pack_test.go
+++ b/internal/service/ssh/receive_pack_test.go
@@ -27,8 +27,8 @@ import (
)
func TestFailedReceivePackRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
client, conn := newSSHClient(t, serverSocketPath)
defer conn.Close()
@@ -84,8 +84,8 @@ func TestReceivePackPushSuccess(t *testing.T) {
hookOutputFile, cleanup := testhelper.CaptureHookEnv(t)
defer cleanup()
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
glRepository := "project-456"
@@ -112,8 +112,8 @@ func TestReceivePackPushSuccessWithGitProtocol(t *testing.T) {
restore := testhelper.EnableGitProtocolV2Support()
defer restore()
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
lHead, rHead, err := testCloneAndPush(t, serverSocketPath, pushParams{storageName: testRepo.GetStorageName(), glID: "1", gitProtocol: git.ProtocolV2})
if err != nil {
@@ -129,8 +129,8 @@ func TestReceivePackPushSuccessWithGitProtocol(t *testing.T) {
}
func TestReceivePackPushFailure(t *testing.T) {
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
_, _, err := testCloneAndPush(t, serverSocketPath, pushParams{storageName: "foobar", glID: "1"})
require.Error(t, err, "local and remote head equal. push did not fail")
@@ -140,8 +140,8 @@ func TestReceivePackPushFailure(t *testing.T) {
}
func TestReceivePackPushHookFailure(t *testing.T) {
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
hookDir, err := ioutil.TempDir("", "gitaly-tmp-hooks")
require.NoError(t, err)
@@ -161,8 +161,8 @@ func TestReceivePackPushHookFailure(t *testing.T) {
}
func TestObjectPoolRefAdvertisementHidingSSH(t *testing.T) {
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
client, conn := newSSHClient(t, serverSocketPath)
defer conn.Close()
@@ -213,8 +213,8 @@ func TestSSHReceivePackToHooks(t *testing.T) {
restore := testhelper.EnableGitProtocolV2Support()
defer restore()
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
tempGitlabShellDir, cleanup := testhelper.CreateTemporaryGitlabShellDir(t)
defer cleanup()
diff --git a/internal/service/ssh/testhelper_test.go b/internal/service/ssh/testhelper_test.go
index e368ba877..c6af60b20 100644
--- a/internal/service/ssh/testhelper_test.go
+++ b/internal/service/ssh/testhelper_test.go
@@ -1,12 +1,12 @@
package ssh
import (
- "net"
"os"
"path"
"testing"
log "github.com/sirupsen/logrus"
+ "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/git/hooks"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -58,21 +58,15 @@ func mustGetCwd() string {
return wd
}
-func runSSHServer(t *testing.T, serverOpts ...ServerOpt) (*grpc.Server, string) {
- server := testhelper.NewTestGrpcServer(t, nil, nil)
+func runSSHServer(t *testing.T, serverOpts ...ServerOpt) (string, func()) {
+ srv := testhelper.NewServer(t, nil, nil)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterSSHServiceServer(server, NewServer(serverOpts...))
- reflection.Register(server)
+ gitalypb.RegisterSSHServiceServer(srv.GrpcServer(), NewServer(serverOpts...))
+ reflection.Register(srv.GrpcServer())
- go server.Serve(listener)
+ require.NoError(t, srv.Start())
- return server, "unix://" + serverSocketPath
+ return "unix://" + srv.Socket(), srv.Stop
}
func newSSHClient(t *testing.T, serverSocketPath string) (gitalypb.SSHServiceClient, *grpc.ClientConn) {
diff --git a/internal/service/ssh/upload_archive_test.go b/internal/service/ssh/upload_archive_test.go
index 7a512bc3f..160e6ee87 100644
--- a/internal/service/ssh/upload_archive_test.go
+++ b/internal/service/ssh/upload_archive_test.go
@@ -16,8 +16,8 @@ import (
)
func TestFailedUploadArchiveRequestDueToTimeout(t *testing.T) {
- server, serverSocketPath := runSSHServer(t, WithArchiveRequestTimeout(100*time.Microsecond))
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t, WithArchiveRequestTimeout(100*time.Microsecond))
+ defer stop()
client, conn := newSSHClient(t, serverSocketPath)
defer conn.Close()
@@ -50,8 +50,8 @@ func TestFailedUploadArchiveRequestDueToTimeout(t *testing.T) {
}
func TestFailedUploadArchiveRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
client, conn := newSSHClient(t, serverSocketPath)
defer conn.Close()
@@ -99,8 +99,8 @@ func TestFailedUploadArchiveRequestDueToValidationError(t *testing.T) {
}
func TestUploadArchiveSuccess(t *testing.T) {
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
cmd := exec.Command("git", "archive", "master", "--remote=git@localhost:test/test.git")
diff --git a/internal/service/ssh/upload_pack_test.go b/internal/service/ssh/upload_pack_test.go
index d3936461d..60618b5c8 100644
--- a/internal/service/ssh/upload_pack_test.go
+++ b/internal/service/ssh/upload_pack_test.go
@@ -21,9 +21,8 @@ import (
)
func TestFailedUploadPackRequestDueToTimeout(t *testing.T) {
- server, serverSocketPath := runSSHServer(t, WithUploadPackRequestTimeout(10*time.Microsecond))
-
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t, WithUploadPackRequestTimeout(10*time.Microsecond))
+ defer stop()
client, conn := newSSHClient(t, serverSocketPath)
defer conn.Close()
@@ -77,8 +76,8 @@ func requireFailedSSHStream(t *testing.T, recv func() (int32, error)) {
}
func TestFailedUploadPackRequestDueToValidationError(t *testing.T) {
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
client, conn := newSSHClient(t, serverSocketPath)
defer conn.Close()
@@ -126,8 +125,8 @@ func TestFailedUploadPackRequestDueToValidationError(t *testing.T) {
}
func TestUploadPackCloneSuccess(t *testing.T) {
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
localRepoPath := path.Join(testRepoRoot, "gitlab-test-upload-pack-local")
@@ -158,8 +157,8 @@ func TestUploadPackCloneSuccessWithGitProtocol(t *testing.T) {
restore := testhelper.EnableGitProtocolV2Support()
defer restore()
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
localRepoPath := path.Join(testRepoRoot, "gitlab-test-upload-pack-local")
@@ -192,8 +191,8 @@ func TestUploadPackCloneSuccessWithGitProtocol(t *testing.T) {
}
func TestUploadPackCloneHideTags(t *testing.T) {
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
localRepoPath := path.Join(testRepoRoot, "gitlab-test-upload-pack-local-hide-tags")
@@ -213,8 +212,8 @@ func TestUploadPackCloneHideTags(t *testing.T) {
}
func TestUploadPackCloneFailure(t *testing.T) {
- server, serverSocketPath := runSSHServer(t)
- defer server.Stop()
+ serverSocketPath, stop := runSSHServer(t)
+ defer stop()
localRepoPath := path.Join(testRepoRoot, "gitlab-test-upload-pack-local-failure")
diff --git a/internal/service/wiki/delete_page_test.go b/internal/service/wiki/delete_page_test.go
index 0ffac0eb0..428ba4b7d 100644
--- a/internal/service/wiki/delete_page_test.go
+++ b/internal/service/wiki/delete_page_test.go
@@ -17,8 +17,8 @@ func TestSuccessfulWikiDeletePageRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -85,8 +85,8 @@ func TestFailedWikiDeletePageDueToValidations(t *testing.T) {
wikiRepo, _, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/wiki/find_file_test.go b/internal/service/wiki/find_file_test.go
index 9908686a0..1ff13871f 100644
--- a/internal/service/wiki/find_file_test.go
+++ b/internal/service/wiki/find_file_test.go
@@ -18,8 +18,8 @@ func TestSuccessfulWikiFindFileRequest(t *testing.T) {
_, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -156,8 +156,8 @@ func TestFailedWikiFindFileDueToValidation(t *testing.T) {
wikiRepo, _, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/wiki/find_page_test.go b/internal/service/wiki/find_page_test.go
index fd7e262f6..4d5ab7249 100644
--- a/internal/service/wiki/find_page_test.go
+++ b/internal/service/wiki/find_page_test.go
@@ -14,8 +14,8 @@ func TestSuccessfulWikiFindPageRequest(t *testing.T) {
wikiRepo, _, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -190,8 +190,8 @@ func TestSuccessfulWikiFindPageSameTitleDifferentPathRequest(t *testing.T) {
wikiRepo, _, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -306,8 +306,8 @@ func TestFailedWikiFindPageDueToValidation(t *testing.T) {
wikiRepo, _, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -372,8 +372,8 @@ func readFullWikiPageFromWikiFindPageClient(t *testing.T, c gitalypb.WikiService
}
func TestInvalidWikiFindPageRequestRevision(t *testing.T) {
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/wiki/get_all_pages_test.go b/internal/service/wiki/get_all_pages_test.go
index c14acbd46..7952915c2 100644
--- a/internal/service/wiki/get_all_pages_test.go
+++ b/internal/service/wiki/get_all_pages_test.go
@@ -14,8 +14,8 @@ func TestSuccessfulWikiGetAllPagesRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -69,8 +69,8 @@ func TestWikiGetAllPagesSorting(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -177,8 +177,8 @@ func TestWikiGetAllPagesSorting(t *testing.T) {
}
func TestFailedWikiGetAllPagesDueToValidation(t *testing.T) {
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/wiki/get_page_versions_test.go b/internal/service/wiki/get_page_versions_test.go
index 6456146d3..09a8ad15a 100644
--- a/internal/service/wiki/get_page_versions_test.go
+++ b/internal/service/wiki/get_page_versions_test.go
@@ -19,8 +19,8 @@ func TestWikiGetPageVersionsRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -109,8 +109,8 @@ func TestWikiGetPageVersionsPaginationParams(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/wiki/list_pages_test.go b/internal/service/wiki/list_pages_test.go
index 4bb9d6995..b2e0f164b 100644
--- a/internal/service/wiki/list_pages_test.go
+++ b/internal/service/wiki/list_pages_test.go
@@ -13,8 +13,8 @@ func TestSuccessfulWikiListPagesRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -70,8 +70,8 @@ func TestWikiListPagesSorting(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/wiki/testhelper_test.go b/internal/service/wiki/testhelper_test.go
index 5de3ac199..efad55063 100644
--- a/internal/service/wiki/testhelper_test.go
+++ b/internal/service/wiki/testhelper_test.go
@@ -3,7 +3,6 @@ package wiki
import (
"bytes"
"io/ioutil"
- "net"
"os"
"path"
"strings"
@@ -58,21 +57,15 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func runWikiServiceServer(t *testing.T) (*grpc.Server, string) {
- grpcServer := testhelper.NewTestGrpcServer(t, nil, nil)
- serverSocketPath := testhelper.GetTemporaryGitalySocketFileName()
+func runWikiServiceServer(t *testing.T) (func(), string) {
+ srv := testhelper.NewServer(t, nil, nil)
- listener, err := net.Listen("unix", serverSocketPath)
- if err != nil {
- t.Fatal(err)
- }
-
- gitalypb.RegisterWikiServiceServer(grpcServer, &server{ruby: rubyServer})
- reflection.Register(grpcServer)
+ gitalypb.RegisterWikiServiceServer(srv.GrpcServer(), &server{ruby: rubyServer})
+ reflection.Register(srv.GrpcServer())
- go grpcServer.Serve(listener)
+ require.NoError(t, srv.Start())
- return grpcServer, "unix://" + serverSocketPath
+ return srv.Stop, "unix://" + srv.Socket()
}
func newWikiClient(t *testing.T, serverSocketPath string) (gitalypb.WikiServiceClient, *grpc.ClientConn) {
diff --git a/internal/service/wiki/update_page_test.go b/internal/service/wiki/update_page_test.go
index f4bbbbc78..094628826 100644
--- a/internal/service/wiki/update_page_test.go
+++ b/internal/service/wiki/update_page_test.go
@@ -18,8 +18,8 @@ func TestSuccessfulWikiUpdatePageRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -114,8 +114,8 @@ func TestFailedWikiUpdatePageDueToValidations(t *testing.T) {
wikiRepo, _, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/wiki/write_page_test.go b/internal/service/wiki/write_page_test.go
index 53577ebc7..37b1ce86d 100644
--- a/internal/service/wiki/write_page_test.go
+++ b/internal/service/wiki/write_page_test.go
@@ -18,8 +18,8 @@ func TestSuccessfulWikiWritePageRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -117,8 +117,8 @@ func TestFailedWikiWritePageDueToDuplicatePage(t *testing.T) {
wikiRepo, _, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -162,8 +162,8 @@ func TestFailedWikiWritePageInPathDueToDuplicatePage(t *testing.T) {
wikiRepo, _, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
@@ -206,8 +206,8 @@ func TestFailedWikiWritePageInPathDueToDuplicatePage(t *testing.T) {
func TestFailedWikiWritePageDueToValidations(t *testing.T) {
wikiRepo := &gitalypb.Repository{}
- server, serverSocketPath := runWikiServiceServer(t)
- defer server.Stop()
+ stop, serverSocketPath := runWikiServiceServer(t)
+ defer stop()
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()