diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-10 10:35:39 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-08-10 16:51:05 +0300 |
commit | 337f706eb69d408e25f3f8e61b2b5d2ad3bfb749 (patch) | |
tree | d31de95251a85869143ddc9244a1f1c852160bd0 | |
parent | f8c03d709d4fad2aef42627d7c85e5f15f533f1e (diff) |
gittest: Convert callers of CloneRepo to use CreateRepository
Convert all callers of CloneRepo to use CreateRepository.
33 files changed, 367 insertions, 124 deletions
diff --git a/internal/cache/diskcache_test.go b/internal/cache/diskcache_test.go index be58460ba..b33ad8648 100644 --- a/internal/cache/diskcache_test.go +++ b/internal/cache/diskcache_test.go @@ -47,8 +47,17 @@ func TestStreamDBNaiveKeyer(t *testing.T) { cfg := testcfg.Build(t) - repo1, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) - repo2, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + ctx := testhelper.Context(t) + ctx = testhelper.SetCtxGrpcMethod(ctx, "InfoRefsUploadPack") + + repo1, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) + repo2, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) locator := config.NewLocator(cfg) @@ -58,8 +67,6 @@ func TestStreamDBNaiveKeyer(t *testing.T) { req2 := &gitalypb.InfoRefsRequest{ Repository: repo2, } - ctx := testhelper.Context(t) - ctx = testhelper.SetCtxGrpcMethod(ctx, "InfoRefsUploadPack") t.Run("empty cache", func(t *testing.T) { cache := New(cfg, locator) diff --git a/internal/git/decoder_test.go b/internal/git/decoder_test.go index 517a4980c..34073658e 100644 --- a/internal/git/decoder_test.go +++ b/internal/git/decoder_test.go @@ -19,8 +19,10 @@ func TestShowRefDecoder(t *testing.T) { cfg := testcfg.Build(t) ctx := testhelper.Context(t) - repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: "repo.git", + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: "repo.git", }) repo := localrepo.NewTestRepo(t, cfg, repoProto) diff --git a/internal/git/gitpipe/catfile_info_test.go b/internal/git/gitpipe/catfile_info_test.go index ac2a9cfb9..e9af6cfd7 100644 --- a/internal/git/gitpipe/catfile_info_test.go +++ b/internal/git/gitpipe/catfile_info_test.go @@ -26,9 +26,13 @@ const ( ) func TestCatfileInfo(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) for _, tc := range []struct { @@ -133,8 +137,6 @@ func TestCatfileInfo(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - ctx := testhelper.Context(t) - catfileCache := catfile.NewCache(cfg) defer catfileCache.Stop() diff --git a/internal/git/gitpipe/catfile_object_test.go b/internal/git/gitpipe/catfile_object_test.go index 905ea0895..72c47c1f5 100644 --- a/internal/git/gitpipe/catfile_object_test.go +++ b/internal/git/gitpipe/catfile_object_test.go @@ -20,9 +20,13 @@ import ( ) func TestCatfileObject(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) for _, tc := range []struct { @@ -75,8 +79,6 @@ func TestCatfileObject(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - ctx := testhelper.Context(t) - catfileCache := catfile.NewCache(cfg) defer catfileCache.Stop() diff --git a/internal/git/gitpipe/diff_tree_test.go b/internal/git/gitpipe/diff_tree_test.go index 1dad55b78..f2cac6a38 100644 --- a/internal/git/gitpipe/diff_tree_test.go +++ b/internal/git/gitpipe/diff_tree_test.go @@ -14,9 +14,13 @@ import ( ) func TestDiffTree(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) for _, tc := range []struct { @@ -119,8 +123,6 @@ func TestDiffTree(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - ctx := testhelper.Context(t) - it := DiffTree(ctx, repo, tc.leftRevision, tc.rightRevision, tc.options...) var results []RevisionResult diff --git a/internal/git/gitpipe/ls_tree_test.go b/internal/git/gitpipe/ls_tree_test.go index 04e09dcb1..0a90f0fec 100644 --- a/internal/git/gitpipe/ls_tree_test.go +++ b/internal/git/gitpipe/ls_tree_test.go @@ -14,9 +14,13 @@ import ( ) func TestLsTree(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) for _, tc := range []struct { @@ -130,8 +134,6 @@ func TestLsTree(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - ctx := testhelper.Context(t) - it := LsTree(ctx, repo, tc.revision, tc.options...) var results []RevisionResult diff --git a/internal/git/gitpipe/pipeline_test.go b/internal/git/gitpipe/pipeline_test.go index 07ec84f65..797d1fced 100644 --- a/internal/git/gitpipe/pipeline_test.go +++ b/internal/git/gitpipe/pipeline_test.go @@ -19,9 +19,13 @@ import ( ) func TestPipeline_revlist(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) for _, tc := range []struct { @@ -221,8 +225,6 @@ func TestPipeline_revlist(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - ctx := testhelper.Context(t) - catfileCache := catfile.NewCache(cfg) defer catfileCache.Stop() @@ -371,11 +373,14 @@ func TestPipeline_revlist(t *testing.T) { } func TestPipeline_forEachRef(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) - ctx := testhelper.Context(t) catfileCache := catfile.NewCache(cfg) defer catfileCache.Stop() diff --git a/internal/git/gitpipe/revision_test.go b/internal/git/gitpipe/revision_test.go index 5fccfd2be..7e740c247 100644 --- a/internal/git/gitpipe/revision_test.go +++ b/internal/git/gitpipe/revision_test.go @@ -19,9 +19,13 @@ import ( ) func TestRevlist(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) for _, tc := range []struct { @@ -487,8 +491,6 @@ func TestRevlist(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { - ctx := testhelper.Context(t) - it := Revlist(ctx, repo, tc.revisions, tc.options...) var results []RevisionResult diff --git a/internal/git/housekeeping/optimize_repository_test.go b/internal/git/housekeeping/optimize_repository_test.go index da5488bad..030ab1eef 100644 --- a/internal/git/housekeeping/optimize_repository_test.go +++ b/internal/git/housekeeping/optimize_repository_test.go @@ -53,8 +53,10 @@ func TestNeedsRepacking(t *testing.T) { { desc: "missing bitmap", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) return repoProto }, @@ -67,8 +69,10 @@ func TestNeedsRepacking(t *testing.T) { { desc: "missing bitmap with alternate", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) // Create the alternates file. If it exists, then we shouldn't try @@ -85,8 +89,10 @@ func TestNeedsRepacking(t *testing.T) { { desc: "missing commit-graph", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) gittest.Exec(t, cfg, "-C", repoPath, "repack", "-Ad", "--write-bitmap-index") @@ -101,8 +107,10 @@ func TestNeedsRepacking(t *testing.T) { { desc: "commit-graph without bloom filters", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) gittest.Exec(t, cfg, "-C", repoPath, "repack", "-Ad", "--write-bitmap-index") @@ -118,8 +126,10 @@ func TestNeedsRepacking(t *testing.T) { { desc: "no repack needed", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repoProto, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repoProto, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) gittest.Exec(t, cfg, "-C", repoPath, "repack", "-Ad", "--write-bitmap-index") @@ -549,8 +559,10 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 { desc: "repository without bitmap repacks objects", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) return repo }, @@ -565,8 +577,10 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 { desc: "repository without commit-graph writes commit-graph", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) gittest.Exec(t, cfg, "-C", repoPath, "repack", "-A", "-d", "--write-bitmap-index") return repo @@ -580,8 +594,10 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 { desc: "repository with multiple packfiles packs only for object pool", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) // Note: git-repack(1) without "-d" will _not_ delete the old @@ -606,8 +622,10 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 { desc: "well-packed repository does not optimize", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) gittest.Exec(t, cfg, "-C", repoPath, "repack", "-A", "-d", "--write-bitmap-index") gittest.Exec(t, cfg, "-C", repoPath, "commit-graph", "write", "--split", "--changed-paths") @@ -621,8 +639,10 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 { desc: "recent loose objects don't get pruned", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) gittest.Exec(t, cfg, "-C", repoPath, "repack", "-A", "-d", "--write-bitmap-index") gittest.Exec(t, cfg, "-C", repoPath, "commit-graph", "write", "--split", "--changed-paths") @@ -654,8 +674,10 @@ gitaly_housekeeping_tasks_total{housekeeping_task="total", status="success"} 1 { desc: "old loose objects get pruned", setup: func(t *testing.T, relativePath string) *gitalypb.Repository { - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: relativePath, + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: relativePath, }) gittest.Exec(t, cfg, "-C", repoPath, "repack", "-A", "-d", "--write-bitmap-index") gittest.Exec(t, cfg, "-C", repoPath, "commit-graph", "write", "--split", "--changed-paths") @@ -745,7 +767,10 @@ func TestOptimizeRepository_ConcurrencyLimit(t *testing.T) { t.Run("subsequent calls get skipped", func(t *testing.T) { reqReceivedCh, ch := make(chan struct{}), make(chan struct{}) - repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) manager := &RepositoryManager{ @@ -773,9 +798,15 @@ func TestOptimizeRepository_ConcurrencyLimit(t *testing.T) { t.Run("multiple repositories concurrently", func(t *testing.T) { reqReceivedCh, ch := make(chan struct{}), make(chan struct{}) - repoProtoFirst, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProtoFirst, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repoFirst := localrepo.NewTestRepo(t, cfg, repoProtoFirst) - repoProtoSecond, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProtoSecond, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repoSecond := localrepo.NewTestRepo(t, cfg, repoProtoSecond) reposOptimized := make(map[string]struct{}) @@ -812,7 +843,10 @@ func TestOptimizeRepository_ConcurrencyLimit(t *testing.T) { t.Run("serialized optimizations", func(t *testing.T) { reqReceivedCh, ch := make(chan struct{}), make(chan struct{}) - repoProto, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) repo := localrepo.NewTestRepo(t, cfg, repoProto) var optimizations int diff --git a/internal/git/quarantine/quarantine_test.go b/internal/git/quarantine/quarantine_test.go index 9c1576549..161426bf8 100644 --- a/internal/git/quarantine/quarantine_test.go +++ b/internal/git/quarantine/quarantine_test.go @@ -88,7 +88,11 @@ func TestQuarantine_Migrate(t *testing.T) { t.Run("no changes", func(t *testing.T) { ctx := testhelper.Context(t) - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, + gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) oldContents := listEntries(t, repoPath) @@ -103,7 +107,10 @@ func TestQuarantine_Migrate(t *testing.T) { t.Run("simple change", func(t *testing.T) { ctx := testhelper.Context(t) - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) oldContents := listEntries(t, repoPath) require.NotContains(t, oldContents, "objects/file") diff --git a/internal/git/stats/commit_graph_test.go b/internal/git/stats/commit_graph_test.go index 029ff158a..f6a38e104 100644 --- a/internal/git/stats/commit_graph_test.go +++ b/internal/git/stats/commit_graph_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "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" ) @@ -34,8 +35,13 @@ func TestIsMissingBloomFilters(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - _, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + + _, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) if len(tc.args) > 0 { gittest.Exec(t, cfg, append([]string{"-C", repoPath}, tc.args...)...) diff --git a/internal/git/stats/git_test.go b/internal/git/stats/git_test.go index fc7050118..70faf4f26 100644 --- a/internal/git/stats/git_test.go +++ b/internal/git/stats/git_test.go @@ -21,11 +21,17 @@ import ( ) func TestLogObjectInfo(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repo1, repoPath1 := gittest.CloneRepo(t, cfg, cfg.Storages[0]) - repo2, repoPath2 := gittest.CloneRepo(t, cfg, cfg.Storages[0]) - ctx := testhelper.Context(t) + repo1, repoPath1 := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) + repo2, repoPath2 := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) requireLog := func(entries []*logrus.Entry) map[string]interface{} { for _, entry := range entries { diff --git a/internal/git/stats/http_push_test.go b/internal/git/stats/http_push_test.go index f589aa30f..f35bec39f 100644 --- a/internal/git/stats/http_push_test.go +++ b/internal/git/stats/http_push_test.go @@ -42,7 +42,10 @@ func TestPerformHTTPPush(t *testing.T) { { desc: "single revision", preparePush: func(t *testing.T, cfg config.Cfg) ([]PushCommand, io.Reader) { - _, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + _, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) commit := gittest.WriteCommit(t, cfg, repoPath) revisions := strings.NewReader(commit.String()) @@ -76,7 +79,10 @@ func TestPerformHTTPPush(t *testing.T) { { desc: "many revisions", preparePush: func(t *testing.T, cfg config.Cfg) ([]PushCommand, io.Reader) { - _, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + _, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) commands := make([]PushCommand, 1000) commits := make([]string, len(commands)) diff --git a/internal/gitaly/linguist/language_stats_test.go b/internal/gitaly/linguist/language_stats_test.go index b3d611e1a..9199f6eb8 100644 --- a/internal/gitaly/linguist/language_stats_test.go +++ b/internal/gitaly/linguist/language_stats_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest" "gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo" + "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg" ) @@ -95,8 +96,12 @@ func TestNewLanguageStats(t *testing.T) { func TestLanguageStats_add(t *testing.T) { t.Parallel() + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + repo := localrepo.NewTestRepo(t, cfg, repoProto) for _, tc := range []struct { @@ -162,8 +167,12 @@ func TestLanguageStats_add(t *testing.T) { func TestLanguageStats_drop(t *testing.T) { t.Parallel() + ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repoProto, _ := gittest.InitRepo(t, cfg, cfg.Storages[0]) + repoProto, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + repo := localrepo.NewTestRepo(t, cfg, repoProto) for _, tc := range []struct { @@ -217,8 +226,11 @@ func TestLanguageStats_drop(t *testing.T) { func TestLanguageStats_save(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) s, err := newLanguageStats(repo) diff --git a/internal/gitaly/linguist/linguist_test.go b/internal/gitaly/linguist/linguist_test.go index 8d24a22b6..c74152d00 100644 --- a/internal/gitaly/linguist/linguist_test.go +++ b/internal/gitaly/linguist/linguist_test.go @@ -105,7 +105,10 @@ func testInstanceStats(t *testing.T, ctx context.Context) { { desc: "successful", 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, + }) + commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( gittest.TreeEntry{Path: "webpack.coffee", Mode: "100644", Content: strings.Repeat("a", 107)}, gittest.TreeEntry{Path: "show_user.html", Mode: "100644", Content: strings.Repeat("a", 349)}, @@ -143,7 +146,10 @@ func testInstanceStats(t *testing.T, ctx context.Context) { { desc: "preexisting 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, + }) + commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( gittest.TreeEntry{Path: "webpack.coffee", Mode: "100644", Content: strings.Repeat("a", 107)}, gittest.TreeEntry{Path: "show_user.html", Mode: "100644", Content: strings.Repeat("a", 349)}, @@ -173,7 +179,10 @@ func testInstanceStats(t *testing.T, ctx context.Context) { { desc: "corrupted 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, + }) + commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithTreeEntries( gittest.TreeEntry{Path: "webpack.coffee", Mode: "100644", Content: strings.Repeat("a", 107)}, gittest.TreeEntry{Path: "show_user.html", Mode: "100644", Content: strings.Repeat("a", 349)}, @@ -329,8 +338,9 @@ func benchmarkInstanceStats(b *testing.B, ctx context.Context) { catfileCache := catfile.NewCache(cfg) b.Cleanup(catfileCache.Stop) - repoProto, repoPath := gittest.CloneRepo(b, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - SourceRepo: "benchmark.git", + repoProto, repoPath := gittest.CreateRepository(ctx, b, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: "benchmark.git", }) repo := localrepo.NewTestRepo(b, cfg, repoProto) diff --git a/internal/gitaly/service/commit/tree_entries_test.go b/internal/gitaly/service/commit/tree_entries_test.go index 82be60290..ca079ee09 100644 --- a/internal/gitaly/service/commit/tree_entries_test.go +++ b/internal/gitaly/service/commit/tree_entries_test.go @@ -719,8 +719,9 @@ func BenchmarkGetTreeEntries(b *testing.B) { ctx := testhelper.Context(b) cfg, client := setupCommitService(ctx, b) - repo, _ := gittest.CloneRepo(b, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - SourceRepo: "benchmark.git", + repo, _ := gittest.CreateRepository(ctx, b, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: "benchmark.git", }) for _, tc := range []struct { diff --git a/internal/gitaly/service/internalgitaly/walkrepos_test.go b/internal/gitaly/service/internalgitaly/walkrepos_test.go index 56a8207cc..a29313e5a 100644 --- a/internal/gitaly/service/internalgitaly/walkrepos_test.go +++ b/internal/gitaly/service/internalgitaly/walkrepos_test.go @@ -39,20 +39,28 @@ func (w *streamWrapper) Send(resp *gitalypb.WalkReposResponse) error { } func TestWalkRepos(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t) + storageName := cfg.Storages[0].Name storageRoot := cfg.Storages[0].Path // file walk happens lexicographically, so we delete repository in the middle // of the sequence to ensure the walk proceeds normally - testRepo1, testRepo1Path := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: "a", + testRepo1, testRepo1Path := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: "a", }) - deletedRepo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: "b", + deletedRepo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: "b", }) - testRepo2, testRepo2Path := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: "c", + testRepo2, testRepo2Path := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + RelativePath: "c", }) modifiedDate := time.Now().Add(-1 * time.Hour) @@ -87,7 +95,6 @@ func TestWalkRepos(t *testing.T) { } client := setupInternalGitalyService(t, cfg, wsrv) - ctx := testhelper.Context(t) stream, err := client.WalkRepos(ctx, &gitalypb.WalkReposRequest{ StorageName: "invalid storage name", diff --git a/internal/gitaly/service/operations/rebase_test.go b/internal/gitaly/service/operations/rebase_test.go index 8f7742c25..80a5de039 100644 --- a/internal/gitaly/service/operations/rebase_test.go +++ b/internal/gitaly/service/operations/rebase_test.go @@ -347,7 +347,10 @@ func TestUserRebaseConfirmable_inputValidation(t *testing.T) { ctx, cfg, repo, repoPath, client := setupOperationsService(t, ctx) - repoCopy, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoCopy, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) branchCommitID := gittest.ResolveRevision(t, cfg, repoPath, rebaseBranchName) diff --git a/internal/gitaly/service/ref/find_all_tags_test.go b/internal/gitaly/service/ref/find_all_tags_test.go index d270ad956..5a34e683a 100644 --- a/internal/gitaly/service/ref/find_all_tags_test.go +++ b/internal/gitaly/service/ref/find_all_tags_test.go @@ -690,7 +690,10 @@ func BenchmarkFindAllTags(b *testing.B) { cfg, client := setupRefServiceWithoutRepo(b) - repoProto, repoPath := gittest.CloneRepo(b, cfg, cfg.Storages[0]) + repoProto, repoPath := gittest.CreateRepository(ctx, b, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) for i := 0; i < 1000; i++ { gittest.WriteTag(b, cfg, repoPath, fmt.Sprintf("%d", i), "HEAD", gittest.WriteTagConfig{ diff --git a/internal/gitaly/service/repository/archive_test.go b/internal/gitaly/service/repository/archive_test.go index ce90c525e..fbf8efe60 100644 --- a/internal/gitaly/service/repository/archive_test.go +++ b/internal/gitaly/service/repository/archive_test.go @@ -482,7 +482,10 @@ func TestGetArchive_environment(t *testing.T) { client, serverSocketPath := runRepositoryService(t, cfg, nil, testserver.WithGitCommandFactory(gitCmdFactory)) cfg.SocketPath = serverSocketPath - repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) commitID := "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863" diff --git a/internal/gitaly/service/repository/create_repository_from_bundle_test.go b/internal/gitaly/service/repository/create_repository_from_bundle_test.go index bde2bf12b..b5c7a03cd 100644 --- a/internal/gitaly/service/repository/create_repository_from_bundle_test.go +++ b/internal/gitaly/service/repository/create_repository_from_bundle_test.go @@ -265,8 +265,10 @@ func TestCreateRepositoryFromBundle_existingRepository(t *testing.T) { // The above test creates the second repository on the server. As this test can run with Praefect in front of it, // we'll use the next replica path Praefect will assign in order to ensure this repository creation conflicts even // with Praefect in front of it. - repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: praefectutil.DeriveReplicaPath(1), + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: praefectutil.DeriveReplicaPath(1), + Seed: gittest.SeedGitLabTest, }) stream, err := client.CreateRepositoryFromBundle(ctx) diff --git a/internal/gitaly/service/repository/create_repository_from_snapshot_test.go b/internal/gitaly/service/repository/create_repository_from_snapshot_test.go index c7269d370..7dbe42ff8 100644 --- a/internal/gitaly/service/repository/create_repository_from_snapshot_test.go +++ b/internal/gitaly/service/repository/create_repository_from_snapshot_test.go @@ -82,7 +82,10 @@ func TestCreateRepositoryFromSnapshot_success(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - _, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + _, sourceRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) // Ensure these won't be in the archive require.NoError(t, os.Remove(filepath.Join(sourceRepoPath, "config"))) @@ -137,8 +140,10 @@ func TestCreateRepositoryFromSnapshot_repositoryExists(t *testing.T) { // This creates the first repository on the server. As this test can run with Praefect in front of it, // we'll use the next replica path Praefect will assign in order to ensure this repository creation // conflicts even with Praefect in front of it. - repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: praefectutil.DeriveReplicaPath(1), + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: praefectutil.DeriveReplicaPath(1), + Seed: gittest.SeedGitLabTest, }) req := &gitalypb.CreateRepositoryFromSnapshotRequest{Repository: repo} @@ -153,7 +158,10 @@ func TestCreateRepositoryFromSnapshot_badURL(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) require.NoError(t, os.RemoveAll(repoPath)) req := &gitalypb.CreateRepositoryFromSnapshotRequest{ @@ -207,7 +215,10 @@ func TestCreateRepositoryFromSnapshot_invalidArguments(t *testing.T) { for _, tc := range testCases { t.Run(tc.desc, func(t *testing.T) { cfg := testcfg.Build(t) - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) require.NoError(t, os.RemoveAll(repoPath)) req := &gitalypb.CreateRepositoryFromSnapshotRequest{ @@ -231,7 +242,10 @@ func TestCreateRepositoryFromSnapshot_malformedResponse(t *testing.T) { ctx := testhelper.Context(t) cfg := testcfg.Build(t) - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) require.NoError(t, os.Remove(filepath.Join(repoPath, "config"))) require.NoError(t, os.RemoveAll(filepath.Join(repoPath, "hooks"))) diff --git a/internal/gitaly/service/repository/create_repository_test.go b/internal/gitaly/service/repository/create_repository_test.go index 52e95d467..0c956e9b3 100644 --- a/internal/gitaly/service/repository/create_repository_test.go +++ b/internal/gitaly/service/repository/create_repository_test.go @@ -207,8 +207,9 @@ func TestCreateRepository_transactional(t *testing.T) { // The above test creates the second repository on the server. As this test can run with Praefect in front of it, // we'll use the next replica path Praefect will assign in order to ensure this repository creation conflicts even // with Praefect in front of it. - repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: praefectutil.DeriveReplicaPath(2), + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: praefectutil.DeriveReplicaPath(2), }) _, err = client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{ @@ -231,8 +232,9 @@ func TestCreateRepository_idempotent(t *testing.T) { // conflicts even with Praefect in front of it. RelativePath: praefectutil.DeriveReplicaPath(1), } - gittest.CloneRepo(t, cfg, cfg.Storages[0], gittest.CloneRepoOpts{ - RelativePath: repo.RelativePath, + gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: repo.RelativePath, }) req := &gitalypb.CreateRepositoryRequest{Repository: repo} diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go index b97d3259e..b60b6c52d 100644 --- a/internal/gitaly/service/repository/fetch_test.go +++ b/internal/gitaly/service/repository/fetch_test.go @@ -138,7 +138,10 @@ func TestFetchSourceBranchWrongRef(t *testing.T) { md := testcfg.GitalyServersMetadataFromCfg(t, cfg) ctx = testhelper.MergeOutgoingMetadata(ctx, md) - sourceRepo, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + sourceRepo, sourceRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) sourceBranch := "fetch-source-branch-testmas-branch" gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch(sourceBranch)) diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go index 783379e59..9f8bf64f5 100644 --- a/internal/gitaly/service/repository/replicate_test.go +++ b/internal/gitaly/service/repository/replicate_test.go @@ -50,7 +50,10 @@ func TestReplicateRepository(t *testing.T) { client, serverSocketPath := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect()) cfg.SocketPath = serverSocketPath - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) // create a loose object to ensure snapshot replication is used blobData, err := text.RandomHex(10) @@ -210,7 +213,10 @@ func TestReplicateRepositoryTransactional(t *testing.T) { _, serverSocketPath := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect()) cfg.SocketPath = serverSocketPath - sourceRepo, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + sourceRepo, sourceRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) targetRepo := proto.Clone(sourceRepo).(*gitalypb.Repository) targetRepo.StorageName = cfg.Storages[1].Name @@ -419,9 +425,14 @@ func TestReplicateRepository_BadRepository(t *testing.T) { client, serverSocketPath := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect()) cfg.SocketPath = serverSocketPath - sourceRepo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) - targetRepo, targetRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[1], gittest.CloneRepoOpts{ - RelativePath: sourceRepo.RelativePath, + sourceRepo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) + targetRepo, targetRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Storage: cfg.Storages[1], + RelativePath: sourceRepo.RelativePath, }) var invalidRepos []*gitalypb.Repository diff --git a/internal/gitaly/service/repository/repository_test.go b/internal/gitaly/service/repository/repository_test.go index 7cc3226cc..ce650b336 100644 --- a/internal/gitaly/service/repository/repository_test.go +++ b/internal/gitaly/service/repository/repository_test.go @@ -18,6 +18,8 @@ import ( func TestRepositoryExists(t *testing.T) { t.Parallel() + + ctx := testhelper.Context(t) cfgBuilder := testcfg.NewGitalyCfgBuilder(testcfg.WithStorages("default", "other", "broken")) cfg := cfgBuilder.Build(t) @@ -25,7 +27,10 @@ func TestRepositoryExists(t *testing.T) { client, _ := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect()) - repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) queries := []struct { desc string @@ -94,7 +99,6 @@ func TestRepositoryExists(t *testing.T) { for _, tc := range queries { t.Run(tc.desc, func(t *testing.T) { - ctx := testhelper.Context(t) response, err := client.RepositoryExists(ctx, tc.request) require.Equal(t, tc.errorCode, helper.GrpcCode(err)) diff --git a/internal/gitaly/service/repository/snapshot_test.go b/internal/gitaly/service/repository/snapshot_test.go index 4dce4e410..49d1e93d7 100644 --- a/internal/gitaly/service/repository/snapshot_test.go +++ b/internal/gitaly/service/repository/snapshot_test.go @@ -252,7 +252,10 @@ func copyRepoUsingSnapshot(t *testing.T, ctx context.Context, cfg config.Cfg, cl srv := httptest.NewServer(&tarTesthandler{tarData: bytes.NewBuffer(data), secret: secret}) defer srv.Close() - repoCopy, repoCopyPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repoCopy, repoCopyPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) // Delete the repository so we can re-use the path require.NoError(t, os.RemoveAll(repoCopyPath)) diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go index 399ef04d7..1d50d2ea6 100644 --- a/internal/gitaly/service/smarthttp/receive_pack_test.go +++ b/internal/gitaly/service/smarthttp/receive_pack_test.go @@ -792,7 +792,10 @@ func TestPostReceivePack_referenceTransactionHook(t *testing.T) { stream, err := client.PostReceivePack(ctx) require.NoError(t, err) - repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) _, _, pushRequest := createPushRequest(t, cfg) response := performPush(t, stream, &gitalypb.PostReceivePackRequest{ @@ -813,7 +816,11 @@ func TestPostReceivePack_referenceTransactionHook(t *testing.T) { stream, err := client.PostReceivePack(ctx) require.NoError(t, err) - repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, repoPath := gittest.CreateRepository(ctx, t, cfg, + gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) // Create a new branch which we're about to delete. We also pack references because // this used to generate two transactions: one for the packed-refs file and one for @@ -887,7 +894,10 @@ func TestPostReceivePack_notAllowed(t *testing.T) { stream, err := client.PostReceivePack(ctx) require.NoError(t, err) - repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) _, _, pushRequest := createPushRequest(t, cfg) request := &gitalypb.PostReceivePackRequest{Repository: repo, GlId: "key-1234", GlRepository: "some_repo"} @@ -897,7 +907,12 @@ func TestPostReceivePack_notAllowed(t *testing.T) { } func createPushRequest(t *testing.T, cfg config.Cfg) (git.ObjectID, git.ObjectID, io.Reader) { - _, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + ctx := testhelper.Context(t) + + _, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) oldCommitID := git.ObjectID(text.ChompBytes(gittest.Exec(t, cfg, "-C", repoPath, "rev-parse", "HEAD"))) newCommitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithParents(oldCommitID)) diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go index 69eaed0d7..541dfa112 100644 --- a/internal/gitaly/service/ssh/receive_pack_test.go +++ b/internal/gitaly/service/ssh/receive_pack_test.go @@ -731,7 +731,12 @@ type SSHCloneDetails struct { // setupSSHClone sets up a test clone func setupSSHClone(t *testing.T, cfg config.Cfg, remoteRepo *gitalypb.Repository, remoteRepoPath string) (SSHCloneDetails, func()) { - _, localRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + ctx := testhelper.Context(t) + + _, localRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) oldHead := text.ChompBytes(gittest.Exec(t, cfg, "-C", localRepoPath, "rev-parse", "HEAD")) newHead := gittest.WriteCommit(t, cfg, localRepoPath, diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go index 8ae2bdc8e..b9349a0bc 100644 --- a/internal/praefect/replicator_test.go +++ b/internal/praefect/replicator_test.go @@ -285,7 +285,10 @@ func TestConfirmReplication(t *testing.T) { cfg, testRepoA, testRepoAPath := testcfg.BuildWithRepo(t) srvSocketPath := testserver.RunGitalyServer(t, cfg, nil, setup.RegisterAll, testserver.WithDisablePraefect()) - testRepoB, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0]) + testRepoB, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) connOpts := []grpc.DialOption{ grpc.WithTransportCredentials(insecure.NewCredentials()), diff --git a/internal/praefect/repocleaner/repository_test.go b/internal/praefect/repocleaner/repository_test.go index 0066ce747..37b2e90d7 100644 --- a/internal/praefect/repocleaner/repository_test.go +++ b/internal/praefect/repocleaner/repository_test.go @@ -74,24 +74,70 @@ func TestRunner_Run(t *testing.T) { RepositoriesInBatch: 2, } + ctx, cancel := context.WithCancel(testhelper.Context(t)) + // each gitaly has an extra repo-4.git repository - gittest.CloneRepo(t, g1Cfg, g1Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: repo1RelPath}) - gittest.CloneRepo(t, g1Cfg, g1Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: repo2RelPath}) - gittest.CloneRepo(t, g1Cfg, g1Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: repo3RelPath}) - _, repo4Path := gittest.CloneRepo(t, g1Cfg, g1Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: "repo-4.git"}) + gittest.CreateRepository(ctx, t, g1Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: repo1RelPath, + Seed: gittest.SeedGitLabTest, + }) + gittest.CreateRepository(ctx, t, g1Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: repo2RelPath, + Seed: gittest.SeedGitLabTest, + }) + gittest.CreateRepository(ctx, t, g1Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: repo3RelPath, + Seed: gittest.SeedGitLabTest, + }) + _, repo4Path := gittest.CreateRepository(ctx, t, g1Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: "repo-4.git", + Seed: gittest.SeedGitLabTest, + }) require.NoError(t, os.Chtimes(repo4Path, time.Now().Add(-25*time.Hour), time.Now().Add(-25*time.Hour))) - gittest.CloneRepo(t, g2Cfg, g2Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: repo1RelPath}) - gittest.CloneRepo(t, g2Cfg, g2Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: repo2RelPath}) - _, repo4Path = gittest.CloneRepo(t, g2Cfg, g2Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: "repo-4.git"}) + gittest.CreateRepository(ctx, t, g2Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: repo1RelPath, + Seed: gittest.SeedGitLabTest, + }) + gittest.CreateRepository(ctx, t, g2Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: repo2RelPath, + Seed: gittest.SeedGitLabTest, + }) + _, repo4Path = gittest.CreateRepository(ctx, t, g2Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: "repo-4.git", + Seed: gittest.SeedGitLabTest, + }) require.NoError(t, os.Chtimes(repo4Path, time.Now().Add(-25*time.Hour), time.Now().Add(-25*time.Hour))) - gittest.CloneRepo(t, g3Cfg, g3Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: repo1RelPath}) - gittest.CloneRepo(t, g3Cfg, g3Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: repo2RelPath}) - gittest.CloneRepo(t, g3Cfg, g3Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: repo3RelPath}) - _, repo4Path = gittest.CloneRepo(t, g3Cfg, g3Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: "repo-4.git"}) + gittest.CreateRepository(ctx, t, g3Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: repo1RelPath, + Seed: gittest.SeedGitLabTest, + }) + gittest.CreateRepository(ctx, t, g3Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: repo2RelPath, + Seed: gittest.SeedGitLabTest, + }) + gittest.CreateRepository(ctx, t, g3Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: repo3RelPath, + Seed: gittest.SeedGitLabTest, + }) + _, repo4Path = gittest.CreateRepository(ctx, t, g3Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: "repo-4.git", + Seed: gittest.SeedGitLabTest, + }) + require.NoError(t, os.Chtimes(repo4Path, time.Now().Add(-25*time.Hour), time.Now().Add(-25*time.Hour))) - ctx, cancel := context.WithCancel(testhelper.Context(t)) repoStore := datastore.NewPostgresRepositoryStore(db.DB, nil) for i, set := range []struct { @@ -207,10 +253,15 @@ func TestRunner_Run_noAvailableStorages(t *testing.T) { RepositoriesInBatch: 2, } - _, repoPath := gittest.CloneRepo(t, g1Cfg, g1Cfg.Storages[0], gittest.CloneRepoOpts{RelativePath: repo1RelPath}) - require.NoError(t, os.Chtimes(repoPath, time.Now().Add(-25*time.Hour), time.Now().Add(-25*time.Hour))) ctx, cancel := context.WithCancel(testhelper.Context(t)) + _, repoPath := gittest.CreateRepository(ctx, t, g1Cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + RelativePath: repo1RelPath, + Seed: gittest.SeedGitLabTest, + }) + require.NoError(t, os.Chtimes(repoPath, time.Now().Add(-25*time.Hour), time.Now().Add(-25*time.Hour))) + repoStore := datastore.NewPostgresRepositoryStore(db.DB, nil) for i, set := range []struct { relativePath string diff --git a/internal/tempdir/clean_test.go b/internal/tempdir/clean_test.go index 04bb6825e..b21368d06 100644 --- a/internal/tempdir/clean_test.go +++ b/internal/tempdir/clean_test.go @@ -55,10 +55,14 @@ func TestCleanSuccess(t *testing.T) { } func TestCleanTempDir(t *testing.T) { + ctx := testhelper.Context(t) cfg := testcfg.Build(t, testcfg.WithStorages("first", "second")) locator := config.NewLocator(cfg) - gittest.CloneRepo(t, cfg, cfg.Storages[0]) + gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Seed: gittest.SeedGitLabTest, + }) logrus.SetLevel(logrus.InfoLevel) logrus.SetOutput(io.Discard) diff --git a/internal/testhelper/testcfg/gitaly_builder.go b/internal/testhelper/testcfg/gitaly_builder.go index 0159525ed..d1ea23283 100644 --- a/internal/testhelper/testcfg/gitaly_builder.go +++ b/internal/testhelper/testcfg/gitaly_builder.go @@ -157,13 +157,17 @@ func (gc *GitalyCfgBuilder) Build(t testing.TB) config.Cfg { func (gc *GitalyCfgBuilder) BuildWithRepoAt(t testing.TB, relativePath string) (config.Cfg, []*gitalypb.Repository) { t.Helper() + ctx := testhelper.Context(t) cfg := gc.Build(t) // clone the test repo to the each storage repos := make([]*gitalypb.Repository, len(cfg.Storages)) for i, gitalyStorage := range cfg.Storages { - repo, _ := gittest.CloneRepo(t, cfg, gitalyStorage, gittest.CloneRepoOpts{ - RelativePath: relativePath, + repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + Storage: gitalyStorage, + RelativePath: relativePath, + Seed: gittest.SeedGitLabTest, }) repos[i] = repo |