diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2020-10-16 01:45:02 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2020-10-16 01:45:02 +0300 |
commit | b4b8b03d923647b9e5d42c5f746db1647f7c06ee (patch) | |
tree | 4a1744b8ded4628839c8f28a30c97e11e2e7c5ec | |
parent | c40d8906f30f71801e7840a1932208b7274634a6 (diff) | |
parent | 756ba0cb7769e1596604103fba6beef19b60a749 (diff) |
Merge branch 'ps-repository-uses-locator' into 'master'
Introduce Locator abstraction to repository service
See merge request gitlab-org/gitaly!2647
38 files changed, 308 insertions, 165 deletions
diff --git a/internal/gitaly/service/repository/apply_gitattributes_test.go b/internal/gitaly/service/repository/apply_gitattributes_test.go index cbb3a8777..c34eb042d 100644 --- a/internal/gitaly/service/repository/apply_gitattributes_test.go +++ b/internal/gitaly/service/repository/apply_gitattributes_test.go @@ -8,13 +8,15 @@ import ( "testing" "github.com/stretchr/testify/assert" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestApplyGitattributesSuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -66,7 +68,8 @@ func TestApplyGitattributesSuccess(t *testing.T) { } func TestApplyGitattributesFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/archive_test.go b/internal/gitaly/service/repository/archive_test.go index 84cc7d983..63f717b90 100644 --- a/internal/gitaly/service/repository/archive_test.go +++ b/internal/gitaly/service/repository/archive_test.go @@ -25,7 +25,8 @@ const ( ) func TestGetArchiveSuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -184,7 +185,7 @@ func TestGetArchiveWithLfsSuccess(t *testing.T) { cfg := config.Config cfg.Gitlab.URL = url cfg.Gitlab.SecretFile = filepath.Join(cfg.GitlabShell.Dir, ".gitlab_shell_secret") - serverSocketPath, stop := runRepoServerWithConfig(t, cfg) + serverSocketPath, stop := runRepoServerWithConfig(t, cfg, config.NewLocator(cfg)) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -278,7 +279,8 @@ func TestGetArchiveWithLfsSuccess(t *testing.T) { } func TestGetArchiveFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -412,7 +414,8 @@ func TestGetArchiveFailure(t *testing.T) { } func TestGetArchivePathInjection(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -486,7 +489,8 @@ func TestGetArchivePathInjection(t *testing.T) { } func TestGetArchiveEnv(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/backup_custom_hooks_test.go b/internal/gitaly/service/repository/backup_custom_hooks_test.go index 8efcec4d5..28aaf2824 100644 --- a/internal/gitaly/service/repository/backup_custom_hooks_test.go +++ b/internal/gitaly/service/repository/backup_custom_hooks_test.go @@ -11,14 +11,15 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" ) func TestSuccessfullBackupCustomHooksRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -30,7 +31,7 @@ func TestSuccessfullBackupCustomHooksRequest(t *testing.T) { testRepo, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - repoPath, err := helper.GetPath(testRepo) + repoPath, err := locator.GetPath(testRepo) require.NoError(t, err) expectedTarResponse := []string{ @@ -67,7 +68,8 @@ func TestSuccessfullBackupCustomHooksRequest(t *testing.T) { } func TestSuccessfullBackupCustomHooksSymlink(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -79,7 +81,7 @@ func TestSuccessfullBackupCustomHooksSymlink(t *testing.T) { testRepo, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - repoPath, err := helper.GetPath(testRepo) + repoPath, err := locator.GetPath(testRepo) require.NoError(t, err) linkTarget := "/var/empty" @@ -106,7 +108,8 @@ func TestSuccessfullBackupCustomHooksSymlink(t *testing.T) { } func TestSuccessfullBackupCustomHooksRequestWithNoHooks(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/calculate_checksum_test.go b/internal/gitaly/service/repository/calculate_checksum_test.go index 41835c720..3e27c036a 100644 --- a/internal/gitaly/service/repository/calculate_checksum_test.go +++ b/internal/gitaly/service/repository/calculate_checksum_test.go @@ -8,13 +8,15 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/command" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulCalculateChecksum(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -71,7 +73,8 @@ func TestRefWhitelist(t *testing.T) { } func TestEmptyRepositoryCalculateChecksum(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -90,7 +93,8 @@ func TestEmptyRepositoryCalculateChecksum(t *testing.T) { } func TestBrokenRepositoryCalculateChecksum(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -111,7 +115,8 @@ func TestBrokenRepositoryCalculateChecksum(t *testing.T) { } func TestFailedCalculateChecksum(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -146,7 +151,8 @@ func TestFailedCalculateChecksum(t *testing.T) { } func TestInvalidRefsCalculateChecksum(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/cleanup_test.go b/internal/gitaly/service/repository/cleanup_test.go index d29aeb73a..743e84813 100644 --- a/internal/gitaly/service/repository/cleanup_test.go +++ b/internal/gitaly/service/repository/cleanup_test.go @@ -11,12 +11,14 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) func TestCleanupDeletesRefsLocks(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -59,7 +61,8 @@ func TestCleanupDeletesRefsLocks(t *testing.T) { } func TestCleanupDeletesPackedRefsLock(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -128,7 +131,8 @@ func TestCleanupDeletesPackedRefsLock(t *testing.T) { // TODO: replace emulated rebase RPC with actual // https://gitlab.com/gitlab-org/gitaly/issues/1750 func TestCleanupDeletesStaleWorktrees(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -200,7 +204,8 @@ func TestCleanupDisconnectedWorktrees(t *testing.T) { worktreeAdminDir = "worktrees" ) - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -259,7 +264,8 @@ func TestCleanupDisconnectedWorktrees(t *testing.T) { } func TestCleanupFileLocks(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -294,7 +300,8 @@ func TestCleanupFileLocks(t *testing.T) { } func TestCleanupDeletesPackedRefsNew(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/commit_graph_test.go b/internal/gitaly/service/repository/commit_graph_test.go index 11efa8a18..bc9398f2b 100644 --- a/internal/gitaly/service/repository/commit_graph_test.go +++ b/internal/gitaly/service/repository/commit_graph_test.go @@ -7,12 +7,14 @@ import ( "time" "github.com/stretchr/testify/assert" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) func TestWriteCommitGraph(t *testing.T) { - s, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + s, stop := runRepoServer(t, locator) defer stop() c, conn := newRepositoryClient(t, s) @@ -44,7 +46,8 @@ func TestWriteCommitGraph(t *testing.T) { } func TestUpdateCommitGraph(t *testing.T) { - s, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + s, stop := runRepoServer(t, locator) defer stop() c, conn := newRepositoryClient(t, s) diff --git a/internal/gitaly/service/repository/config_test.go b/internal/gitaly/service/repository/config_test.go index 9cc0fcea1..39db6e07d 100644 --- a/internal/gitaly/service/repository/config_test.go +++ b/internal/gitaly/service/repository/config_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -14,7 +15,8 @@ import ( ) func TestDeleteConfig(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -74,7 +76,8 @@ func TestDeleteConfig(t *testing.T) { } func TestSetConfig(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/create_bundle_test.go b/internal/gitaly/service/repository/create_bundle_test.go index 2ad93a0f9..914500c6e 100644 --- a/internal/gitaly/service/repository/create_bundle_test.go +++ b/internal/gitaly/service/repository/create_bundle_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/tempdir" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -17,7 +18,8 @@ import ( ) func TestSuccessfulCreateBundleRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -67,7 +69,8 @@ func TestSuccessfulCreateBundleRequest(t *testing.T) { } func TestFailedCreateBundleRequestDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/create_from_bundle_test.go b/internal/gitaly/service/repository/create_from_bundle_test.go index 46262b34b..eee45ff0a 100644 --- a/internal/gitaly/service/repository/create_from_bundle_test.go +++ b/internal/gitaly/service/repository/create_from_bundle_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/git/log" - "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/tempdir" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -19,7 +19,8 @@ import ( ) func TestSuccessfulCreateRepositoryFromBundleRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -47,7 +48,7 @@ func TestSuccessfulCreateRepositoryFromBundleRequest(t *testing.T) { StorageName: testhelper.DefaultStorageName, RelativePath: "a-repo-from-bundle", } - importedRepoPath, err := helper.GetPath(importedRepo) + importedRepoPath, err := locator.GetPath(importedRepo) require.NoError(t, err) defer os.RemoveAll(importedRepoPath) @@ -86,7 +87,8 @@ func TestSuccessfulCreateRepositoryFromBundleRequest(t *testing.T) { } func TestFailedCreateRepositoryFromBundleRequestDueToInvalidBundle(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -102,7 +104,7 @@ func TestFailedCreateRepositoryFromBundleRequestDueToInvalidBundle(t *testing.T) StorageName: testhelper.DefaultStorageName, RelativePath: "a-repo-from-bundle", } - importedRepoPath, err := helper.GetPath(importedRepo) + importedRepoPath, err := locator.GetPath(importedRepo) require.NoError(t, err) defer os.RemoveAll(importedRepoPath) @@ -128,7 +130,8 @@ func TestFailedCreateRepositoryFromBundleRequestDueToInvalidBundle(t *testing.T) } func TestFailedCreateRepositoryFromBundleRequestDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -147,7 +150,8 @@ func TestFailedCreateRepositoryFromBundleRequestDueToValidations(t *testing.T) { } func TestFailedCreateRepositoryFromBundle_ExistingDirectory(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() testRepo, _, cleanup := testhelper.NewTestRepo(t) diff --git a/internal/gitaly/service/repository/create_from_snapshot_test.go b/internal/gitaly/service/repository/create_from_snapshot_test.go index 0cfb79f54..523c23cfe 100644 --- a/internal/gitaly/service/repository/create_from_snapshot_test.go +++ b/internal/gitaly/service/repository/create_from_snapshot_test.go @@ -12,6 +12,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/gitaly/archive" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -55,7 +56,8 @@ func generateTarFile(t *testing.T, path string) ([]byte, []string) { } func createFromSnapshot(t *testing.T, req *gitalypb.CreateRepositoryFromSnapshotRequest) (*gitalypb.CreateRepositoryFromSnapshotResponse, error) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/create_from_url_test.go b/internal/gitaly/service/repository/create_from_url_test.go index 41a114643..0807f47a5 100644 --- a/internal/gitaly/service/repository/create_from_url_test.go +++ b/internal/gitaly/service/repository/create_from_url_test.go @@ -10,14 +10,15 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulCreateRepositoryFromURLRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -49,7 +50,7 @@ func TestSuccessfulCreateRepositoryFromURLRequest(t *testing.T) { _, err := client.CreateRepositoryFromURL(ctx, req) require.NoError(t, err) - importedRepoPath, err := helper.GetRepoPath(importedRepo) + importedRepoPath, err := locator.GetRepoPath(importedRepo) require.NoError(t, err) defer os.RemoveAll(importedRepoPath) @@ -85,7 +86,8 @@ func TestCloneRepositoryFromUrlCommand(t *testing.T) { } func TestFailedCreateRepositoryFromURLRequestDueToExistingTarget(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -118,7 +120,7 @@ func TestFailedCreateRepositoryFromURLRequestDueToExistingTarget(t *testing.T) { StorageName: testhelper.DefaultStorageName, } - importedRepoPath, err := helper.GetPath(importedRepo) + importedRepoPath, err := locator.GetPath(importedRepo) require.NoError(t, err) if testCase.isDir { @@ -140,7 +142,8 @@ func TestFailedCreateRepositoryFromURLRequestDueToExistingTarget(t *testing.T) { } func TestPreventingRedirect(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/create_test.go b/internal/gitaly/service/repository/create_test.go index 76e18470f..1b7d2f7f0 100644 --- a/internal/gitaly/service/repository/create_test.go +++ b/internal/gitaly/service/repository/create_test.go @@ -9,14 +9,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestCreateRepositorySuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -25,7 +26,7 @@ func TestCreateRepositorySuccess(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - storageDir, err := helper.GetStorageByName("default") + storageDir, err := locator.GetStorageByName("default") require.NoError(t, err) relativePath := "create-repository-test.git" repoDir := filepath.Join(storageDir, relativePath) @@ -49,7 +50,8 @@ func TestCreateRepositorySuccess(t *testing.T) { } func TestCreateRepositoryFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -58,7 +60,7 @@ func TestCreateRepositoryFailure(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - storagePath, err := helper.GetStorageByName("default") + storagePath, err := locator.GetStorageByName("default") require.NoError(t, err) fullPath := filepath.Join(storagePath, "foo.git") @@ -74,7 +76,8 @@ func TestCreateRepositoryFailure(t *testing.T) { } func TestCreateRepositoryFailureInvalidArgs(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -104,7 +107,8 @@ func TestCreateRepositoryFailureInvalidArgs(t *testing.T) { } func TestCreateRepositoryIdempotent(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/fetch.go b/internal/gitaly/service/repository/fetch.go index cb27a9bc7..deaf60b5f 100644 --- a/internal/gitaly/service/repository/fetch.go +++ b/internal/gitaly/service/repository/fetch.go @@ -26,7 +26,7 @@ func (s *server) FetchSourceBranch(ctx context.Context, req *gitalypb.FetchSourc return nil, helper.ErrInvalidArgument(err) } - repoPath, err := helper.GetRepoPath(req.Repository) + repoPath, err := s.locator.GetRepoPath(req.Repository) if err != nil { return nil, err } diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go index 29a56229c..cd8254426 100644 --- a/internal/gitaly/service/repository/fetch_remote_test.go +++ b/internal/gitaly/service/repository/fetch_remote_test.go @@ -14,14 +14,14 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" - "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/storage" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) -func copyRepoWithNewRemote(t *testing.T, repo *gitalypb.Repository, remote string) *gitalypb.Repository { - repoPath, err := helper.GetRepoPath(repo) +func copyRepoWithNewRemote(t *testing.T, repo *gitalypb.Repository, locator storage.Locator, remote string) *gitalypb.Repository { + repoPath, err := locator.GetRepoPath(repo) require.NoError(t, err) cloneRepo := &gitalypb.Repository{StorageName: repo.GetStorageName(), RelativePath: "fetch-remote-clone.git"} @@ -44,14 +44,15 @@ func TestFetchRemoteSuccess(t *testing.T) { testRepo, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, _ := newRepositoryClient(t, serverSocketPath) - cloneRepo := copyRepoWithNewRemote(t, testRepo, "my-remote") + cloneRepo := copyRepoWithNewRemote(t, testRepo, locator, "my-remote") defer func(r *gitalypb.Repository) { - path, err := helper.GetRepoPath(r) + path, err := locator.GetRepoPath(r) if err != nil { panic(err) } @@ -130,7 +131,8 @@ func getRefnames(t *testing.T, repoPath string) []string { } func TestFetchRemoteOverHTTP(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -186,7 +188,8 @@ func TestFetchRemoteOverHTTP(t *testing.T) { } func TestFetchRemoteOverHTTPWithRedirect(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -217,7 +220,8 @@ func TestFetchRemoteOverHTTPWithRedirect(t *testing.T) { } func TestFetchRemoteOverHTTPError(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go index d38f61f63..636e44b76 100644 --- a/internal/gitaly/service/repository/fetch_test.go +++ b/internal/gitaly/service/repository/fetch_test.go @@ -10,8 +10,8 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" serverPkg "gitlab.com/gitlab-org/gitaly/internal/gitaly/server" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/repository" - "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag" + "gitlab.com/gitlab-org/gitaly/internal/storage" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" @@ -23,6 +23,8 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) { server, serverSocketPath := runFullServer(t) defer server.Stop() + locator := config.NewLocator(config.Config) + client, conn := repository.NewRepositoryClient(t, serverSocketPath) defer conn.Close() @@ -49,10 +51,10 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) { ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, feature, "true") } - targetRepo, _, cleanup := newTestRepo(t, "fetch-source-target.git") + targetRepo, _, cleanup := newTestRepo(t, locator, "fetch-source-target.git") defer cleanup() - sourceRepo, sourcePath, cleanup := newTestRepo(t, "fetch-source-source.git") + sourceRepo, sourcePath, cleanup := newTestRepo(t, locator, "fetch-source-source.git") defer cleanup() sourceBranch := "fetch-source-branch-test-branch" @@ -81,6 +83,8 @@ func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) { server, serverSocketPath := runFullServer(t) defer server.Stop() + locator := config.NewLocator(config.Config) + client, conn := repository.NewRepositoryClient(t, serverSocketPath) defer conn.Close() @@ -107,7 +111,7 @@ func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) { ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, feature, "false") } - repo, repoPath, cleanup := newTestRepo(t, "fetch-source-source.git") + repo, repoPath, cleanup := newTestRepo(t, locator, "fetch-source-source.git") defer cleanup() sourceBranch := "fetch-source-branch-test-branch" @@ -136,6 +140,8 @@ func TestFetchSourceBranchBranchNotFound(t *testing.T) { server, serverSocketPath := runFullServer(t) defer server.Stop() + locator := config.NewLocator(config.Config) + client, conn := repository.NewRepositoryClient(t, serverSocketPath) defer conn.Close() @@ -162,10 +168,10 @@ func TestFetchSourceBranchBranchNotFound(t *testing.T) { ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, feature, "false") } - targetRepo, _, cleanup := newTestRepo(t, "fetch-source-target.git") + targetRepo, _, cleanup := newTestRepo(t, locator, "fetch-source-target.git") defer cleanup() - sourceRepo, _, cleanup := newTestRepo(t, "fetch-source-source.git") + sourceRepo, _, cleanup := newTestRepo(t, locator, "fetch-source-source.git") defer cleanup() sourceBranch := "does-not-exist" @@ -210,6 +216,8 @@ func TestFetchSourceBranchWrongRef(t *testing.T) { server, serverSocketPath := runFullServer(t) defer server.Stop() + locator := config.NewLocator(config.Config) + client, conn := repository.NewRepositoryClient(t, serverSocketPath) defer conn.Close() @@ -219,10 +227,10 @@ func TestFetchSourceBranchWrongRef(t *testing.T) { md := testhelper.GitalyServersMetadata(t, serverSocketPath) ctx = testhelper.MergeOutgoingMetadata(ctx, md) - targetRepo, _, cleanup := newTestRepo(t, "fetch-source-target.git") + targetRepo, _, cleanup := newTestRepo(t, locator, "fetch-source-target.git") defer cleanup() - sourceRepo, sourceRepoPath, cleanup := newTestRepo(t, "fetch-source-source.git") + sourceRepo, sourceRepoPath, cleanup := newTestRepo(t, locator, "fetch-source-source.git") defer cleanup() sourceBranch := "fetch-source-branch-testmas-branch" @@ -360,13 +368,13 @@ func TestFetchFullServerRequiresAuthentication(t *testing.T) { testhelper.RequireGrpcError(t, err, codes.Unauthenticated) } -func newTestRepo(t *testing.T, relativePath string) (*gitalypb.Repository, string, func()) { +func newTestRepo(t *testing.T, locator storage.Locator, relativePath string) (*gitalypb.Repository, string, func()) { _, testRepoPath, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() repo := &gitalypb.Repository{StorageName: "default", RelativePath: relativePath} - repoPath, err := helper.GetPath(repo) + repoPath, err := locator.GetPath(repo) require.NoError(t, err) require.NoError(t, os.RemoveAll(repoPath)) diff --git a/internal/gitaly/service/repository/fork_test.go b/internal/gitaly/service/repository/fork_test.go index 8f2b557cf..89e2b0d6c 100644 --- a/internal/gitaly/service/repository/fork_test.go +++ b/internal/gitaly/service/repository/fork_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/repository" - "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/testhelper" gitaly_x509 "gitlab.com/gitlab-org/gitaly/internal/x509" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -20,6 +19,8 @@ import ( ) func TestSuccessfulCreateForkRequest(t *testing.T) { + locator := config.NewLocator(config.Config) + for _, tt := range []struct { name string secure bool @@ -67,7 +68,7 @@ func TestSuccessfulCreateForkRequest(t *testing.T) { StorageName: testRepo.StorageName, } - forkedRepoPath, err := helper.GetPath(forkedRepo) + forkedRepoPath, err := locator.GetPath(forkedRepo) require.NoError(t, err) require.NoError(t, os.RemoveAll(forkedRepoPath)) @@ -96,6 +97,8 @@ func TestFailedCreateForkRequestDueToExistingTarget(t *testing.T) { server, serverSocketPath := runFullServer(t) defer server.Stop() + locator := config.NewLocator(config.Config) + client, conn := repository.NewRepositoryClient(t, serverSocketPath) defer conn.Close() @@ -132,7 +135,7 @@ func TestFailedCreateForkRequestDueToExistingTarget(t *testing.T) { StorageName: testRepo.StorageName, } - forkedRepoPath, err := helper.GetPath(forkedRepo) + forkedRepoPath, err := locator.GetPath(forkedRepo) require.NoError(t, err) if testCase.isDir { diff --git a/internal/gitaly/service/repository/fsck_test.go b/internal/gitaly/service/repository/fsck_test.go index 103d24404..03560cdf8 100644 --- a/internal/gitaly/service/repository/fsck_test.go +++ b/internal/gitaly/service/repository/fsck_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -16,7 +17,8 @@ func TestFsckSuccess(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -35,7 +37,8 @@ func TestFsckFailureSeverelyBrokenRepo(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -61,7 +64,8 @@ func TestFsckFailureSlightlyBrokenRepo(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/gc_test.go b/internal/gitaly/service/repository/gc_test.go index 2aa44778c..32df05e7c 100644 --- a/internal/gitaly/service/repository/gc_test.go +++ b/internal/gitaly/service/repository/gc_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/git/gittest" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -28,7 +29,8 @@ var ( ) func TestGarbageCollectCommitGraph(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -64,7 +66,8 @@ func TestGarbageCollectCommitGraph(t *testing.T) { } func TestGarbageCollectSuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -125,7 +128,8 @@ func TestGarbageCollectWithPrune(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -180,7 +184,8 @@ func TestGarbageCollectLogStatistics(t *testing.T) { defer cancel() ctx = ctxlogrus.ToContext(ctx, log.WithField("test", "logging")) - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -196,7 +201,8 @@ func TestGarbageCollectLogStatistics(t *testing.T) { } func TestGarbageCollectDeletesRefsLocks(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -244,7 +250,8 @@ func TestGarbageCollectDeletesRefsLocks(t *testing.T) { } func TestGarbageCollectFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -274,7 +281,8 @@ func TestGarbageCollectFailure(t *testing.T) { } func TestCleanupInvalidKeepAroundRefs(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -372,7 +380,8 @@ func mustCreateFileWithTimes(t testing.TB, path string, mTime time.Time) { } func TestGarbageCollectDeltaIslands(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/info_attributes_test.go b/internal/gitaly/service/repository/info_attributes_test.go index d599b2107..bafb9f6c9 100644 --- a/internal/gitaly/service/repository/info_attributes_test.go +++ b/internal/gitaly/service/repository/info_attributes_test.go @@ -8,13 +8,15 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" ) func TestGetInfoAttributesExisting(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -49,7 +51,8 @@ func TestGetInfoAttributesExisting(t *testing.T) { } func TestGetInfoAttributesNonExisting(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/license_test.go b/internal/gitaly/service/repository/license_test.go index 63886c5f6..bd6ad2156 100644 --- a/internal/gitaly/service/repository/license_test.go +++ b/internal/gitaly/service/repository/license_test.go @@ -5,13 +5,14 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) func TestSuccessfulFindLicenseRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -32,7 +33,8 @@ func TestSuccessfulFindLicenseRequest(t *testing.T) { } func TestFindLicenseRequestEmptyRepo(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -49,7 +51,7 @@ func TestFindLicenseRequestEmptyRepo(t *testing.T) { _, err := client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{Repository: emptyRepo}) require.NoError(t, err) - emptyRepoPath, err := helper.GetRepoPath(emptyRepo) + emptyRepoPath, err := locator.GetRepoPath(emptyRepo) require.NoError(t, err) defer os.RemoveAll(emptyRepoPath) diff --git a/internal/gitaly/service/repository/merge_base_test.go b/internal/gitaly/service/repository/merge_base_test.go index 35b394f8c..8f394bc48 100644 --- a/internal/gitaly/service/repository/merge_base_test.go +++ b/internal/gitaly/service/repository/merge_base_test.go @@ -4,13 +4,15 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulFindFindMergeBaseRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -86,7 +88,8 @@ func TestSuccessfulFindFindMergeBaseRequest(t *testing.T) { } func TestFailedFindMergeBaseRequestDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/midx.go b/internal/gitaly/service/repository/midx.go index c151af2de..ec04e3dc6 100644 --- a/internal/gitaly/service/repository/midx.go +++ b/internal/gitaly/service/repository/midx.go @@ -20,15 +20,15 @@ const ( MidxRelPath = "objects/pack/multi-pack-index" ) -func (*server) MidxRepack(ctx context.Context, in *gitalypb.MidxRepackRequest) (*gitalypb.MidxRepackResponse, error) { +func (s *server) MidxRepack(ctx context.Context, in *gitalypb.MidxRepackRequest) (*gitalypb.MidxRepackResponse, error) { repo := in.GetRepository() if err := midxSetConfig(ctx, repo); err != nil { return nil, err } - for _, cmd := range []midxSubCommand{midxWrite, midxExpire, midxRepack} { - if err := safeMidxCommand(ctx, repo, cmd); err != nil { + for _, cmd := range []midxSubCommand{midxWrite, midxExpire, s.midxRepack} { + if err := s.safeMidxCommand(ctx, repo, cmd); err != nil { if git.IsInvalidArgErr(err) { return nil, helper.ErrInvalidArgumentf("MidxRepack: %w", err) } @@ -45,12 +45,12 @@ func (*server) MidxRepack(ctx context.Context, in *gitalypb.MidxRepackRequest) ( // midxSubCommand is a helper type to group the helper functions in multi-pack-index type midxSubCommand func(ctx context.Context, repo repository.GitRepo) error -func safeMidxCommand(ctx context.Context, repo repository.GitRepo, cmd midxSubCommand) error { +func (s *server) safeMidxCommand(ctx context.Context, repo repository.GitRepo, cmd midxSubCommand) error { if err := cmd(ctx, repo); err != nil { return err } - return midxEnsureExists(ctx, repo) + return s.midxEnsureExists(ctx, repo) } func midxSetConfig(ctx context.Context, repo repository.GitRepo) error { @@ -95,7 +95,7 @@ func midxWrite(ctx context.Context, repo repository.GitRepo) error { return nil } -func midxEnsureExists(ctx context.Context, repo repository.GitRepo) error { +func (s *server) midxEnsureExists(ctx context.Context, repo repository.GitRepo) error { ctxlogger := ctxlogrus.Extract(ctx) if err := midxVerify(ctx, repo); err != nil { @@ -104,7 +104,7 @@ func midxEnsureExists(ctx context.Context, repo repository.GitRepo) error { WithFields(log.Fields{"verify_success": false}). Error("MidxRepack") - return midxRewrite(ctx, repo) + return s.midxRewrite(ctx, repo) } return nil @@ -135,8 +135,8 @@ func midxVerify(ctx context.Context, repo repository.GitRepo) error { return nil } -func midxRewrite(ctx context.Context, repo repository.GitRepo) error { - repoPath, err := helper.GetRepoPath(repo) +func (s *server) midxRewrite(ctx context.Context, repo repository.GitRepo) error { + repoPath, err := s.locator.GetRepoPath(repo) if err != nil { return err } @@ -170,8 +170,8 @@ func midxExpire(ctx context.Context, repo repository.GitRepo) error { return nil } -func midxRepack(ctx context.Context, repo repository.GitRepo) error { - repoPath, err := helper.GetRepoPath(repo) +func (s *server) midxRepack(ctx context.Context, repo repository.GitRepo) error { + repoPath, err := s.locator.GetRepoPath(repo) if err != nil { return err } diff --git a/internal/gitaly/service/repository/midx_test.go b/internal/gitaly/service/repository/midx_test.go index df22fec9a..802961fdd 100644 --- a/internal/gitaly/service/repository/midx_test.go +++ b/internal/gitaly/service/repository/midx_test.go @@ -12,12 +12,14 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/git/stats" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) func TestMidxWrite(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -52,7 +54,8 @@ func TestMidxWrite(t *testing.T) { } func TestMidxRewrite(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -86,7 +89,8 @@ func TestMidxRewrite(t *testing.T) { } func TestMidxRepack(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -132,7 +136,8 @@ func TestMidxRepack(t *testing.T) { } func TestMidxRepackExpire(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/optimize_test.go b/internal/gitaly/service/repository/optimize_test.go index cba2caa29..678d57971 100644 --- a/internal/gitaly/service/repository/optimize_test.go +++ b/internal/gitaly/service/repository/optimize_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/git/stats" "gitlab.com/gitlab-org/gitaly/internal/git/updateref" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -52,7 +53,8 @@ func TestOptimizeRepository(t *testing.T) { testhelper.CreateCommit(t, testRepoPath, "master", nil) - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() repoClient, conn := NewRepositoryClient(t, serverSocketPath) @@ -131,7 +133,8 @@ func TestOptimizeRepositoryValidation(t *testing.T) { }, } - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() repoClient, conn := NewRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/raw_changes_test.go b/internal/gitaly/service/repository/raw_changes_test.go index 07cc8f975..c3de5a746 100644 --- a/internal/gitaly/service/repository/raw_changes_test.go +++ b/internal/gitaly/service/repository/raw_changes_test.go @@ -7,13 +7,15 @@ import ( "unicode/utf8" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestGetRawChanges(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -130,7 +132,8 @@ func TestGetRawChangesSpecialCharacters(t *testing.T) { // This test looks for a specific path known to contain special // characters. - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -174,7 +177,8 @@ func collectChanges(t *testing.T, stream gitalypb.RepositoryService_GetRawChange } func TestGetRawChangesFailures(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -236,7 +240,8 @@ func TestGetRawChangesFailures(t *testing.T) { } func TestGetRawChangesManyFiles(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -264,7 +269,8 @@ func TestGetRawChangesManyFiles(t *testing.T) { } func TestGetRawChangesMappingOperations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -315,7 +321,8 @@ func TestGetRawChangesMappingOperations(t *testing.T) { } func TestGetRawChangesInvalidUTF8Paths(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/rebase_in_progress_test.go b/internal/gitaly/service/repository/rebase_in_progress_test.go index efc44b7ab..5cfea4721 100644 --- a/internal/gitaly/service/repository/rebase_in_progress_test.go +++ b/internal/gitaly/service/repository/rebase_in_progress_test.go @@ -8,13 +8,15 @@ import ( "time" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulIsRebaseInProgressRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -94,7 +96,8 @@ func TestSuccessfulIsRebaseInProgressRequest(t *testing.T) { } func TestFailedIsRebaseInProgressRequestDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/remove_test.go b/internal/gitaly/service/repository/remove_test.go index 24b31f1cd..c25d0e4eb 100644 --- a/internal/gitaly/service/repository/remove_test.go +++ b/internal/gitaly/service/repository/remove_test.go @@ -4,12 +4,14 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) func TestRemoveRepository(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -28,7 +30,8 @@ func TestRemoveRepository(t *testing.T) { } func TestRemoveRepositoryDoesNotExist(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/rename_test.go b/internal/gitaly/service/repository/rename_test.go index e04d9a6ca..48b99ef0e 100644 --- a/internal/gitaly/service/repository/rename_test.go +++ b/internal/gitaly/service/repository/rename_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/storage" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -13,7 +13,8 @@ import ( ) func TestRenameRepositorySuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -30,7 +31,7 @@ func TestRenameRepositorySuccess(t *testing.T) { _, err := client.RenameRepository(ctx, req) require.NoError(t, err) - newDirectory, err := helper.GetPath(&gitalypb.Repository{StorageName: "default", RelativePath: req.RelativePath}) + newDirectory, err := locator.GetPath(&gitalypb.Repository{StorageName: "default", RelativePath: req.RelativePath}) require.NoError(t, err) require.DirExists(t, newDirectory) defer func() { require.NoError(t, os.RemoveAll(newDirectory)) }() @@ -42,7 +43,8 @@ func TestRenameRepositorySuccess(t *testing.T) { } func TestRenameRepositoryDestinationExists(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -69,7 +71,8 @@ func TestRenameRepositoryDestinationExists(t *testing.T) { } func TestRenameRepositoryInvalidRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/repack_test.go b/internal/gitaly/service/repository/repack_test.go index f84f99e97..08b1fa01b 100644 --- a/internal/gitaly/service/repository/repack_test.go +++ b/internal/gitaly/service/repository/repack_test.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git/gittest" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/labkit/log" @@ -22,7 +23,8 @@ import ( ) func TestRepackIncrementalSuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -62,7 +64,8 @@ func TestRepackIncrementalCollectLogStatistics(t *testing.T) { defer cancel() ctx = ctxlogrus.ToContext(ctx, log.WithField("test", "logging")) - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -78,7 +81,8 @@ func TestRepackIncrementalCollectLogStatistics(t *testing.T) { } func TestRepackLocal(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -117,7 +121,8 @@ func TestRepackLocal(t *testing.T) { } func TestRepackIncrementalFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -145,7 +150,8 @@ func TestRepackIncrementalFailure(t *testing.T) { } func TestRepackFullSuccess(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -211,7 +217,8 @@ func TestRepackFullCollectLogStatistics(t *testing.T) { defer cancel() ctx = ctxlogrus.ToContext(ctx, log.WithField("test", "logging")) - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -253,7 +260,8 @@ func doBitmapsContainHashCache(t *testing.T, bitmapPaths []string) { } func TestRepackFullFailure(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -281,7 +289,8 @@ func TestRepackFullFailure(t *testing.T) { } func TestRepackFullDeltaIslands(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go index c08de75b6..852335090 100644 --- a/internal/gitaly/service/repository/replicate_test.go +++ b/internal/gitaly/service/repository/replicate_test.go @@ -13,7 +13,6 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/repository" - "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -80,7 +79,8 @@ func TestReplicateRepository(t *testing.T) { }) require.NoError(t, err) - targetRepoPath, err := helper.GetRepoPath(&targetRepo) + locator := config.NewLocator(config.Config) + targetRepoPath, err := locator.GetRepoPath(&targetRepo) require.NoError(t, err) testhelper.MustRunCommand(t, nil, "git", "-C", targetRepoPath, "fsck") @@ -178,7 +178,8 @@ func TestReplicateRepositoryInvalidArguments(t *testing.T) { }, } - serverSocketPath, stop := repository.RunRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := repository.RunRepoServer(t, locator) defer stop() client, conn := repository.NewRepositoryClient(t, serverSocketPath) @@ -220,6 +221,8 @@ func TestReplicateRepository_BadRepository(t *testing.T) { server, serverSocketPath := runFullServer(t) defer server.Stop() + locator := config.NewLocator(config.Config) + testRepo, _, cleanupRepo := testhelper.NewTestRepo(t) defer cleanupRepo() @@ -231,7 +234,7 @@ func TestReplicateRepository_BadRepository(t *testing.T) { targetRepo := *testRepo targetRepo.StorageName = "replica" - targetRepoPath, err := helper.GetPath(&targetRepo) + targetRepoPath, err := locator.GetPath(&targetRepo) require.NoError(t, err) require.NoError(t, os.MkdirAll(targetRepoPath, 0755)) @@ -277,6 +280,8 @@ func TestReplicateRepository_FailedFetchInternalRemote(t *testing.T) { server, serverSocketPath := runServerWithBadFetchInternalRemote(t) defer server.Stop() + locator := config.NewLocator(config.Config) + testRepo, _, cleanupRepo := testhelper.NewTestRepo(t) defer cleanupRepo() @@ -288,7 +293,7 @@ func TestReplicateRepository_FailedFetchInternalRemote(t *testing.T) { targetRepo := *testRepo targetRepo.StorageName = "replica" - targetRepoPath, err := helper.GetPath(&targetRepo) + targetRepoPath, err := locator.GetPath(&targetRepo) require.NoError(t, err) require.NoError(t, os.MkdirAll(targetRepoPath, 0755)) diff --git a/internal/gitaly/service/repository/repository_test.go b/internal/gitaly/service/repository/repository_test.go index 7f914d886..156350b91 100644 --- a/internal/gitaly/service/repository/repository_test.go +++ b/internal/gitaly/service/repository/repository_test.go @@ -31,7 +31,8 @@ func TestRepositoryExists(t *testing.T) { }(config.Config.Storages) config.Config.Storages = testStorages - serverSocketPath, stop := runRepoServer(t, testhelper.WithStorages([]string{"default", "other", "broken"})) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator, testhelper.WithStorages([]string{"default", "other", "broken"})) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -121,7 +122,8 @@ func TestRepositoryExists(t *testing.T) { } func TestSuccessfulHasLocalBranches(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -176,7 +178,8 @@ func TestSuccessfulHasLocalBranches(t *testing.T) { } func TestFailedHasLocalBranches(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/restore_custom_hooks_test.go b/internal/gitaly/service/repository/restore_custom_hooks_test.go index d4eb5ca06..b3f554307 100644 --- a/internal/gitaly/service/repository/restore_custom_hooks_test.go +++ b/internal/gitaly/service/repository/restore_custom_hooks_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" @@ -15,7 +15,8 @@ import ( ) func TestSuccessfullRestoreCustomHooksRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -32,7 +33,7 @@ func TestSuccessfullRestoreCustomHooksRequest(t *testing.T) { require.NoError(t, err) - repoPath, err := helper.GetPath(testRepo) + repoPath, err := locator.GetPath(testRepo) require.NoError(t, err) defer os.RemoveAll(repoPath) request := &gitalypb.RestoreCustomHooksRequest{Repository: testRepo} @@ -59,7 +60,8 @@ func TestSuccessfullRestoreCustomHooksRequest(t *testing.T) { } func TestFailedRestoreCustomHooksDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -78,7 +80,8 @@ func TestFailedRestoreCustomHooksDueToValidations(t *testing.T) { } func TestFailedRestoreCustomHooksDueToBadTar(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -95,7 +98,7 @@ func TestFailedRestoreCustomHooksDueToBadTar(t *testing.T) { require.NoError(t, err) - repoPath, err := helper.GetPath(testRepo) + repoPath, err := locator.GetPath(testRepo) require.NoError(t, err) defer os.RemoveAll(repoPath) request := &gitalypb.RestoreCustomHooksRequest{Repository: testRepo} diff --git a/internal/gitaly/service/repository/search_files_test.go b/internal/gitaly/service/repository/search_files_test.go index fa0611e73..3aba2e20c 100644 --- a/internal/gitaly/service/repository/search_files_test.go +++ b/internal/gitaly/service/repository/search_files_test.go @@ -81,7 +81,8 @@ func TestSearchFilesByContentSuccessful(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -153,7 +154,8 @@ func TestSearchFilesByContentLargeFile(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -269,7 +271,8 @@ func TestSearchFilesByNameSuccessful(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/size_test.go b/internal/gitaly/service/repository/size_test.go index ff28183ff..2e0f0668c 100644 --- a/internal/gitaly/service/repository/size_test.go +++ b/internal/gitaly/service/repository/size_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -14,7 +15,8 @@ import ( const testRepoMinSizeKB = 10000 func TestSuccessfulRepositorySizeRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -36,7 +38,8 @@ func TestSuccessfulRepositorySizeRequest(t *testing.T) { } func TestFailedRepositorySizeRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -66,7 +69,8 @@ func TestFailedRepositorySizeRequest(t *testing.T) { } func TestSuccessfulGetObjectDirectorySizeRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/snapshot_test.go b/internal/gitaly/service/repository/snapshot_test.go index 87794021b..08faf0feb 100644 --- a/internal/gitaly/service/repository/snapshot_test.go +++ b/internal/gitaly/service/repository/snapshot_test.go @@ -18,7 +18,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/catfile" "gitlab.com/gitlab-org/gitaly/internal/gitaly/archive" - "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" @@ -26,7 +26,8 @@ import ( ) func getSnapshot(t *testing.T, req *gitalypb.GetSnapshotRequest) ([]byte, error) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -172,6 +173,8 @@ func TestGetSnapshotWithDedupeSoftFailures(t *testing.T) { testRepo, repoPath, cleanup := testhelper.NewTestRepoWithWorktree(t) defer cleanup() + locator := config.NewLocator(config.Config) + // write alternates file to point to alternates objects folder that doesn't exist alternateObjDir := "./alt-objects" alternateObjPath := filepath.Join(repoPath, ".git", alternateObjDir) @@ -185,7 +188,7 @@ func TestGetSnapshotWithDedupeSoftFailures(t *testing.T) { require.NoError(t, os.Remove(alternatesPath)) // write alternates file to point outside storage root - storageRoot, err := helper.GetStorageByName(testRepo.GetStorageName()) + storageRoot, err := locator.GetStorageByName(testRepo.GetStorageName()) require.NoError(t, err) require.NoError(t, ioutil.WriteFile(alternatesPath, []byte(filepath.Join(storageRoot, "..")), 0600)) diff --git a/internal/gitaly/service/repository/squash_in_progress_test.go b/internal/gitaly/service/repository/squash_in_progress_test.go index 72f0beda7..429efbfba 100644 --- a/internal/gitaly/service/repository/squash_in_progress_test.go +++ b/internal/gitaly/service/repository/squash_in_progress_test.go @@ -5,13 +5,15 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestSuccessfulIsSquashInProgressRequest(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -62,7 +64,8 @@ func TestSuccessfulIsSquashInProgressRequest(t *testing.T) { } func TestFailedIsSquashInProgressRequestDueToValidations(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go index e6b32798e..8a7582e38 100644 --- a/internal/gitaly/service/repository/testhelper_test.go +++ b/internal/gitaly/service/repository/testhelper_test.go @@ -17,6 +17,7 @@ import ( "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver" mcache "gitlab.com/gitlab-org/gitaly/internal/middleware/cache" "gitlab.com/gitlab-org/gitaly/internal/praefect/protoregistry" + "gitlab.com/gitlab-org/gitaly/internal/storage" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc" @@ -65,7 +66,7 @@ func newSecureRepoClient(t *testing.T, serverSocketPath string, pool *x509.CertP var NewSecureRepoClient = newSecureRepoClient -func runRepoServerWithConfig(t *testing.T, cfg config.Cfg, opts ...testhelper.TestServerOpt) (string, func()) { +func runRepoServerWithConfig(t *testing.T, cfg config.Cfg, locator storage.Locator, opts ...testhelper.TestServerOpt) (string, func()) { streamInt := []grpc.StreamServerInterceptor{ mcache.StreamInvalidator(dcache.LeaseKeyer{}, protoregistry.GitalyProtoPreregistered), } @@ -75,7 +76,7 @@ func runRepoServerWithConfig(t *testing.T, cfg config.Cfg, opts ...testhelper.Te srv := testhelper.NewServerWithAuth(t, streamInt, unaryInt, cfg.Auth.Token, opts...) - gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), NewServer(cfg, RubyServer, config.NewLocator(cfg), config.GitalyInternalSocketPath())) + gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), NewServer(cfg, RubyServer, locator, config.GitalyInternalSocketPath())) reflection.Register(srv.GrpcServer()) require.NoError(t, srv.Start()) @@ -83,12 +84,13 @@ func runRepoServerWithConfig(t *testing.T, cfg config.Cfg, opts ...testhelper.Te return "unix://" + srv.Socket(), srv.Stop } -func runRepoServer(t *testing.T, opts ...testhelper.TestServerOpt) (string, func()) { - return runRepoServerWithConfig(t, config.Config, opts...) +func runRepoServer(t *testing.T, locator storage.Locator, opts ...testhelper.TestServerOpt) (string, func()) { + return runRepoServerWithConfig(t, config.Config, locator, opts...) } func TestRepoNoAuth(t *testing.T) { - socket, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + socket, stop := runRepoServer(t, locator) defer stop() connOpts := []grpc.DialOption{ diff --git a/internal/gitaly/service/repository/write_ref_test.go b/internal/gitaly/service/repository/write_ref_test.go index d84f8ec50..5f819dc39 100644 --- a/internal/gitaly/service/repository/write_ref_test.go +++ b/internal/gitaly/service/repository/write_ref_test.go @@ -6,13 +6,15 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" ) func TestWriteRefSuccessful(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) @@ -78,7 +80,8 @@ func TestWriteRefSuccessful(t *testing.T) { } func TestWriteRefValidationError(t *testing.T) { - serverSocketPath, stop := runRepoServer(t) + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator) defer stop() client, conn := newRepositoryClient(t, serverSocketPath) |