diff options
Diffstat (limited to 'internal/git')
-rw-r--r-- | internal/git/gittest/repo.go | 22 | ||||
-rw-r--r-- | internal/git/gittest/repository_suite.go | 2 | ||||
-rw-r--r-- | internal/git/localrepo/config_test.go | 11 | ||||
-rw-r--r-- | internal/git/localrepo/objects_test.go | 2 | ||||
-rw-r--r-- | internal/git/localrepo/remote_test.go | 6 | ||||
-rw-r--r-- | internal/git/stats/profile_test.go | 2 |
6 files changed, 13 insertions, 32 deletions
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() |