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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-27 16:01:28 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-06-30 16:43:41 +0300
commit35fdf65b8635be8648a58ce75951dcbb0f0cfc94 (patch)
tree784faf146e45f8289a7b96132da55294488ecafd
parentb489ad97db7fe2873cf96767fb765f3b0d60c3ca (diff)
repository: Use helper to dedup repository service setup
Many tests in the `repository` manually assemble the service server via `testserver.RunGitalyServer()`, which also requires them to pass down required dependencies. This is quite boilerplate-y and ultimately not needed: we can just convert most of them to use `runRepositoryService()` to handle the setup for us. Do so to reduce the test setup noise.
-rw-r--r--internal/gitaly/service/repository/apply_gitattributes_test.go16
-rw-r--r--internal/gitaly/service/repository/fetch_bundle_test.go24
-rw-r--r--internal/gitaly/service/repository/fetch_remote_test.go18
-rw-r--r--internal/gitaly/service/repository/replicate_test.go26
-rw-r--r--internal/gitaly/service/repository/restore_custom_hooks_test.go18
5 files changed, 6 insertions, 96 deletions
diff --git a/internal/gitaly/service/repository/apply_gitattributes_test.go b/internal/gitaly/service/repository/apply_gitattributes_test.go
index c2af2db39..4a684421f 100644
--- a/internal/gitaly/service/repository/apply_gitattributes_test.go
+++ b/internal/gitaly/service/repository/apply_gitattributes_test.go
@@ -12,11 +12,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v15/internal/backchannel"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
- "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testserver"
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/txinfo"
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/voting"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
@@ -92,19 +90,7 @@ func TestApplyGitattributesWithTransaction(t *testing.T) {
cfg, repo, repoPath := testcfg.BuildWithRepo(t)
transactionServer := &testTransactionServer{}
- testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterRepositoryServiceServer(srv, NewServer(
- deps.GetCfg(),
- deps.GetRubyServer(),
- deps.GetLocator(),
- deps.GetTxManager(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetConnsPool(),
- deps.GetGit2goExecutor(),
- deps.GetHousekeepingManager(),
- ))
- })
+ runRepositoryService(t, cfg, nil)
// We're using internal listener in order to route around
// Praefect in our tests. Otherwise Praefect would replace our
diff --git a/internal/gitaly/service/repository/fetch_bundle_test.go b/internal/gitaly/service/repository/fetch_bundle_test.go
index 0a45fab43..03a2bd0b8 100644
--- a/internal/gitaly/service/repository/fetch_bundle_test.go
+++ b/internal/gitaly/service/repository/fetch_bundle_test.go
@@ -10,8 +10,6 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
gitalyhook "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service/hook"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
@@ -20,7 +18,6 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/txinfo"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
- "google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
@@ -78,26 +75,7 @@ func TestServer_FetchBundle_transaction(t *testing.T) {
testcfg.BuildGitalyHooks(t, cfg)
hookManager := &mockHookManager{}
- addr := testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterRepositoryServiceServer(srv, NewServer(
- deps.GetCfg(),
- deps.GetRubyServer(),
- deps.GetLocator(),
- deps.GetTxManager(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetConnsPool(),
- deps.GetGit2goExecutor(),
- deps.GetHousekeepingManager(),
- ))
- gitalypb.RegisterHookServiceServer(srv, hook.NewServer(
- deps.GetHookManager(),
- deps.GetGitCmdFactory(),
- deps.GetPackObjectsCache(),
- ))
- }, testserver.WithHookManager(hookManager), testserver.WithDisablePraefect())
-
- client := newRepositoryClient(t, cfg, addr)
+ client, _ := runRepositoryService(t, cfg, nil, testserver.WithHookManager(hookManager), testserver.WithDisablePraefect())
tmp := testhelper.TempDir(t)
bundlePath := filepath.Join(tmp, "test.bundle")
diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go
index 07fbb35f9..8ba97c1c7 100644
--- a/internal/gitaly/service/repository/fetch_remote_test.go
+++ b/internal/gitaly/service/repository/fetch_remote_test.go
@@ -16,7 +16,6 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata"
@@ -25,7 +24,6 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testserver"
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/txinfo"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
- "google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
@@ -173,23 +171,9 @@ func TestFetchRemote_transaction(t *testing.T) {
sourceCfg := testcfg.Build(t)
txManager := transaction.NewTrackingManager()
- addr := testserver.RunGitalyServer(t, sourceCfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterRepositoryServiceServer(srv, NewServer(
- deps.GetCfg(),
- deps.GetRubyServer(),
- deps.GetLocator(),
- deps.GetTxManager(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetConnsPool(),
- deps.GetGit2goExecutor(),
- deps.GetHousekeepingManager(),
- ))
- }, testserver.WithTransactionManager(txManager))
+ client, addr := runRepositoryService(t, sourceCfg, nil, testserver.WithTransactionManager(txManager))
sourceCfg.SocketPath = addr
- client := newRepositoryClient(t, sourceCfg, addr)
-
ctx := testhelper.Context(t)
repo, _ := gittest.CreateRepository(ctx, t, sourceCfg, gittest.CreateRepositoryConfig{
RelativePath: t.Name(),
diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go
index 44521db8f..69c049ea9 100644
--- a/internal/gitaly/service/repository/replicate_test.go
+++ b/internal/gitaly/service/repository/replicate_test.go
@@ -20,10 +20,6 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
gitalyhook "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service/hook"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service/ref"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service/ssh"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
@@ -460,19 +456,7 @@ func TestFetchInternalRemote_successful(t *testing.T) {
testcfg.BuildGitalyHooks(t, remoteCfg)
gittest.WriteCommit(t, remoteCfg, remoteRepoPath, gittest.WithBranch("master"))
- remoteAddr := testserver.RunGitalyServer(t, remoteCfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterSSHServiceServer(srv, ssh.NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetTxManager(),
- ))
- gitalypb.RegisterRefServiceServer(srv, ref.NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetTxManager(),
- deps.GetCatfileCache(),
- ))
- }, testserver.WithDisablePraefect())
+ _, remoteAddr := runRepositoryService(t, remoteCfg, nil, testserver.WithDisablePraefect())
localCfg, localRepoProto, localRepoPath := testcfg.BuildWithRepo(t)
localRepo := localrepo.NewTestRepo(t, localCfg, localRepoProto)
@@ -484,13 +468,7 @@ func TestFetchInternalRemote_successful(t *testing.T) {
// We do not require the server's address, but it needs to be around regardless such that
// `FetchInternalRemote` can reach the hook service which is injected via the config.
- testserver.RunGitalyServer(t, localCfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterHookServiceServer(srv, hook.NewServer(
- deps.GetHookManager(),
- deps.GetGitCmdFactory(),
- deps.GetPackObjectsCache(),
- ))
- }, testserver.WithHookManager(gitalyhook.NewMockManager(t, nil, nil, nil,
+ runRepositoryService(t, localCfg, nil, testserver.WithHookManager(gitalyhook.NewMockManager(t, nil, nil, nil,
func(t *testing.T, _ context.Context, _ gitalyhook.ReferenceTransactionState, _ []string, stdin io.Reader) error {
// We need to discard stdin or otherwise the sending Goroutine may return an
// EOF error and cause the test to fail.
diff --git a/internal/gitaly/service/repository/restore_custom_hooks_test.go b/internal/gitaly/service/repository/restore_custom_hooks_test.go
index 965e0d768..caa6d0290 100644
--- a/internal/gitaly/service/repository/restore_custom_hooks_test.go
+++ b/internal/gitaly/service/repository/restore_custom_hooks_test.go
@@ -10,7 +10,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/transaction"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
@@ -21,7 +20,6 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/voting"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
- "google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
@@ -38,23 +36,9 @@ func testSuccessfulRestoreCustomHooksRequest(t *testing.T, ctx context.Context)
testcfg.BuildGitalyHooks(t, cfg)
txManager := transaction.NewTrackingManager()
- addr := testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterRepositoryServiceServer(srv, NewServer(
- deps.GetCfg(),
- deps.GetRubyServer(),
- deps.GetLocator(),
- deps.GetTxManager(),
- deps.GetGitCmdFactory(),
- deps.GetCatfileCache(),
- deps.GetConnsPool(),
- deps.GetGit2goExecutor(),
- deps.GetHousekeepingManager(),
- ))
- }, testserver.WithTransactionManager(txManager))
+ client, addr := runRepositoryService(t, cfg, nil, testserver.WithTransactionManager(txManager))
cfg.SocketPath = addr
- client := newRepositoryClient(t, cfg, addr)
-
ctx, err := txinfo.InjectTransaction(ctx, 1, "node", true)
require.NoError(t, err)