diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-05 13:56:55 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-11 13:35:43 +0300 |
commit | 24a3bead79daada06a70d58465cbf9fa9f38954b (patch) | |
tree | a3a7121e03f34a6821bc14c30a200e33cc123b3e | |
parent | 79b8b738faf547ac112360b8ff19ede3964763e3 (diff) |
gittest: Convert callers of InitRepo to use CreateRepository
Convert all callers of InitRepo to use CreateRepository.
38 files changed, 392 insertions, 149 deletions
diff --git a/cmd/gitaly-git2go/merge_test.go b/cmd/gitaly-git2go/merge_test.go index aedc6e9bf..1ae181c2f 100644 --- a/cmd/gitaly-git2go/merge_test.go +++ b/cmd/gitaly-git2go/merge_test.go @@ -418,7 +418,9 @@ func TestMerge_recursive(t *testing.T) { testcfg.BuildGitalyGit2Go(t, cfg) executor := buildExecutor(t, cfg) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) base := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( gittest.TreeEntry{Path: "base", Content: "base\n", Mode: "100644"}, diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go index f223e039e..949b7f6a4 100644 --- a/cmd/gitaly-hooks/hooks_test.go +++ b/cmd/gitaly-hooks/hooks_test.go @@ -273,7 +273,9 @@ func TestHooksUpdate(t *testing.T) { } func testHooksUpdate(t *testing.T, ctx context.Context, cfg config.Cfg, glValues glHookValues) { - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) refval, oldval, newval := "refval", strings.Repeat("a", 40), strings.Repeat("b", 40) diff --git a/cmd/praefect/subcmd_list_untracked_repositories_test.go b/cmd/praefect/subcmd_list_untracked_repositories_test.go index 399939e87..71180d856 100644 --- a/cmd/praefect/subcmd_list_untracked_repositories_test.go +++ b/cmd/praefect/subcmd_list_untracked_repositories_test.go @@ -95,9 +95,15 @@ func TestListUntrackedRepositories_Exec(t *testing.T) { require.NoError(t, fs.Parse([]string{"-older-than", "4h"})) // Repositories not managed by praefect. - repo1, repo1Path := gittest.InitRepo(t, g1Cfg, g1Cfg.Storages[0]) - repo2, repo2Path := gittest.InitRepo(t, g1Cfg, g1Cfg.Storages[0]) - _, _ = gittest.InitRepo(t, g2Cfg, g2Cfg.Storages[0]) + repo1, repo1Path := gittest.CreateRepository(ctx, t, g1Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + repo2, repo2Path := gittest.CreateRepository(ctx, t, g1Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + _, _ = gittest.CreateRepository(ctx, t, g2Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) require.NoError(t, os.Chtimes( repo1Path, diff --git a/internal/git/catfile/cache_test.go b/internal/git/catfile/cache_test.go index 0ac225444..89bbec75a 100644 --- a/internal/git/catfile/cache_test.go +++ b/internal/git/catfile/cache_test.go @@ -20,11 +20,15 @@ import ( ) func TestProcesses_add(t *testing.T) { + ctx := testhelper.Context(t) + const maxLen = 3 p := &processes{maxLen: maxLen} cfg := testcfg.Build(t) - repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) key0 := mustCreateKey(t, "0", repo) value0, cancel := mustCreateCacheable(t, cfg, repo) @@ -54,10 +58,14 @@ func TestProcesses_add(t *testing.T) { } func TestProcesses_addTwice(t *testing.T) { + ctx := testhelper.Context(t) + p := &processes{maxLen: 10} cfg := testcfg.Build(t) - repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) key0 := mustCreateKey(t, "0", repo) value0, cancel := mustCreateCacheable(t, cfg, repo) @@ -82,10 +90,14 @@ func TestProcesses_addTwice(t *testing.T) { } func TestProcesses_Checkout(t *testing.T) { + ctx := testhelper.Context(t) + p := &processes{maxLen: 10} cfg := testcfg.Build(t) - repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) key0 := mustCreateKey(t, "0", repo) value0, cancel := mustCreateCacheable(t, cfg, repo) @@ -110,10 +122,14 @@ func TestProcesses_Checkout(t *testing.T) { } func TestProcesses_EnforceTTL(t *testing.T) { + ctx := testhelper.Context(t) + p := &processes{maxLen: 10} cfg := testcfg.Build(t) - repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) cutoff := time.Now() @@ -153,13 +169,17 @@ func TestProcesses_EnforceTTL(t *testing.T) { } func TestCache_autoExpiry(t *testing.T) { + ctx := testhelper.Context(t) + monitorTicker := helper.NewManualTicker() c := newCache(time.Hour, 10, monitorTicker) defer c.Stop() cfg := testcfg.Build(t) - repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) // Add a process that has expired already. key0 := mustCreateKey(t, "0", repo) @@ -183,9 +203,12 @@ func TestCache_autoExpiry(t *testing.T) { } func TestCache_ObjectReader(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) repoExecutor := newRepoExecutor(t, cfg, repo) @@ -193,8 +216,6 @@ func TestCache_ObjectReader(t *testing.T) { cache := newCache(time.Hour, 10, helper.NewManualTicker()) defer cache.Stop() - ctx := testhelper.Context(t) - t.Run("uncacheable", func(t *testing.T) { // The context doesn't carry a session ID and is thus uncacheable. // The process should never get returned to the cache and must be @@ -282,9 +303,12 @@ func TestCache_ObjectReader(t *testing.T) { } func TestCache_ObjectInfoReader(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) repoExecutor := newRepoExecutor(t, cfg, repo) @@ -292,8 +316,6 @@ func TestCache_ObjectInfoReader(t *testing.T) { cache := newCache(time.Hour, 10, helper.NewManualTicker()) defer cache.Stop() - ctx := testhelper.Context(t) - t.Run("uncacheable", func(t *testing.T) { // The context doesn't carry a session ID and is thus uncacheable. // The process should never get returned to the cache and must be diff --git a/internal/git/catfile/object_info_reader_test.go b/internal/git/catfile/object_info_reader_test.go index 7d9614602..25d784bb7 100644 --- a/internal/git/catfile/object_info_reader_test.go +++ b/internal/git/catfile/object_info_reader_test.go @@ -108,7 +108,9 @@ func TestObjectInfoReader(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"), @@ -210,7 +212,9 @@ func TestObjectInfoReader_queue(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) blobOID := gittest.WriteBlob(t, cfg, repoPath, []byte("foobar")) blobInfo := ObjectInfo{ diff --git a/internal/git/catfile/object_reader_test.go b/internal/git/catfile/object_reader_test.go index 9aade3b47..83b3a46d0 100644 --- a/internal/git/catfile/object_reader_test.go +++ b/internal/git/catfile/object_reader_test.go @@ -21,7 +21,9 @@ func TestObjectReader_reader(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main"), @@ -131,7 +133,9 @@ func TestObjectReader_queue(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) foobarBlob := gittest.WriteBlob(t, cfg, repoPath, []byte("foobar")) barfooBlob := gittest.WriteBlob(t, cfg, repoPath, []byte("barfoo")) @@ -429,7 +433,9 @@ func TestObjectReader_replaceRefs(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) originalOID := gittest.WriteBlob(t, cfg, repoPath, []byte("original")) replacedOID := gittest.WriteBlob(t, cfg, repoPath, []byte("replaced")) diff --git a/internal/git/catfile/request_queue_test.go b/internal/git/catfile/request_queue_test.go index 9dede16aa..59f71e154 100644 --- a/internal/git/catfile/request_queue_test.go +++ b/internal/git/catfile/request_queue_test.go @@ -315,7 +315,9 @@ func TestRequestQueue_RequestRevision(t *testing.T) { func newInterceptedQueue(ctx context.Context, t *testing.T, script string) (ObjectReader, *requestQueue) { cfg := testcfg.Build(t) - repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) commandFactory := gittest.NewInterceptingCommandFactory(ctx, t, cfg, func(execEnv git.ExecutionEnvironment) string { return script diff --git a/internal/git/catfile/testhelper_test.go b/internal/git/catfile/testhelper_test.go index dc8b7994f..8d7e036a0 100644 --- a/internal/git/catfile/testhelper_test.go +++ b/internal/git/catfile/testhelper_test.go @@ -59,7 +59,9 @@ func setupObjectReader(t *testing.T, ctx context.Context) (config.Cfg, ObjectRea t.Helper() cfg := testcfg.Build(t) - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repoExecutor := newRepoExecutor(t, cfg, repo) cache := newCache(1*time.Hour, 1000, helper.NewTimerTicker(defaultEvictionInterval)) diff --git a/internal/git/command_factory_test.go b/internal/git/command_factory_test.go index 18467d5fd..5cff2406f 100644 --- a/internal/git/command_factory_test.go +++ b/internal/git/command_factory_test.go @@ -477,7 +477,9 @@ func TestExecCommandFactory_config(t *testing.T) { // Create a repository and remove its gitconfig to bring us into a known state where there // is no repo-level configuration that interferes with our test. - repo, repoDir := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, repoDir := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) require.NoError(t, os.Remove(filepath.Join(repoDir, "config"))) commonEnv := []string{ diff --git a/internal/git/gitpipe/catfile_info_test.go b/internal/git/gitpipe/catfile_info_test.go index ad0377d43..ac2a9cfb9 100644 --- a/internal/git/gitpipe/catfile_info_test.go +++ b/internal/git/gitpipe/catfile_info_test.go @@ -280,7 +280,9 @@ func TestCatfileInfoAllObjects(t *testing.T) { cfg := testcfg.Build(t) ctx := testhelper.Context(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) blob1 := gittest.WriteBlob(t, cfg, repoPath, []byte("foobar")) diff --git a/internal/git/gittest/testhelper_test.go b/internal/git/gittest/testhelper_test.go index dd24561fa..a39c196f6 100644 --- a/internal/git/gittest/testhelper_test.go +++ b/internal/git/gittest/testhelper_test.go @@ -23,6 +23,7 @@ func setup(t testing.TB) (config.Cfg, *gitalypb.Repository, string) { rootDir := testhelper.TempDir(t) + ctx := testhelper.Context(t) var cfg config.Cfg cfg.SocketPath = "it is a stub to bypass Validate method" @@ -52,7 +53,9 @@ func setup(t testing.TB) (config.Cfg, *gitalypb.Repository, string) { require.NoError(t, cfg.Validate()) - repo, repoPath := InitRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := CreateRepository(ctx, t, cfg, CreateRepositoryConfig{ + SkipCreationViaService: true, + }) return cfg, repo, repoPath } diff --git a/internal/git/housekeeping/clean_stale_data_test.go b/internal/git/housekeeping/clean_stale_data_test.go index b39565cbd..5a8e5f218 100644 --- a/internal/git/housekeeping/clean_stale_data_test.go +++ b/internal/git/housekeeping/clean_stale_data_test.go @@ -865,13 +865,15 @@ func TestRepositoryManager_CleanStaleData_missingRepo(t *testing.T) { } func TestRepositoryManager_CleanStaleData_unsetConfiguration(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) configPath := filepath.Join(repoPath, "config") - ctx := testhelper.Context(t) - require.NoError(t, os.WriteFile(configPath, []byte( `[core] repositoryformatversion = 0 @@ -923,7 +925,9 @@ func TestRepositoryManager_CleanStaleData_unsetConfigurationTransactional(t *tes ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) gittest.Exec(t, cfg, "-C", repoPath, "config", "http.some.extraHeader", "value") @@ -955,7 +959,9 @@ func TestRepositoryManager_CleanStaleData_pruneEmptyConfigSections(t *testing.T) ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) configPath := filepath.Join(repoPath, "config") @@ -1003,7 +1009,9 @@ func TestPruneEmptyConfigSections(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) configPath := filepath.Join(repoPath, "config") diff --git a/internal/git/housekeeping/objects_test.go b/internal/git/housekeeping/objects_test.go index 156a58ff2..33bc89e41 100644 --- a/internal/git/housekeeping/objects_test.go +++ b/internal/git/housekeeping/objects_test.go @@ -37,7 +37,9 @@ func TestRepackObjects(t *testing.T) { cfg := testcfg.Build(t) t.Run("no server info is written", func(t *testing.T) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) @@ -55,8 +57,9 @@ func TestRepackObjects(t *testing.T) { }) testRepoAndPool(t, "delta islands", func(t *testing.T, relativePath string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) diff --git a/internal/git/housekeeping/optimize_repository_test.go b/internal/git/housekeeping/optimize_repository_test.go index 886765b5a..da5488bad 100644 --- a/internal/git/housekeeping/optimize_repository_test.go +++ b/internal/git/housekeeping/optimize_repository_test.go @@ -30,6 +30,7 @@ import ( func TestNeedsRepacking(t *testing.T) { t.Parallel() + ctx := testhelper.Context(t) cfg := testcfg.Build(t) for _, tc := range []struct { @@ -42,8 +43,9 @@ func TestNeedsRepacking(t *testing.T) { { desc: "empty repo does nothing", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) return repoProto }, @@ -189,8 +191,9 @@ func TestNeedsRepacking(t *testing.T) { // Let's not go any further than this, we're thrashing the temporary directory. } { testRepoAndPool(t, fmt.Sprintf("packfile with %d bytes", tc.packfileSize), func(t *testing.T, relativePath string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) packDir := filepath.Join(repoPath, "objects", "pack") @@ -301,8 +304,9 @@ func TestNeedsRepacking(t *testing.T) { }, } { testRepoAndPool(t, tc.desc, func(t *testing.T, relativePath string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -379,8 +383,9 @@ func TestPackRefsIfNeeded(t *testing.T) { }, } { testRepoAndPool(t, fmt.Sprintf("packed-refs with %d bytes", tc.packedRefsSize), func(t *testing.T, relativePath string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -431,8 +436,12 @@ func TestPackRefsIfNeeded(t *testing.T) { func TestEstimateLooseObjectCount(t *testing.T) { t.Parallel() + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) t.Run("empty repository", func(t *testing.T) { @@ -511,7 +520,9 @@ func TestEstimateLooseObjectCount(t *testing.T) { } func TestOptimizeRepository(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) + txManager := transaction.NewManager(cfg, backchannel.NewRegistry()) for _, tc := range []struct { @@ -524,8 +535,9 @@ func TestOptimizeRepository(t *testing.T) { { desc: "empty repository does nothing", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) return repo }, @@ -680,8 +692,9 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 { desc: "loose refs get packed", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) for i := 0; i < 16; i++ { @@ -852,8 +865,9 @@ func TestPruneIfNeeded(t *testing.T) { cfg := testcfg.Build(t) testRepoAndPool(t, "empty repo does not prune", func(t *testing.T, relativePath string) { - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -863,8 +877,9 @@ func TestPruneIfNeeded(t *testing.T) { }) testRepoAndPool(t, "repo with single object does not prune", func(t *testing.T, relativePath string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -876,8 +891,9 @@ func TestPruneIfNeeded(t *testing.T) { }) testRepoAndPool(t, "repo with single 17-prefixed objects does not prune", func(t *testing.T, relativePath string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -890,8 +906,9 @@ func TestPruneIfNeeded(t *testing.T) { }) testRepoAndPool(t, "repo with four 17-prefixed objects does not prune", func(t *testing.T, relativePath string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -906,8 +923,9 @@ func TestPruneIfNeeded(t *testing.T) { }) testRepoAndPool(t, "repo with five 17-prefixed objects does prune after grace period", func(t *testing.T, relativePath string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - WithRelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: relativePath, }) repo := localrepo.NewTestRepo(t, cfg, repoProto) @@ -987,7 +1005,9 @@ func TestWriteCommitGraphIfNeeded(t *testing.T) { { desc: "empty repository", setup: func(t *testing.T) (*gitalypb.Repository, string) { - return gittest.InitRepo(t, cfg, cfg.Storages[0]) + return gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) }, didRepack: true, didPrune: true, @@ -996,7 +1016,9 @@ func TestWriteCommitGraphIfNeeded(t *testing.T) { { desc: "repository with objects but no refs", setup: func(t *testing.T) (*gitalypb.Repository, string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteBlob(t, cfg, repoPath, []byte("something")) return repoProto, repoPath }, @@ -1007,7 +1029,9 @@ func TestWriteCommitGraphIfNeeded(t *testing.T) { { desc: "repository without commit-graph", setup: func(t *testing.T) (*gitalypb.Repository, string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) return repoProto, repoPath }, @@ -1020,7 +1044,9 @@ func TestWriteCommitGraphIfNeeded(t *testing.T) { { desc: "repository with old-style unsplit commit-graph", setup: func(t *testing.T) (*gitalypb.Repository, string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) // Write a non-split commit-graph with bloom filters. We should @@ -1042,7 +1068,9 @@ func TestWriteCommitGraphIfNeeded(t *testing.T) { { desc: "repository with split commit-graph without bitmap", setup: func(t *testing.T) (*gitalypb.Repository, string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) // Generate a split commit-graph, but don't enable computation of @@ -1061,7 +1089,9 @@ func TestWriteCommitGraphIfNeeded(t *testing.T) { { desc: "repository with split commit-graph with bitmap without repack", setup: func(t *testing.T) (*gitalypb.Repository, string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) // Write a split commit-graph with bitmaps. This is the state we @@ -1080,7 +1110,9 @@ func TestWriteCommitGraphIfNeeded(t *testing.T) { { desc: "repository with split commit-graph with bitmap with repack", setup: func(t *testing.T) (*gitalypb.Repository, string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) // Write a split commit-graph with bitmaps. This is the state we @@ -1100,7 +1132,9 @@ func TestWriteCommitGraphIfNeeded(t *testing.T) { { desc: "repository with split commit-graph with bitmap with pruned objects", setup: func(t *testing.T) (*gitalypb.Repository, string) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) // Write a split commit-graph with bitmaps. This is the state we @@ -1141,7 +1175,9 @@ func TestWriteCommitGraphIfNeeded(t *testing.T) { } t.Run("commit-graph with pruned objects", func(t *testing.T) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) // Write a first commit-graph that contains the root commit, only. diff --git a/internal/git/localrepo/config_test.go b/internal/git/localrepo/config_test.go index 3f17c22c5..43e4d516a 100644 --- a/internal/git/localrepo/config_test.go +++ b/internal/git/localrepo/config_test.go @@ -78,7 +78,10 @@ func TestRepo_SetConfig(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, + gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := NewTestRepo(t, cfg, repoProto) for _, entry := range tc.preexistingEntries { @@ -121,7 +124,9 @@ func TestRepo_SetConfig(t *testing.T) { } t.Run("transactional", func(t *testing.T) { - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := NewTestRepo(t, cfg, repoProto) backchannelPeer := &peer.Peer{ @@ -228,7 +233,9 @@ func TestRepo_UnsetMatchingConfig(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := NewTestRepo(t, cfg, repoProto) for key, value := range tc.addEntries { @@ -250,7 +257,9 @@ func TestRepo_UnsetMatchingConfig(t *testing.T) { } t.Run("transactional", func(t *testing.T) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := NewTestRepo(t, cfg, repoProto) gittest.Exec(t, cfg, "-C", repoPath, "config", "--add", "some.key", "value") diff --git a/internal/git/localrepo/paths_test.go b/internal/git/localrepo/paths_test.go index e785bd01f..6ced8e612 100644 --- a/internal/git/localrepo/paths_test.go +++ b/internal/git/localrepo/paths_test.go @@ -20,10 +20,13 @@ import ( ) func TestRepo_Path(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) t.Run("valid repository", func(t *testing.T) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) path, err := repo.Path() @@ -32,7 +35,9 @@ func TestRepo_Path(t *testing.T) { }) t.Run("deleted repository", func(t *testing.T) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) require.NoError(t, os.RemoveAll(repoPath)) @@ -42,7 +47,9 @@ func TestRepo_Path(t *testing.T) { }) t.Run("non-git repository", func(t *testing.T) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) // Recreate the repository as a simple empty directory to simulate @@ -56,11 +63,13 @@ func TestRepo_Path(t *testing.T) { } func TestRepo_ObjectDirectoryPath(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) - locator := config.NewLocator(cfg) - ctx := testhelper.Context(t) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + locator := config.NewLocator(cfg) quarantine, err := quarantine.New(ctx, repoProto, locator) require.NoError(t, err) diff --git a/internal/git/localrepo/refs_test.go b/internal/git/localrepo/refs_test.go index 6da5ee98c..deed4ab3b 100644 --- a/internal/git/localrepo/refs_test.go +++ b/internal/git/localrepo/refs_test.go @@ -474,7 +474,9 @@ func TestRepo_UpdateRef(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { // We need to re-seed the repository every time so that we don't carry over // the state. - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := New(repo.locator, repo.gitCmdFactory, repo.catfileCache, repoProto) seedRepo(t, repoPath) diff --git a/internal/git/localrepo/remote_test.go b/internal/git/localrepo/remote_test.go index fe65206d6..47dd57a21 100644 --- a/internal/git/localrepo/remote_test.go +++ b/internal/git/localrepo/remote_test.go @@ -28,7 +28,9 @@ func TestRepo_FetchRemote(t *testing.T) { defer catfileCache.Stop() locator := config.NewLocator(cfg) - _, remoteRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + _, remoteRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) commitID := gittest.WriteCommit(t, cfg, remoteRepoPath, gittest.WithBranch("main")) tagID := gittest.WriteTag(t, cfg, remoteRepoPath, "v1.0.0", commitID.Revision(), gittest.WriteTagConfig{ Message: "annotated tag", @@ -37,7 +39,9 @@ func TestRepo_FetchRemote(t *testing.T) { initBareWithRemote := func(t *testing.T, remote string) (*Repo, string) { t.Helper() - clientRepo, clientRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + clientRepo, clientRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) cmd := gittest.NewCommand(t, cfg, "-C", clientRepoPath, "remote", "add", remote, remoteRepoPath) err := cmd.Run() @@ -57,7 +61,9 @@ func TestRepo_FetchRemote(t *testing.T) { }) t.Run("unknown remote", func(t *testing.T) { - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := New(locator, gitCmdFactory, catfileCache, repoProto) var stderr bytes.Buffer @@ -87,7 +93,9 @@ func TestRepo_FetchRemote(t *testing.T) { }) t.Run("with env", func(t *testing.T) { - testRepo, testRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := New(locator, gitCmdFactory, catfileCache, testRepo) gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", remoteRepoPath) @@ -98,7 +106,9 @@ func TestRepo_FetchRemote(t *testing.T) { }) t.Run("with disabled transactions", func(t *testing.T) { - testRepo, testRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := New(locator, gitCmdFactory, catfileCache, testRepo) gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", remoteRepoPath) @@ -113,7 +123,9 @@ func TestRepo_FetchRemote(t *testing.T) { }) t.Run("with globals", func(t *testing.T) { - testRepo, testRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := New(locator, gitCmdFactory, catfileCache, testRepo) gittest.Exec(t, cfg, "-C", testRepoPath, "remote", "add", "source", remoteRepoPath) @@ -140,7 +152,9 @@ func TestRepo_FetchRemote(t *testing.T) { }) t.Run("with prune", func(t *testing.T) { - testRepo, testRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := New(locator, gitCmdFactory, catfileCache, testRepo) @@ -247,18 +261,24 @@ func TestRepo_Push(t *testing.T) { t.Cleanup(catfileCache.Stop) locator := config.NewLocator(cfg) - sourceRepoProto, sourceRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + sourceRepoProto, sourceRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) sourceRepo := New(locator, gitCmdFactory, catfileCache, sourceRepoProto) gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("master")) gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch("feature")) setupPushRepo := func(t testing.TB) (*Repo, string, []git.ConfigPair) { - repoProto, repopath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repopath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) return New(locator, gitCmdFactory, catfileCache, repoProto), repopath, nil } setupDivergedRepo := func(t testing.TB) (*Repo, string, []git.ConfigPair) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := New(locator, gitCmdFactory, catfileCache, repoProto) // set up master as a diverging ref in push repo @@ -332,7 +352,9 @@ func TestRepo_Push(t *testing.T) { { desc: "invalid remote", setupPushRepo: func(t testing.TB) (*Repo, string, []git.ConfigPair) { - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) return New(locator, gitCmdFactory, catfileCache, repoProto), "", nil }, refspecs: []string{"refs/heads/master"}, @@ -341,7 +363,9 @@ func TestRepo_Push(t *testing.T) { { desc: "in-memory remote", setupPushRepo: func(testing.TB) (*Repo, string, []git.ConfigPair) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) return New(locator, gitCmdFactory, catfileCache, repoProto), "inmemory", []git.ConfigPair{ {Key: "remote.inmemory.url", Value: repoPath}, } diff --git a/internal/git/localrepo/repo_test.go b/internal/git/localrepo/repo_test.go index e2f8fa8ff..4a13c0922 100644 --- a/internal/git/localrepo/repo_test.go +++ b/internal/git/localrepo/repo_test.go @@ -25,7 +25,9 @@ func TestRepo(t *testing.T) { gittest.TestRepository(t, cfg, func(ctx context.Context, t testing.TB) (git.Repository, string) { t.Helper() - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gitCmdFactory := gittest.NewCommandFactory(t, cfg) catfileCache := catfile.NewCache(cfg) @@ -69,7 +71,9 @@ func TestSize(t *testing.T) { desc: "empty repository", expectedSize: 0, setup: func(t *testing.T) *gitalypb.Repository { - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) return repoProto }, expectedUseBitmap: true, @@ -77,7 +81,9 @@ func TestSize(t *testing.T) { { desc: "referenced commit", setup: func(t *testing.T) *gitalypb.Repository { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( @@ -94,7 +100,9 @@ func TestSize(t *testing.T) { { desc: "unreferenced commit", setup: func(t *testing.T) *gitalypb.Repository { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( @@ -110,7 +118,9 @@ func TestSize(t *testing.T) { { desc: "modification to blob without repack", setup: func(t *testing.T) *gitalypb.Repository { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) rootCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( @@ -135,7 +145,9 @@ func TestSize(t *testing.T) { { desc: "modification to blob after repack", setup: func(t *testing.T) *gitalypb.Repository { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) rootCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( @@ -162,7 +174,9 @@ func TestSize(t *testing.T) { { desc: "excluded single ref", setup: func(t *testing.T) *gitalypb.Repository { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( @@ -189,7 +203,9 @@ func TestSize(t *testing.T) { { desc: "excluded everything", setup: func(t *testing.T) *gitalypb.Repository { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( @@ -209,8 +225,12 @@ func TestSize(t *testing.T) { { desc: "repo with alternate", setup: func(t *testing.T) *gitalypb.Repository { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) - _, poolPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + _, poolPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) require.NoError(t, os.WriteFile( filepath.Join(repoPath, "objects", "info", "alternates"), @@ -239,8 +259,12 @@ func TestSize(t *testing.T) { { desc: "exclude alternate with identical contents", setup: func(t *testing.T) *gitalypb.Repository { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) - _, poolPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + _, poolPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) require.NoError(t, os.WriteFile( filepath.Join(repoPath, "objects", "info", "alternates"), @@ -270,8 +294,12 @@ func TestSize(t *testing.T) { { desc: "exclude alternate with additional contents", setup: func(t *testing.T) *gitalypb.Repository { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) - _, poolPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + _, poolPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) require.NoError(t, os.WriteFile( filepath.Join(repoPath, "objects", "info", "alternates"), @@ -332,13 +360,17 @@ func TestSize(t *testing.T) { } func TestRepo_StorageTempDir(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) + gitCmdFactory := gittest.NewCommandFactory(t, cfg) catfileCache := catfile.NewCache(cfg) t.Cleanup(catfileCache.Stop) locator := config.NewLocator(cfg) - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := New(locator, gitCmdFactory, catfileCache, repoProto) expected, err := locator.TempDir(cfg.Storages[0].Name) @@ -372,7 +404,9 @@ func TestRepo_ObjectHash(t *testing.T) { exec %q "$@"`, outputFile, execEnv.BinaryPath) }) - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := New(locator, gitCmdFactory, catfileCache, repoProto) objectHash, err := repo.ObjectHash(ctx) diff --git a/internal/git/localrepo/testhelper_test.go b/internal/git/localrepo/testhelper_test.go index 28fc6a851..5bc11b2af 100644 --- a/internal/git/localrepo/testhelper_test.go +++ b/internal/git/localrepo/testhelper_test.go @@ -36,6 +36,7 @@ func setupRepo(t *testing.T, opts ...setupRepoOption) (config.Cfg, *Repo, string opt(&setupRepoCfg) } + ctx := testhelper.Context(t) cfg := testcfg.Build(t) var commandFactoryOpts []git.ExecCommandFactoryOption @@ -43,7 +44,9 @@ func setupRepo(t *testing.T, opts ...setupRepoOption) (config.Cfg, *Repo, string commandFactoryOpts = append(commandFactoryOpts, git.WithSkipHooks()) } - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gitCmdFactory := gittest.NewCommandFactory(t, cfg, commandFactoryOpts...) catfileCache := catfile.NewCache(cfg) diff --git a/internal/git/lstree/list_entries_test.go b/internal/git/lstree/list_entries_test.go index 9a3d3cba7..2d78f9c34 100644 --- a/internal/git/lstree/list_entries_test.go +++ b/internal/git/lstree/list_entries_test.go @@ -17,7 +17,9 @@ func TestListEntries(t *testing.T) { cfg := testcfg.Build(t) ctx := testhelper.Context(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) blobID := gittest.WriteBlob(t, cfg, repoPath, []byte("blob contents")) diff --git a/internal/git/lstree/parser_test.go b/internal/git/lstree/parser_test.go index 4fc4d09c1..3df2145cb 100644 --- a/internal/git/lstree/parser_test.go +++ b/internal/git/lstree/parser_test.go @@ -8,14 +8,18 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest" + "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg" ) func TestParser(t *testing.T) { t.Parallel() + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - _, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + _, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gitignoreBlobID := gittest.WriteBlob(t, cfg, repoPath, []byte("gitignore")) gitmodulesBlobID := gittest.WriteBlob(t, cfg, repoPath, []byte("gitmodules")) diff --git a/internal/git/object_id_test.go b/internal/git/object_id_test.go index 8c8502ef4..6597daf99 100644 --- a/internal/git/object_id_test.go +++ b/internal/git/object_id_test.go @@ -33,8 +33,9 @@ func TestDetectObjectHash(t *testing.T) { { desc: "defaults to SHA1", setup: func(t *testing.T) *gitalypb.Repository { - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - ObjectFormat: "sha1", + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + ObjectFormat: "sha1", }) // Verify that the repo doesn't explicitly mention it's using SHA1 @@ -49,8 +50,9 @@ func TestDetectObjectHash(t *testing.T) { { desc: "explicitly set to SHA1", setup: func(t *testing.T) *gitalypb.Repository { - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - ObjectFormat: "sha1", + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + ObjectFormat: "sha1", }) // Explicitly set the object format to SHA1. Note that setting the @@ -66,8 +68,9 @@ func TestDetectObjectHash(t *testing.T) { { desc: "explicitly set to SHA256", setup: func(t *testing.T) *gitalypb.Repository { - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - ObjectFormat: "sha256", + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + ObjectFormat: "sha256", }) require.Equal(t, @@ -82,8 +85,9 @@ func TestDetectObjectHash(t *testing.T) { { desc: "invalid repository configuration", setup: func(t *testing.T) *gitalypb.Repository { - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0], gittest.InitRepoOpts{ - ObjectFormat: "sha1", + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + ObjectFormat: "sha1", }) gittest.Exec(t, cfg, "-C", repoPath, "config", "extensions.objectFormat", "sha1") @@ -98,7 +102,9 @@ func TestDetectObjectHash(t *testing.T) { { desc: "unknown hash", setup: func(t *testing.T) *gitalypb.Repository { - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) // Explicitly set the object format to something unknown. gittest.Exec(t, cfg, "-C", repoPath, "config", "extensions.objectFormat", "blake2") diff --git a/internal/git/objectpool/fetch_test.go b/internal/git/objectpool/fetch_test.go index 2df9a769d..0a03970ec 100644 --- a/internal/git/objectpool/fetch_test.go +++ b/internal/git/objectpool/fetch_test.go @@ -249,7 +249,9 @@ func testFetchFromOriginRefs(t *testing.T, ctx context.Context) { poolPath := pool.FullPath() // Init the source repo with a bunch of refs. - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries()) diff --git a/internal/git/stats/profile_test.go b/internal/git/stats/profile_test.go index 0b6b3030c..dff0ede48 100644 --- a/internal/git/stats/profile_test.go +++ b/internal/git/stats/profile_test.go @@ -16,10 +16,12 @@ import ( ) func TestRepositoryProfile(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - testRepo, testRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) - ctx := testhelper.Context(t) + testRepo, testRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) hasBitmap, err := HasBitmap(testRepoPath) require.NoError(t, err) diff --git a/internal/git/updateref/update_with_hooks_test.go b/internal/git/updateref/update_with_hooks_test.go index 808b06454..b47db59fe 100644 --- a/internal/git/updateref/update_with_hooks_test.go +++ b/internal/git/updateref/update_with_hooks_test.go @@ -32,7 +32,9 @@ func TestUpdaterWithHooks_UpdateReference_invalidParameters(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) gitCmdFactory := gittest.NewCommandFactory(t, cfg) - repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) revA := git.ObjectID(strings.Repeat("a", gittest.DefaultObjectHash.EncodedLen())) revB := git.ObjectID(strings.Repeat("b", gittest.DefaultObjectHash.EncodedLen())) @@ -99,7 +101,9 @@ func TestUpdaterWithHooks_UpdateReference(t *testing.T) { gitalypb.RegisterHookServiceServer(srv, hookservice.NewServer(deps.GetHookManager(), deps.GetGitCmdFactory(), deps.GetPackObjectsCache(), deps.GetPackObjectsConcurrencyTracker())) }) - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) requirePayload := func(t *testing.T, env []string) { @@ -276,7 +280,9 @@ func TestUpdaterWithHooks_quarantine(t *testing.T) { gitCmdFactory := gittest.NewCommandFactory(t, cfg) locator := config.NewLocator(cfg) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("main")) unquarantinedRepo := localrepo.NewTestRepo(t, cfg, repoProto) diff --git a/internal/git/updateref/updateref_test.go b/internal/git/updateref/updateref_test.go index 96cad19b2..50c2d7eb1 100644 --- a/internal/git/updateref/updateref_test.go +++ b/internal/git/updateref/updateref_test.go @@ -24,7 +24,9 @@ func setupUpdater(t *testing.T, ctx context.Context) (config.Cfg, *localrepo.Rep cfg := testcfg.Build(t) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto, git.WithSkipHooks()) updater, err := New(ctx, repo) @@ -133,7 +135,9 @@ func TestUpdater_concurrentLocking(t *testing.T) { t.Skip("git does not support flushing yet, which is known to be flaky") } - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto, git.WithSkipHooks()) commitID := gittest.WriteCommit(t, cfg, repoPath) diff --git a/internal/git2go/apply_test.go b/internal/git2go/apply_test.go index 146a487f8..c225f02b8 100644 --- a/internal/git2go/apply_test.go +++ b/internal/git2go/apply_test.go @@ -18,14 +18,16 @@ import ( ) func TestExecutor_Apply(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) testcfg.BuildGitalyGit2Go(t, cfg) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) executor := NewExecutor(cfg, gittest.NewCommandFactory(t, cfg), config.NewLocator(cfg)) - ctx := testhelper.Context(t) oidBase, err := repo.WriteBlob(ctx, "file", strings.NewReader("base")) require.NoError(t, err) diff --git a/internal/git2go/commit_test.go b/internal/git2go/commit_test.go index ee4cddb4e..4999d668f 100644 --- a/internal/git2go/commit_test.go +++ b/internal/git2go/commit_test.go @@ -48,7 +48,9 @@ func TestExecutor_Commit(t *testing.T) { cfg := testcfg.Build(t) testcfg.BuildGitalyGit2Go(t, cfg) - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) diff --git a/internal/git2go/featureflags_test.go b/internal/git2go/featureflags_test.go index 59026624c..b4e9117ef 100644 --- a/internal/git2go/featureflags_test.go +++ b/internal/git2go/featureflags_test.go @@ -48,7 +48,9 @@ func testExecutorFeatureFlags(t *testing.T, ctx context.Context) { cfg := testcfg.Build(t) testcfg.BuildGitalyGit2Go(t, cfg) - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) diff --git a/internal/gitaly/linguist/language_stats_test.go b/internal/gitaly/linguist/language_stats_test.go index a64f8ad90..b3d611e1a 100644 --- a/internal/gitaly/linguist/language_stats_test.go +++ b/internal/gitaly/linguist/language_stats_test.go @@ -19,6 +19,7 @@ import ( func TestNewLanguageStats(t *testing.T) { t.Parallel() + ctx := testhelper.Context(t) cfg := testcfg.Build(t) for _, tc := range []struct { @@ -82,7 +83,9 @@ func TestNewLanguageStats(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) tc.run(t, repo, repoPath) }) diff --git a/internal/gitaly/linguist/linguist_test.go b/internal/gitaly/linguist/linguist_test.go index cd9d68f63..8d24a22b6 100644 --- a/internal/gitaly/linguist/linguist_test.go +++ b/internal/gitaly/linguist/linguist_test.go @@ -125,7 +125,10 @@ func testInstanceStats(t *testing.T, ctx context.Context) { { desc: "empty code files", setup: func(t *testing.T) (*gitalypb.Repository, string, git.ObjectID) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + emptyBlob := gittest.WriteBlob(t, cfg, repoPath, []byte{}) commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( gittest.TreeEntry{Path: "README.md", Mode: "100644", Content: "Hello world!"}, @@ -192,7 +195,9 @@ func testInstanceStats(t *testing.T, ctx context.Context) { { desc: "old cache", setup: func(t *testing.T) (*gitalypb.Repository, string, git.ObjectID) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) oldCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( @@ -230,7 +235,9 @@ func testInstanceStats(t *testing.T, ctx context.Context) { { desc: "missing commit", setup: func(t *testing.T) (*gitalypb.Repository, string, git.ObjectID) { - repoProto, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) return repoProto, repoPath, git.ObjectID("b1bb1d1b0b1d1b00") }, diff --git a/internal/gitaly/rubyserver/rubyserver_test.go b/internal/gitaly/rubyserver/rubyserver_test.go index 7f7aa4a40..cf35f7538 100644 --- a/internal/gitaly/rubyserver/rubyserver_test.go +++ b/internal/gitaly/rubyserver/rubyserver_test.go @@ -206,7 +206,9 @@ func TestServer_gitconfig(t *testing.T) { `[`, ), 0o666)) - repo, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) // We now do any random RPC request that hits the Ruby server... client, err := rubyServer.WikiServiceClient(ctx) diff --git a/internal/gitaly/service/operations/commit_files_test.go b/internal/gitaly/service/operations/commit_files_test.go index 24bed724c..3eb876c00 100644 --- a/internal/gitaly/service/operations/commit_files_test.go +++ b/internal/gitaly/service/operations/commit_files_test.go @@ -1293,7 +1293,9 @@ func testSuccessfulUserCommitFilesRemoteRepositoryRequest(setHeader func(header repo := localrepo.NewTestRepo(t, cfg, repoProto) - newRepoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + newRepoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) newRepo := localrepo.NewTestRepo(t, cfg, newRepoProto) targetBranchName := "new" 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 f0690ca01..c97b26d4f 100644 --- a/internal/gitaly/service/remote/find_remote_root_ref_test.go +++ b/internal/gitaly/service/remote/find_remote_root_ref_test.go @@ -65,7 +65,9 @@ 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 := gittest.InitRepo(t, cfg, cfg.Storages[0]) + _, clientRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) gittest.Exec(t, cfg, "-C", remoteRepoPath, "remote", "add", "foo", "file://"+clientRepoPath) response, err := client.FindRemoteRootRef(ctx, &gitalypb.FindRemoteRootRefRequest{ Repository: remoteRepo, diff --git a/internal/gitaly/service/repository/calculate_checksum_test.go b/internal/gitaly/service/repository/calculate_checksum_test.go index 38feb5bbc..e8f705904 100644 --- a/internal/gitaly/service/repository/calculate_checksum_test.go +++ b/internal/gitaly/service/repository/calculate_checksum_test.go @@ -40,31 +40,33 @@ func TestSuccessfulCalculateChecksum(t *testing.T) { func TestEmptyRepositoryCalculateChecksum(t *testing.T) { t.Parallel() + + ctx := testhelper.Context(t) cfg, client := setupRepositoryServiceWithoutRepo(t) - testCtx := testhelper.Context(t) - repo, _ := gittest.CreateRepository(testCtx, t, cfg) + repo, _ := gittest.CreateRepository(ctx, t, cfg) request := &gitalypb.CalculateChecksumRequest{Repository: repo} - response, err := client.CalculateChecksum(testCtx, request) + response, err := client.CalculateChecksum(ctx, request) require.NoError(t, err) require.Equal(t, git.ObjectHashSHA1.ZeroOID.String(), response.Checksum) } func TestBrokenRepositoryCalculateChecksum(t *testing.T) { t.Parallel() + + ctx := testhelper.Context(t) cfg, client := setupRepositoryServiceWithoutRepo(t) - testCtx := testhelper.Context(t) - repo, repoPath := gittest.CreateRepository(testCtx, t, cfg) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg) // Force an empty HEAD file require.NoError(t, os.Truncate(filepath.Join(repoPath, "HEAD"), 0)) request := &gitalypb.CalculateChecksumRequest{Repository: repo} - _, err := client.CalculateChecksum(testCtx, request) + _, err := client.CalculateChecksum(ctx, request) testhelper.RequireGrpcCode(t, err, codes.DataLoss) } diff --git a/internal/gitaly/service/repository/license_test.go b/internal/gitaly/service/repository/license_test.go index bd38c746b..bfc18d3fa 100644 --- a/internal/gitaly/service/repository/license_test.go +++ b/internal/gitaly/service/repository/license_test.go @@ -108,7 +108,9 @@ SOFTWARE.`, func testFindLicenseRequestEmptyRepo(t *testing.T, cfg config.Cfg, client gitalypb.RepositoryServiceClient, rubySrv *rubyserver.Server) { testhelper.NewFeatureSets(featureflag.GoFindLicense).Run(t, func(t *testing.T, ctx context.Context) { - repo, repoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) require.NoError(t, os.RemoveAll(repoPath)) _, err := client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{Repository: repo}) diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go index 1908cbbbb..783379e59 100644 --- a/internal/gitaly/service/repository/replicate_test.go +++ b/internal/gitaly/service/repository/replicate_test.go @@ -124,7 +124,10 @@ func TestReplicateRepository_hiddenRefs(t *testing.T) { ctx = testhelper.MergeOutgoingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg)) t.Run("initial seeding", func(t *testing.T) { - sourceRepo, sourceRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) + sourceRepo, sourceRepoPath := gittest.CreateRepository(ctx, t, cfg, + gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) // Create a bunch of internal references, regardless of whether we classify them as hidden // or read-only. We should be able to replicate all of them. @@ -156,9 +159,13 @@ func TestReplicateRepository_hiddenRefs(t *testing.T) { }) t.Run("incremental replication", func(t *testing.T) { - sourceRepo, sourceRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0]) - targetRepo, targetRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[1], gittest.InitRepoOpts{ - WithRelativePath: sourceRepo.GetRelativePath(), + sourceRepo, sourceRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + targetRepo, targetRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: sourceRepo.GetRelativePath(), + Storage: cfg.Storages[1], }) // Create the same commit in both repositories so that they're in a known-good @@ -466,7 +473,10 @@ func TestReplicateRepository_FailedFetchInternalRemote(t *testing.T) { client, socketPath := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect()) cfg.SocketPath = socketPath - targetRepo, _ := gittest.InitRepo(t, cfg, cfg.Storages[1]) + targetRepo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Storage: cfg.Storages[1], + }) // The source repository must be at the same path as the target repository, and it must be a // real repository. In order to still have the fetch fail, we corrupt the repository by |