diff options
Diffstat (limited to 'internal')
21 files changed, 34 insertions, 53 deletions
diff --git a/internal/backup/backup_test.go b/internal/backup/backup_test.go index ce85f235f..0900da2a6 100644 --- a/internal/backup/backup_test.go +++ b/internal/backup/backup_test.go @@ -28,7 +28,7 @@ func TestFilesystem_BackupRepository(t *testing.T) { require.NoError(t, ioutil.WriteFile(filepath.Join(hooksRepoPath, "custom_hooks/pre-commit.sample"), []byte("Some hooks"), os.ModePerm)) noHooksRepo, _, _ := gittest.CloneRepoAtStorage(t, cfg.Storages[0], "no-hooks") - emptyRepo, _, _ := gittest.InitBareRepoAt(t, cfg.Storages[0]) + emptyRepo, _, _ := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) nonexistentRepo := *emptyRepo nonexistentRepo.RelativePath = "nonexistent" diff --git a/internal/git/gittest/repo.go b/internal/git/gittest/repo.go index e8b1c8113..0a3f0c036 100644 --- a/internal/git/gittest/repo.go +++ b/internal/git/gittest/repo.go @@ -38,24 +38,14 @@ func InitRepoDir(t testing.TB, storagePath, relativePath string) *gitalypb.Repos } } -// InitBareRepo creates a new bare repository -func InitBareRepo(t testing.TB) (*gitalypb.Repository, string, func()) { - return initRepoAt(t, true, config.Storage{Name: "default", Path: testhelper.GitlabTestStoragePath()}) -} - // InitBareRepoAt creates a new bare repository in the storage -func InitBareRepoAt(t testing.TB, storage config.Storage) (*gitalypb.Repository, string, func()) { - return initRepoAt(t, true, storage) -} - -// InitRepoWithWorktree creates a new repository with a worktree -func InitRepoWithWorktree(t testing.TB) (*gitalypb.Repository, string, func()) { - return initRepoAt(t, false, config.Storage{Name: "default", Path: testhelper.GitlabTestStoragePath()}) +func InitBareRepoAt(t testing.TB, cfg config.Cfg, storage config.Storage) (*gitalypb.Repository, string, func()) { + return initRepoAt(t, cfg, true, storage) } // InitRepoWithWorktreeAtStorage creates a new repository with a worktree in the storage -func InitRepoWithWorktreeAtStorage(t testing.TB, storage config.Storage) (*gitalypb.Repository, string, func()) { - return initRepoAt(t, false, storage) +func InitRepoWithWorktreeAtStorage(t testing.TB, cfg config.Cfg, storage config.Storage) (*gitalypb.Repository, string, func()) { + return initRepoAt(t, cfg, false, storage) } // NewObjectPoolName returns a random pool repository name in format @@ -86,7 +76,7 @@ func newDiskHash(t testing.TB) string { return filepath.Join(b[0:2], b[2:4], b) } -func initRepoAt(t testing.TB, bare bool, storage config.Storage) (*gitalypb.Repository, string, func()) { +func initRepoAt(t testing.TB, cfg config.Cfg, bare bool, storage config.Storage) (*gitalypb.Repository, string, func()) { relativePath := NewRepositoryName(t, bare) repoPath := filepath.Join(storage.Path, relativePath) @@ -95,7 +85,7 @@ func initRepoAt(t testing.TB, bare bool, storage config.Storage) (*gitalypb.Repo args = append(args, "--bare") } - testhelper.MustRunCommand(t, nil, "git", append(args, repoPath)...) + Exec(t, cfg, append(args, repoPath)...) repo := InitRepoDir(t, storage.Path, relativePath) repo.StorageName = storage.Name diff --git a/internal/git/gittest/repository_suite.go b/internal/git/gittest/repository_suite.go index 8a14cac24..3c6bb0f8f 100644 --- a/internal/git/gittest/repository_suite.go +++ b/internal/git/gittest/repository_suite.go @@ -89,7 +89,7 @@ func testRepositoryHasBranches(t *testing.T, cfg config.Cfg, getRepository func( ctx, cancel := testhelper.Context() defer cancel() - pbRepo, repoPath, cleanup := InitBareRepoAt(t, cfg.Storages[0]) + pbRepo, repoPath, cleanup := InitBareRepoAt(t, cfg, cfg.Storages[0]) defer cleanup() repo := getRepository(t, pbRepo) diff --git a/internal/git/localrepo/config_test.go b/internal/git/localrepo/config_test.go index f945c4e6a..f44bf682e 100644 --- a/internal/git/localrepo/config_test.go +++ b/internal/git/localrepo/config_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/internal/git" "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/internal/testhelper/testcfg" @@ -21,21 +20,13 @@ func setupRepoConfig(t *testing.T) (Config, string) { cfg := testcfg.Build(t) - repoProto, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + repoProto, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) t.Cleanup(cleanup) repo := New(git.NewExecCommandFactory(cfg), repoProto, cfg) return repo.Config(), repoPath } -func TestRepo_Config(t *testing.T) { - bareRepo, _, cleanup := gittest.InitBareRepo(t) - defer cleanup() - - repo := New(nil, bareRepo, config.Cfg{}) - require.Equal(t, Config{repo: repo}, repo.Config()) -} - func TestBuildConfigAddOptsFlags(t *testing.T) { for _, tc := range []struct { desc string diff --git a/internal/git/localrepo/objects_test.go b/internal/git/localrepo/objects_test.go index a25305ba7..18d18ca84 100644 --- a/internal/git/localrepo/objects_test.go +++ b/internal/git/localrepo/objects_test.go @@ -30,7 +30,7 @@ func setupRepo(t *testing.T, bare bool) (*Repo, string) { var repoPath string var repoCleanUp func() if bare { - repoProto, repoPath, repoCleanUp = gittest.InitBareRepoAt(t, cfg.Storages[0]) + repoProto, repoPath, repoCleanUp = gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) } else { repoProto, repoPath, repoCleanUp = gittest.CloneRepoAtStorage(t, cfg.Storages[0], t.Name()) } diff --git a/internal/git/localrepo/remote_test.go b/internal/git/localrepo/remote_test.go index 14659e816..bd424ecdf 100644 --- a/internal/git/localrepo/remote_test.go +++ b/internal/git/localrepo/remote_test.go @@ -32,7 +32,7 @@ func setupRepoRemote(t *testing.T, bare bool) (Remote, string) { var repoPath string var repoCleanUp func() if bare { - repoProto, repoPath, repoCleanUp = gittest.InitBareRepoAt(t, cfg.Storages[0]) + repoProto, repoPath, repoCleanUp = gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) } else { repoProto, repoPath, repoCleanUp = gittest.CloneRepoAtStorage(t, cfg.Storages[0], t.Name()) } @@ -308,7 +308,7 @@ func TestRepo_FetchRemote(t *testing.T) { initBareWithRemote := func(t *testing.T, remote string) (*Repo, string, testhelper.Cleanup) { t.Helper() - testRepo, testRepoPath, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + testRepo, testRepoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) cmd := exec.Command(cfg.Git.BinPath, "-C", testRepoPath, "remote", "add", remote, remoteRepoPath) err := cmd.Run() @@ -524,7 +524,7 @@ if [ -z ${GIT_SSH_COMMAND+x} ];then rm -f %q ;else echo -n "$GIT_SSH_COMMAND" > }, } { t.Run(tc.desc, func(t *testing.T) { - pushRepoPb, pushRepoPath, _ := gittest.InitBareRepoAt(t, cfg.Storages[0]) + pushRepoPb, pushRepoPath, _ := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) pushRepo := New(git.NewExecCommandFactory(cfg), pushRepoPb, cfg) if tc.setupPushRepo != nil { diff --git a/internal/git/stats/profile_test.go b/internal/git/stats/profile_test.go index 491cc86e4..0419b90c0 100644 --- a/internal/git/stats/profile_test.go +++ b/internal/git/stats/profile_test.go @@ -16,7 +16,7 @@ import ( func TestRepositoryProfile(t *testing.T) { cfg := testcfg.Build(t) - testRepo, testRepoPath, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + testRepo, testRepoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) defer cleanup() ctx, cancel := testhelper.Context() diff --git a/internal/git2go/apply_test.go b/internal/git2go/apply_test.go index 17aadd76d..47bcd39e2 100644 --- a/internal/git2go/apply_test.go +++ b/internal/git2go/apply_test.go @@ -19,7 +19,7 @@ func TestExecutor_Apply(t *testing.T) { cfg := testcfg.Build(t) testhelper.ConfigureGitalyGit2GoBin(t, cfg) - repoProto, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + repoProto, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) t.Cleanup(cleanup) repo := localrepo.New(git.NewExecCommandFactory(cfg), repoProto, cfg) diff --git a/internal/git2go/commit_test.go b/internal/git2go/commit_test.go index 68916b759..26c8480fc 100644 --- a/internal/git2go/commit_test.go +++ b/internal/git2go/commit_test.go @@ -56,7 +56,7 @@ func TestExecutor_Commit(t *testing.T) { cfg := testcfg.Build(t) testhelper.ConfigureGitalyGit2GoBin(t, cfg) - repoProto, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + repoProto, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) t.Cleanup(cleanup) repo := localrepo.New(git.NewExecCommandFactory(cfg), repoProto, cfg) diff --git a/internal/gitaly/service/commit/count_commits_test.go b/internal/gitaly/service/commit/count_commits_test.go index a69e0700b..8b23acfc6 100644 --- a/internal/gitaly/service/commit/count_commits_test.go +++ b/internal/gitaly/service/commit/count_commits_test.go @@ -16,7 +16,7 @@ import ( func TestSuccessfulCountCommitsRequest(t *testing.T) { cfg, repo1, _, client := setupCommitServiceWithRepo(t, true) - repo2, repo2Path, cleanupFn := gittest.InitRepoWithWorktreeAtStorage(t, cfg.Storages[0]) + repo2, repo2Path, cleanupFn := gittest.InitRepoWithWorktreeAtStorage(t, cfg, cfg.Storages[0]) t.Cleanup(cleanupFn) committerName := "Scrooge McDuck" diff --git a/internal/gitaly/service/commit/count_diverging_commits_test.go b/internal/gitaly/service/commit/count_diverging_commits_test.go index 96ab6c959..89a2b87fc 100644 --- a/internal/gitaly/service/commit/count_diverging_commits_test.go +++ b/internal/gitaly/service/commit/count_diverging_commits_test.go @@ -26,7 +26,7 @@ func createRepoWithDivergentBranches(t *testing.T, cfg config.Cfg, leftCommits, f h */ - repo, worktreePath, cleanupFn := gittest.InitRepoWithWorktreeAtStorage(t, cfg.Storages[0]) + repo, worktreePath, cleanupFn := gittest.InitRepoWithWorktreeAtStorage(t, cfg, cfg.Storages[0]) committerName := "Scrooge McDuck" committerEmail := "scrooge@mcduck.com" diff --git a/internal/gitaly/service/commit/list_files_test.go b/internal/gitaly/service/commit/list_files_test.go index bcfe2fdf2..38eba7e25 100644 --- a/internal/gitaly/service/commit/list_files_test.go +++ b/internal/gitaly/service/commit/list_files_test.go @@ -135,7 +135,7 @@ func TestListFiles_success(t *testing.T) { func TestListFiles_unbornBranch(t *testing.T) { cfg, _, _, client := setupCommitServiceWithRepo(t, true) - repo, _, _ := gittest.InitBareRepoAt(t, cfg.Storages[0]) + repo, _, _ := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) tests := []struct { desc string diff --git a/internal/gitaly/service/operations/commit_files_test.go b/internal/gitaly/service/operations/commit_files_test.go index c769d7460..27c06e124 100644 --- a/internal/gitaly/service/operations/commit_files_test.go +++ b/internal/gitaly/service/operations/commit_files_test.go @@ -46,7 +46,7 @@ func TestUserCommitFiles(t *testing.T) { // repository there on every test run. This allows us to use deterministic // paths in the tests. - startRepo, startRepoPath, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + startRepo, startRepoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) t.Cleanup(cleanup) pathToStorage := strings.TrimSuffix(startRepoPath, startRepo.RelativePath) @@ -941,7 +941,7 @@ func TestUserCommitFilesStableCommitID(t *testing.T) { ctx, cfg, _, _, client := setupOperationsService(t, ctx) - repoProto, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + repoProto, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) defer cleanup() repo := localrepo.New(git.NewExecCommandFactory(cfg), repoProto, cfg) @@ -1000,7 +1000,7 @@ func TestSuccessfulUserCommitFilesRequest(t *testing.T) { ctx, cfg, repo, repoPath, client := setupOperationsService(t, ctx) - newRepo, newRepoPath, newRepoCleanupFn := gittest.InitBareRepoAt(t, cfg.Storages[0]) + newRepo, newRepoPath, newRepoCleanupFn := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) defer newRepoCleanupFn() filePath := "héllo/wörld" @@ -1254,7 +1254,7 @@ func testSuccessfulUserCommitFilesRemoteRepositoryRequest(setHeader func(header repo := localrepo.New(gitCmdFactory, repoProto, cfg) - newRepoProto, _, newRepoCleanupFn := gittest.InitBareRepoAt(t, cfg.Storages[0]) + newRepoProto, _, newRepoCleanupFn := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) defer newRepoCleanupFn() newRepo := localrepo.New(gitCmdFactory, newRepoProto, cfg) @@ -1291,7 +1291,7 @@ func TestSuccessfulUserCommitFilesRequestWithSpecialCharactersInSignature(t *tes ctx, cfg, _, _, client := setupOperationsService(t, ctx) - repoProto, _, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + repoProto, _, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) defer cleanup() repo := localrepo.New(git.NewExecCommandFactory(cfg), repoProto, cfg) diff --git a/internal/gitaly/service/operations/revert_test.go b/internal/gitaly/service/operations/revert_test.go index 84266ce0f..1f1458b27 100644 --- a/internal/gitaly/service/operations/revert_test.go +++ b/internal/gitaly/service/operations/revert_test.go @@ -246,7 +246,7 @@ func testServerUserRevertSuccessfulIntoNewRepo(t *testing.T, ctx context.Context masterHeadCommit, err := startRepo.ReadCommit(ctx, "master") require.NoError(t, err) - repoProto, _, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + repoProto, _, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) defer cleanup() repo := localrepo.New(gitCmdFactory, repoProto, cfg) diff --git a/internal/gitaly/service/operations/submodules_test.go b/internal/gitaly/service/operations/submodules_test.go index 8142f2183..706245a04 100644 --- a/internal/gitaly/service/operations/submodules_test.go +++ b/internal/gitaly/service/operations/submodules_test.go @@ -370,7 +370,7 @@ func testFailedUserUpdateSubmoduleRequestDueToRepositoryEmpty(t *testing.T, cfg func testFailedUserUpdateSubmoduleRequestDueToRepositoryEmptyFeatured(t *testing.T, ctx context.Context, cfg config.Cfg, rubySrv *rubyserver.Server) { ctx, _, _, _, client := setupOperationsServiceWithRuby(t, ctx, cfg, rubySrv) - repo, _, cleanup := gittest.InitRepoWithWorktreeAtStorage(t, cfg.Storages[0]) + repo, _, cleanup := gittest.InitRepoWithWorktreeAtStorage(t, cfg, cfg.Storages[0]) t.Cleanup(cleanup) request := &gitalypb.UserUpdateSubmoduleRequest{ diff --git a/internal/gitaly/service/remote/find_remote_root_ref_test.go b/internal/gitaly/service/remote/find_remote_root_ref_test.go index c30fccb53..e9bd8aec2 100644 --- a/internal/gitaly/service/remote/find_remote_root_ref_test.go +++ b/internal/gitaly/service/remote/find_remote_root_ref_test.go @@ -58,7 +58,7 @@ func TestFindRemoteRootRefWithUnbornRemoteHead(t *testing.T) { // We're creating an empty repository. Empty repositories do have a HEAD set up, but they // point to an unborn branch because the default branch hasn't yet been created. - _, clientRepoPath, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + _, clientRepoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) defer cleanup() testhelper.MustRunCommand(t, nil, "git", "-C", remoteRepoPath, "remote", "add", "foo", "file://"+clientRepoPath) diff --git a/internal/gitaly/service/remote/update_remote_mirror_test.go b/internal/gitaly/service/remote/update_remote_mirror_test.go index 9056e11c3..be277ba4d 100644 --- a/internal/gitaly/service/remote/update_remote_mirror_test.go +++ b/internal/gitaly/service/remote/update_remote_mirror_test.go @@ -350,10 +350,10 @@ func testUpdateRemoteMirrorFeatured(t *testing.T, ctx context.Context, cfg confi }, } { t.Run(tc.desc, func(t *testing.T) { - _, mirrorRepoPath, cleanMirrorRepo := gittest.InitBareRepoAt(t, cfg.Storages[0]) + _, mirrorRepoPath, cleanMirrorRepo := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) defer cleanMirrorRepo() - sourceRepoPb, sourceRepoPath, cleanSourceRepo := gittest.InitBareRepoAt(t, cfg.Storages[0]) + sourceRepoPb, sourceRepoPath, cleanSourceRepo := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) defer cleanSourceRepo() // configure the mirror repository as a remote in the source diff --git a/internal/gitaly/service/repository/calculate_checksum_test.go b/internal/gitaly/service/repository/calculate_checksum_test.go index e4d445e9c..f5a49a320 100644 --- a/internal/gitaly/service/repository/calculate_checksum_test.go +++ b/internal/gitaly/service/repository/calculate_checksum_test.go @@ -67,7 +67,7 @@ func TestRefWhitelist(t *testing.T) { func TestEmptyRepositoryCalculateChecksum(t *testing.T) { cfg, client := setupRepositoryServiceWithoutRepo(t) - repo, _, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + repo, _, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) t.Cleanup(cleanup) request := &gitalypb.CalculateChecksumRequest{Repository: repo} @@ -82,7 +82,7 @@ func TestEmptyRepositoryCalculateChecksum(t *testing.T) { func TestBrokenRepositoryCalculateChecksum(t *testing.T) { cfg, client := setupRepositoryServiceWithoutRepo(t) - repo, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg.Storages[0]) + repo, repoPath, cleanup := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) t.Cleanup(cleanup) // Force an empty HEAD file diff --git a/internal/gitaly/service/repository/optimize_test.go b/internal/gitaly/service/repository/optimize_test.go index 45f5933ca..5c1d22407 100644 --- a/internal/gitaly/service/repository/optimize_test.go +++ b/internal/gitaly/service/repository/optimize_test.go @@ -89,7 +89,7 @@ func TestOptimizeRepository(t *testing.T) { require.Equal(t, getNewestPackfileModtime(t, repoPath), newestsPackfileTime, "there should not have been a new packfile created") - testRepo, testRepoPath, cleanupBare := gittest.InitBareRepoAt(t, cfg.Storages[0]) + testRepo, testRepoPath, cleanupBare := gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) t.Cleanup(cleanupBare) blobs := 10 diff --git a/internal/gitaly/service/wiki/find_page_test.go b/internal/gitaly/service/wiki/find_page_test.go index 81f5e1c2a..6780fa3f3 100644 --- a/internal/gitaly/service/wiki/find_page_test.go +++ b/internal/gitaly/service/wiki/find_page_test.go @@ -455,7 +455,7 @@ func TestInvalidWikiFindPageRequestRevision(t *testing.T) { } func testSuccessfulWikiFindPageRequestWithTrailers(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) { - wikiRepo, worktreePath, cleanupFn := gittest.InitRepoWithWorktreeAtStorage(t, cfg.Storages[0]) + wikiRepo, worktreePath, cleanupFn := gittest.InitRepoWithWorktreeAtStorage(t, cfg, cfg.Storages[0]) defer cleanupFn() committerName := "Scróoge McDuck" // Include UTF-8 to ensure encoding is handled diff --git a/internal/gitaly/service/wiki/testhelper_test.go b/internal/gitaly/service/wiki/testhelper_test.go index fce7bfdef..38ba459ba 100644 --- a/internal/gitaly/service/wiki/testhelper_test.go +++ b/internal/gitaly/service/wiki/testhelper_test.go @@ -184,7 +184,7 @@ func updateWikiPage(t *testing.T, client gitalypb.WikiServiceClient, wikiRepo *g } func setupWikiRepo(t *testing.T, cfg config.Cfg) (*gitalypb.Repository, string, func()) { - return gittest.InitBareRepoAt(t, cfg.Storages[0]) + return gittest.InitBareRepoAt(t, cfg, cfg.Storages[0]) } func sendBytes(data []byte, chunkSize int, sender func([]byte) error) (int, error) { |