Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-08-11 14:49:14 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-08-11 14:49:14 +0300
commitac315ef254b265af5323387a1df1abb5d57daa95 (patch)
tree6eb8cd88869f061104470f0dacca0ad5e8d1e40d
parente15d444699daaad18af204a2eeb1573ef661b5ec (diff)
parent5fd6b9caa9a09915a5cc9e012e5ad1621f837447 (diff)
Merge branch 'pks-gittest-create-repo-consolidation' into 'master'
gittest: Consolidate functions to create test repositories See merge request gitlab-org/gitaly!4795
-rw-r--r--cmd/gitaly-git2go/merge_test.go4
-rw-r--r--cmd/gitaly-hooks/hooks_test.go4
-rw-r--r--cmd/praefect/subcmd_list_untracked_repositories_test.go12
-rw-r--r--internal/cache/diskcache_test.go15
-rw-r--r--internal/git/catfile/cache_test.go44
-rw-r--r--internal/git/catfile/object_info_reader_test.go8
-rw-r--r--internal/git/catfile/object_reader_test.go12
-rw-r--r--internal/git/catfile/request_queue_test.go4
-rw-r--r--internal/git/catfile/testhelper_test.go4
-rw-r--r--internal/git/command_factory_test.go4
-rw-r--r--internal/git/decoder_test.go6
-rw-r--r--internal/git/gitpipe/catfile_info_test.go12
-rw-r--r--internal/git/gitpipe/catfile_object_test.go8
-rw-r--r--internal/git/gitpipe/diff_tree_test.go8
-rw-r--r--internal/git/gitpipe/ls_tree_test.go8
-rw-r--r--internal/git/gitpipe/pipeline_test.go15
-rw-r--r--internal/git/gitpipe/revision_test.go8
-rw-r--r--internal/git/gittest/repo.go184
-rw-r--r--internal/git/gittest/testhelper_test.go5
-rw-r--r--internal/git/housekeeping/clean_stale_data_test.go20
-rw-r--r--internal/git/housekeeping/objects_test.go9
-rw-r--r--internal/git/housekeeping/optimize_repository_test.go186
-rw-r--r--internal/git/localrepo/config_test.go17
-rw-r--r--internal/git/localrepo/paths_test.go21
-rw-r--r--internal/git/localrepo/refs_test.go4
-rw-r--r--internal/git/localrepo/remote_test.go48
-rw-r--r--internal/git/localrepo/repo_test.go66
-rw-r--r--internal/git/localrepo/testhelper_test.go5
-rw-r--r--internal/git/lstree/list_entries_test.go4
-rw-r--r--internal/git/lstree/parser_test.go6
-rw-r--r--internal/git/object_id_test.go24
-rw-r--r--internal/git/objectpool/fetch_test.go4
-rw-r--r--internal/git/quarantine/quarantine_test.go11
-rw-r--r--internal/git/stats/commit_graph_test.go8
-rw-r--r--internal/git/stats/git_test.go12
-rw-r--r--internal/git/stats/http_push_test.go10
-rw-r--r--internal/git/stats/profile_test.go6
-rw-r--r--internal/git/updateref/update_with_hooks_test.go12
-rw-r--r--internal/git/updateref/updateref_test.go8
-rw-r--r--internal/git2go/apply_test.go6
-rw-r--r--internal/git2go/commit_test.go4
-rw-r--r--internal/git2go/featureflags_test.go4
-rw-r--r--internal/gitaly/linguist/language_stats_test.go23
-rw-r--r--internal/gitaly/linguist/linguist_test.go33
-rw-r--r--internal/gitaly/rubyserver/rubyserver_test.go4
-rw-r--r--internal/gitaly/service/commit/tree_entries_test.go4
-rw-r--r--internal/gitaly/service/internalgitaly/walkrepos_test.go21
-rw-r--r--internal/gitaly/service/operations/commit_files_test.go2
-rw-r--r--internal/gitaly/service/operations/rebase_test.go4
-rw-r--r--internal/gitaly/service/ref/find_all_tags_test.go4
-rw-r--r--internal/gitaly/service/remote/find_remote_root_ref_test.go2
-rw-r--r--internal/gitaly/service/repository/archive_test.go4
-rw-r--r--internal/gitaly/service/repository/calculate_checksum_test.go14
-rw-r--r--internal/gitaly/service/repository/create_repository_from_bundle_test.go9
-rw-r--r--internal/gitaly/service/repository/create_repository_from_snapshot_test.go77
-rw-r--r--internal/gitaly/service/repository/create_repository_test.go16
-rw-r--r--internal/gitaly/service/repository/fetch_test.go4
-rw-r--r--internal/gitaly/service/repository/license_test.go6
-rw-r--r--internal/gitaly/service/repository/replicate_test.go28
-rw-r--r--internal/gitaly/service/repository/repository_test.go10
-rw-r--r--internal/gitaly/service/repository/snapshot_test.go11
-rw-r--r--internal/gitaly/service/smarthttp/receive_pack_test.go63
-rw-r--r--internal/gitaly/service/ssh/receive_pack_test.go6
-rw-r--r--internal/praefect/replicator_test.go5
-rw-r--r--internal/praefect/repocleaner/repository_test.go79
-rw-r--r--internal/tempdir/clean_test.go6
-rw-r--r--internal/testhelper/testcfg/gitaly_builder.go8
67 files changed, 843 insertions, 460 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/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/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/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 ad0377d43..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()
@@ -280,7 +282,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/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/gittest/repo.go b/internal/git/gittest/repo.go
index fb9529b1e..a2c62f9c0 100644
--- a/internal/git/gittest/repo.go
+++ b/internal/git/gittest/repo.go
@@ -94,6 +94,13 @@ type CreateRepositoryConfig struct {
// Seed determines which repository is used to seed the created repository. If unset, the repository
// is just created. The value should be one of the test repositories in _build/testrepos.
Seed string
+ // SkipCreationViaService skips creation of the repository by calling the respective RPC call.
+ // In general, this should not be skipped so that we end up in a state that is consistent
+ // and expected by both Gitaly and Praefect. It may be required though when testing at a
+ // level where there are no gRPC services available.
+ SkipCreationViaService bool
+ // ObjectFormat overrides the object format used by the repository.
+ ObjectFormat string
}
func dialService(ctx context.Context, t testing.TB, cfg config.Cfg) *grpc.ClientConn {
@@ -118,14 +125,11 @@ func CreateRepository(ctx context.Context, t testing.TB, cfg config.Cfg, configs
opts = configs[0]
}
- conn := opts.ClientConn
- if conn == nil {
- conn = dialService(ctx, t, cfg)
- t.Cleanup(func() { conn.Close() })
+ if ObjectHashIsSHA256() || opts.ObjectFormat != "" {
+ require.Empty(t, opts.Seed, "seeded repository creation not supported with non-default object format")
+ require.True(t, opts.SkipCreationViaService, "repository creation via service not supported with non-default object format")
}
- client := gitalypb.NewRepositoryServiceClient(conn)
-
storage := cfg.Storages[0]
if (opts.Storage != config.Storage{}) {
storage = opts.Storage
@@ -143,47 +147,69 @@ func CreateRepository(ctx context.Context, t testing.TB, cfg config.Cfg, configs
GlProjectPath: GlProjectPath,
}
- if opts.Seed != "" {
- if ObjectHashIsSHA256() {
- require.FailNow(t, "seeded repository creation not supported with SHA256")
+ var repoPath string
+ if !opts.SkipCreationViaService {
+ conn := opts.ClientConn
+ if conn == nil {
+ conn = dialService(ctx, t, cfg)
+ t.Cleanup(func() { testhelper.MustClose(t, conn) })
}
-
- _, err := client.CreateRepositoryFromURL(ctx, &gitalypb.CreateRepositoryFromURLRequest{
- Repository: repository,
- Url: testRepositoryPath(t, opts.Seed),
- Mirror: true,
- })
- require.NoError(t, err)
- } else {
- if ObjectHashIsSHA256() {
- require.FailNow(t, "CreateRepository does not yet support creating SHA256 repositories")
+ client := gitalypb.NewRepositoryServiceClient(conn)
+
+ if opts.Seed != "" {
+ _, err := client.CreateRepositoryFromURL(ctx, &gitalypb.CreateRepositoryFromURLRequest{
+ Repository: repository,
+ Url: testRepositoryPath(t, opts.Seed),
+ Mirror: true,
+ })
+ require.NoError(t, err)
+ } else {
+ _, err := client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{
+ Repository: repository,
+ })
+ require.NoError(t, err)
}
- _, err := client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{
- Repository: repository,
- })
- require.NoError(t, err)
- }
+ t.Cleanup(func() {
+ // The ctx parameter would be canceled by now as the tests defer the cancellation.
+ _, err := client.RemoveRepository(context.TODO(), &gitalypb.RemoveRepositoryRequest{
+ Repository: repository,
+ })
- t.Cleanup(func() {
- // The ctx parameter would be canceled by now as the tests defer the cancellation.
- _, err := client.RemoveRepository(context.TODO(), &gitalypb.RemoveRepositoryRequest{
- Repository: repository,
+ if st, ok := status.FromError(err); ok && st.Code() == codes.NotFound {
+ // The tests may delete the repository, so this is not a failure.
+ return
+ }
+
+ require.NoError(t, err)
})
- if st, ok := status.FromError(err); ok && st.Code() == codes.NotFound {
- // The tests may delete the repository, so this is not a failure.
- return
+ repoPath = filepath.Join(storage.Path, getReplicaPath(ctx, t, conn, repository))
+ } else {
+ repoPath = filepath.Join(storage.Path, repository.RelativePath)
+
+ if opts.Seed != "" {
+ Exec(t, cfg, "clone", "--no-hardlinks", "--dissociate", "--bare", testRepositoryPath(t, opts.Seed), repoPath)
+ Exec(t, cfg, "-C", repoPath, "remote", "remove", "origin")
+ } else {
+ args := []string{"init", "--bare"}
+ args = append(args, initRepoExtraArgs...)
+ args = append(args, repoPath)
+ if opts.ObjectFormat != "" {
+ args = append(args, "--object-format", opts.ObjectFormat)
+ }
+
+ Exec(t, cfg, args...)
}
- require.NoError(t, err)
- })
+ t.Cleanup(func() { require.NoError(t, os.RemoveAll(repoPath)) })
+ }
// Return a cloned repository so the above clean up function still targets the correct repository
// if the tests modify the returned repository.
clonedRepo := proto.Clone(repository).(*gitalypb.Repository)
- return clonedRepo, filepath.Join(storage.Path, getReplicaPath(ctx, t, conn, repository))
+ return clonedRepo, repoPath
}
// GetReplicaPathConfig allows for configuring the GetReplicaPath call.
@@ -243,96 +269,6 @@ func RewrittenRepository(ctx context.Context, t testing.TB, cfg config.Cfg, repo
return rewritten
}
-// InitRepoOpts contains options for InitRepo.
-type InitRepoOpts struct {
- // WithRelativePath determines the relative path of this repository.
- WithRelativePath string
- // ObjectFormat overrides the object format used by the repository.
- ObjectFormat string
-}
-
-// InitRepo creates a new empty repository in the given storage. You can either pass no or exactly
-// one InitRepoOpts.
-func InitRepo(t testing.TB, cfg config.Cfg, storage config.Storage, opts ...InitRepoOpts) (*gitalypb.Repository, string) {
- require.Less(t, len(opts), 2, "you must either pass no or exactly one option")
-
- opt := InitRepoOpts{}
- if len(opts) == 1 {
- opt = opts[0]
- }
-
- relativePath := opt.WithRelativePath
- if relativePath == "" {
- relativePath = NewRepositoryName(t, true)
- }
- repoPath := filepath.Join(storage.Path, relativePath)
-
- args := []string{"init", "--bare"}
- args = append(args, initRepoExtraArgs...)
- args = append(args, repoPath)
- if opt.ObjectFormat != "" {
- args = append(args, "--object-format", opt.ObjectFormat)
- }
-
- Exec(t, cfg, args...)
-
- repo := InitRepoDir(t, storage.Path, relativePath)
- repo.StorageName = storage.Name
-
- t.Cleanup(func() { require.NoError(t, os.RemoveAll(repoPath)) })
-
- return repo, repoPath
-}
-
-// CloneRepoOpts is an option for CloneRepo.
-type CloneRepoOpts struct {
- // RelativePath determines the relative path of newly created Git repository. If unset, the
- // relative path is computed via NewRepositoryName.
- RelativePath string
- // SourceRepo determines the name of the source repository which shall be cloned. The source
- // repository is assumed to be relative to "_build/testrepos". If unset, defaults to
- // "gitlab-test.git".
- SourceRepo string
-}
-
-// CloneRepo clones a new copy of test repository under a subdirectory in the storage root. You can
-// either pass no or exactly one CloneRepoOpts.
-func CloneRepo(t testing.TB, cfg config.Cfg, storage config.Storage, opts ...CloneRepoOpts) (*gitalypb.Repository, string) {
- if ObjectHashIsSHA256() {
- require.FailNow(t, "seeded repository creation not supported with SHA256")
- }
-
- require.Less(t, len(opts), 2, "you must either pass no or exactly one option")
-
- opt := CloneRepoOpts{}
- if len(opts) == 1 {
- opt = opts[0]
- }
-
- relativePath := opt.RelativePath
- if relativePath == "" {
- relativePath = NewRepositoryName(t, true)
- }
-
- sourceRepo := opt.SourceRepo
- if sourceRepo == "" {
- sourceRepo = "gitlab-test.git"
- }
-
- repo := InitRepoDir(t, storage.Path, relativePath)
- repo.StorageName = storage.Name
-
- args := []string{"clone", "--no-hardlinks", "--dissociate", "--bare"}
-
- absolutePath := filepath.Join(storage.Path, relativePath)
- Exec(t, cfg, append(args, testRepositoryPath(t, sourceRepo), absolutePath)...)
- Exec(t, cfg, "-C", absolutePath, "remote", "remove", "origin")
-
- t.Cleanup(func() { require.NoError(t, os.RemoveAll(absolutePath)) })
-
- return repo, absolutePath
-}
-
// BundleRepo creates a bundle of a repository. `patterns` define the bundle contents as per
// `git-rev-list-args`. If there are no patterns then `--all` is assumed.
func BundleRepo(t testing.TB, cfg config.Cfg, repoPath, bundlePath string, patterns ...string) {
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..030ab1eef 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
},
@@ -51,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
},
@@ -65,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
@@ -83,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")
@@ -99,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")
@@ -116,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")
@@ -189,8 +201,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 +314,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 +393,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 +446,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 +530,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 +545,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
},
@@ -537,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
},
@@ -553,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
@@ -568,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
@@ -594,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")
@@ -609,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")
@@ -642,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")
@@ -680,8 +714,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++ {
@@ -732,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{
@@ -760,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{})
@@ -799,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
@@ -852,8 +899,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 +911,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 +925,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 +940,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 +957,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 +1039,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 +1050,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 +1063,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 +1078,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 +1102,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 +1123,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 +1144,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 +1166,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 +1209,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/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/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..9199f6eb8 100644
--- a/internal/gitaly/linguist/language_stats_test.go
+++ b/internal/gitaly/linguist/language_stats_test.go
@@ -13,12 +13,14 @@ 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"
)
func TestNewLanguageStats(t *testing.T) {
t.Parallel()
+ ctx := testhelper.Context(t)
cfg := testcfg.Build(t)
for _, tc := range []struct {
@@ -82,7 +84,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)
})
@@ -92,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 {
@@ -159,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 {
@@ -214,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 cd9d68f63..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)},
@@ -125,7 +128,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!"},
@@ -140,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)},
@@ -170,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)},
@@ -192,7 +204,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 +244,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")
},
@@ -322,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/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/commit/tree_entries_test.go b/internal/gitaly/service/commit/tree_entries_test.go
index 82be60290..e763619a4 100644
--- a/internal/gitaly/service/commit/tree_entries_test.go
+++ b/internal/gitaly/service/commit/tree_entries_test.go
@@ -719,8 +719,8 @@ 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{
+ 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/commit_files_test.go b/internal/gitaly/service/operations/commit_files_test.go
index 24bed724c..1c23a7646 100644
--- a/internal/gitaly/service/operations/commit_files_test.go
+++ b/internal/gitaly/service/operations/commit_files_test.go
@@ -1293,7 +1293,7 @@ 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)
newRepo := localrepo.NewTestRepo(t, cfg, newRepoProto)
targetBranchName := "new"
diff --git a/internal/gitaly/service/operations/rebase_test.go b/internal/gitaly/service/operations/rebase_test.go
index 8f7742c25..d8e216d94 100644
--- a/internal/gitaly/service/operations/rebase_test.go
+++ b/internal/gitaly/service/operations/rebase_test.go
@@ -347,7 +347,9 @@ 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{
+ 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..eba8e28e1 100644
--- a/internal/gitaly/service/ref/find_all_tags_test.go
+++ b/internal/gitaly/service/ref/find_all_tags_test.go
@@ -690,7 +690,9 @@ 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{
+ 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/remote/find_remote_root_ref_test.go b/internal/gitaly/service/remote/find_remote_root_ref_test.go
index f0690ca01..193946176 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,7 @@ func TestFindRemoteRootRefWithUnbornRemoteHead(t *testing.T) {
// We're creating an empty repository. Empty repositories do have a HEAD set up, but they
// point to an unborn branch because the default branch hasn't yet been created.
- _, clientRepoPath := gittest.InitRepo(t, cfg, cfg.Storages[0])
+ _, clientRepoPath := gittest.CreateRepository(ctx, t, cfg)
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/archive_test.go b/internal/gitaly/service/repository/archive_test.go
index ce90c525e..b5ac1f0d2 100644
--- a/internal/gitaly/service/repository/archive_test.go
+++ b/internal/gitaly/service/repository/archive_test.go
@@ -482,7 +482,9 @@ 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{
+ Seed: gittest.SeedGitLabTest,
+ })
commitID := "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863"
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/create_repository_from_bundle_test.go b/internal/gitaly/service/repository/create_repository_from_bundle_test.go
index bde2bf12b..015b0d9e6 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,9 @@ 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{
+ repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
RelativePath: praefectutil.DeriveReplicaPath(1),
+ Seed: gittest.SeedGitLabTest,
})
stream, err := client.CreateRepositoryFromBundle(ctx)
@@ -277,7 +278,11 @@ func TestCreateRepositoryFromBundle_existingRepository(t *testing.T) {
}))
_, err = stream.CloseAndRecv()
- testhelper.RequireGrpcError(t, status.Error(codes.AlreadyExists, "creating repository: repository exists already"), err)
+ if testhelper.IsPraefectEnabled() {
+ testhelper.ProtoEqual(t, status.Error(codes.AlreadyExists, "route repository creation: reserve repository id: repository already exists"), err)
+ } else {
+ testhelper.ProtoEqual(t, status.Error(codes.AlreadyExists, "creating repository: repository exists already"), err)
+ }
}
func TestSanitizedError(t *testing.T) {
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..a5983eb68 100644
--- a/internal/gitaly/service/repository/create_repository_from_snapshot_test.go
+++ b/internal/gitaly/service/repository/create_repository_from_snapshot_test.go
@@ -4,7 +4,6 @@ package repository
import (
"bytes"
- "context"
"io"
"net/http"
"net/http/httptest"
@@ -16,7 +15,6 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/archive"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/praefectutil"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
@@ -69,20 +67,18 @@ func generateTarFile(t *testing.T, path string) ([]byte, []string) {
return data, entries
}
-func createFromSnapshot(t *testing.T, ctx context.Context, req *gitalypb.CreateRepositoryFromSnapshotRequest, cfg config.Cfg) (*gitalypb.CreateRepositoryFromSnapshotResponse, error) {
- t.Helper()
-
- client, _ := runRepositoryService(t, cfg, nil)
-
- return client.CreateRepositoryFromSnapshot(ctx, req)
-}
-
func TestCreateRepositoryFromSnapshot_success(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
cfg := testcfg.Build(t)
- _, sourceRepoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+
+ client, socketPath := runRepositoryService(t, cfg, nil)
+ cfg.SocketPath = socketPath
+
+ _, sourceRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
// Ensure these won't be in the archive
require.NoError(t, os.Remove(filepath.Join(sourceRepoPath, "config")))
@@ -107,9 +103,6 @@ func TestCreateRepositoryFromSnapshot_success(t *testing.T) {
HttpHost: host,
}
- client, socketPath := runRepositoryService(t, cfg, nil)
- cfg.SocketPath = socketPath
-
rsp, err := client.CreateRepositoryFromSnapshot(ctx, req)
require.NoError(t, err)
testhelper.ProtoEqual(t, rsp, &gitalypb.CreateRepositoryFromSnapshotResponse{})
@@ -133,35 +126,45 @@ func TestCreateRepositoryFromSnapshot_repositoryExists(t *testing.T) {
ctx := testhelper.Context(t)
cfg := testcfg.Build(t)
+ client, socketPath := runRepositoryService(t, cfg, nil)
+ cfg.SocketPath = socketPath
// 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{
+ repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
RelativePath: praefectutil.DeriveReplicaPath(1),
+ Seed: gittest.SeedGitLabTest,
})
req := &gitalypb.CreateRepositoryFromSnapshotRequest{Repository: repo}
- rsp, err := createFromSnapshot(t, ctx, req, cfg)
+ rsp, err := client.CreateRepositoryFromSnapshot(ctx, req)
testhelper.RequireGrpcCode(t, err, codes.AlreadyExists)
- require.Contains(t, err.Error(), "creating repository: repository exists already")
+ if testhelper.IsPraefectEnabled() {
+ require.Contains(t, err.Error(), "route repository creation: reserve repository id: repository already exists")
+ } else {
+ require.Contains(t, err.Error(), "creating repository: repository exists already")
+ }
require.Nil(t, rsp)
}
func TestCreateRepositoryFromSnapshot_badURL(t *testing.T) {
t.Parallel()
- ctx := testhelper.Context(t)
+ ctx := testhelper.Context(t)
cfg := testcfg.Build(t)
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
- require.NoError(t, os.RemoveAll(repoPath))
+ client, socketPath := runRepositoryService(t, cfg, nil)
+ cfg.SocketPath = socketPath
req := &gitalypb.CreateRepositoryFromSnapshotRequest{
- Repository: repo,
- HttpUrl: "invalid!scheme://invalid.invalid",
+ Repository: &gitalypb.Repository{
+ StorageName: cfg.Storages[0].Name,
+ RelativePath: gittest.NewRepositoryName(t, true),
+ },
+ HttpUrl: "invalid!scheme://invalid.invalid",
}
- rsp, err := createFromSnapshot(t, ctx, req, cfg)
+ rsp, err := client.CreateRepositoryFromSnapshot(ctx, req)
testhelper.RequireGrpcCode(t, err, codes.InvalidArgument)
require.Contains(t, err.Error(), "Bad HTTP URL")
require.Nil(t, rsp)
@@ -207,20 +210,22 @@ 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])
- require.NoError(t, os.RemoveAll(repoPath))
+ client, socketPath := runRepositoryService(t, cfg, nil)
+ cfg.SocketPath = socketPath
req := &gitalypb.CreateRepositoryFromSnapshotRequest{
- Repository: repo,
- HttpUrl: srv.URL + tc.url,
- HttpAuth: tc.auth,
- HttpHost: host,
+ Repository: &gitalypb.Repository{
+ StorageName: cfg.Storages[0].Name,
+ RelativePath: gittest.NewRepositoryName(t, true),
+ },
+ HttpUrl: srv.URL + tc.url,
+ HttpAuth: tc.auth,
+ HttpHost: host,
}
- rsp, err := createFromSnapshot(t, ctx, req, cfg)
+ rsp, err := client.CreateRepositoryFromSnapshot(ctx, req)
testhelper.RequireGrpcCode(t, err, tc.code)
require.Nil(t, rsp)
-
require.Contains(t, err.Error(), tc.errContains)
})
}
@@ -231,7 +236,12 @@ func TestCreateRepositoryFromSnapshot_malformedResponse(t *testing.T) {
ctx := testhelper.Context(t)
cfg := testcfg.Build(t)
- repo, repoPath := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ client, socketPath := runRepositoryService(t, cfg, nil)
+ cfg.SocketPath = socketPath
+
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
require.NoError(t, os.Remove(filepath.Join(repoPath, "config")))
require.NoError(t, os.RemoveAll(filepath.Join(repoPath, "hooks")))
@@ -253,8 +263,7 @@ func TestCreateRepositoryFromSnapshot_malformedResponse(t *testing.T) {
HttpHost: host,
}
- rsp, err := createFromSnapshot(t, ctx, req, cfg)
-
+ rsp, err := client.CreateRepositoryFromSnapshot(ctx, req)
require.Error(t, err)
require.Nil(t, rsp)
diff --git a/internal/gitaly/service/repository/create_repository_test.go b/internal/gitaly/service/repository/create_repository_test.go
index 52e95d467..d1976715e 100644
--- a/internal/gitaly/service/repository/create_repository_test.go
+++ b/internal/gitaly/service/repository/create_repository_test.go
@@ -207,14 +207,18 @@ 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{
+ repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
RelativePath: praefectutil.DeriveReplicaPath(2),
})
_, err = client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{
Repository: repo,
})
- testhelper.ProtoEqual(t, status.Error(codes.AlreadyExists, "creating repository: repository exists already"), err)
+ if testhelper.IsPraefectEnabled() {
+ testhelper.ProtoEqual(t, status.Error(codes.AlreadyExists, "route repository creation: reserve repository id: repository already exists"), err)
+ } else {
+ testhelper.ProtoEqual(t, status.Error(codes.AlreadyExists, "creating repository: repository exists already"), err)
+ }
})
}
@@ -231,11 +235,15 @@ 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{
+ gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
RelativePath: repo.RelativePath,
})
req := &gitalypb.CreateRepositoryRequest{Repository: repo}
_, err := client.CreateRepository(ctx, req)
- testhelper.ProtoEqual(t, status.Error(codes.AlreadyExists, "creating repository: repository exists already"), err)
+ if testhelper.IsPraefectEnabled() {
+ testhelper.ProtoEqual(t, status.Error(codes.AlreadyExists, "route repository creation: reserve repository id: repository already exists"), err)
+ } else {
+ testhelper.ProtoEqual(t, status.Error(codes.AlreadyExists, "creating repository: repository exists already"), err)
+ }
}
diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go
index b97d3259e..7a3a281fd 100644
--- a/internal/gitaly/service/repository/fetch_test.go
+++ b/internal/gitaly/service/repository/fetch_test.go
@@ -138,7 +138,9 @@ 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{
+ Seed: gittest.SeedGitLabTest,
+ })
sourceBranch := "fetch-source-branch-testmas-branch"
gittest.WriteCommit(t, cfg, sourceRepoPath, gittest.WithBranch(sourceBranch))
diff --git a/internal/gitaly/service/repository/license_test.go b/internal/gitaly/service/repository/license_test.go
index bd38c746b..a32171779 100644
--- a/internal/gitaly/service/repository/license_test.go
+++ b/internal/gitaly/service/repository/license_test.go
@@ -108,11 +108,7 @@ 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])
- require.NoError(t, os.RemoveAll(repoPath))
-
- _, err := client.CreateRepository(ctx, &gitalypb.CreateRepositoryRequest{Repository: repo})
- require.NoError(t, err)
+ repo, _ := gittest.CreateRepository(ctx, t, cfg)
resp, err := client.FindLicense(ctx, &gitalypb.FindLicenseRequest{Repository: repo})
require.NoError(t, err)
diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go
index 1908cbbbb..b35123e7a 100644
--- a/internal/gitaly/service/repository/replicate_test.go
+++ b/internal/gitaly/service/repository/replicate_test.go
@@ -50,7 +50,9 @@ 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{
+ Seed: gittest.SeedGitLabTest,
+ })
// create a loose object to ensure snapshot replication is used
blobData, err := text.RandomHex(10)
@@ -124,7 +126,7 @@ 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)
// 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 +158,10 @@ 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)
+ targetRepo, targetRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ RelativePath: sourceRepo.GetRelativePath(),
+ Storage: cfg.Storages[1],
})
// Create the same commit in both repositories so that they're in a known-good
@@ -203,7 +206,9 @@ 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{
+ Seed: gittest.SeedGitLabTest,
+ })
targetRepo := proto.Clone(sourceRepo).(*gitalypb.Repository)
targetRepo.StorageName = cfg.Storages[1].Name
@@ -412,8 +417,11 @@ 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{
+ sourceRepo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
+ targetRepo, targetRepoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ Storage: cfg.Storages[1],
RelativePath: sourceRepo.RelativePath,
})
@@ -466,7 +474,9 @@ 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{
+ 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
diff --git a/internal/gitaly/service/repository/repository_test.go b/internal/gitaly/service/repository/repository_test.go
index 7cc3226cc..74faba1c7 100644
--- a/internal/gitaly/service/repository/repository_test.go
+++ b/internal/gitaly/service/repository/repository_test.go
@@ -18,14 +18,19 @@ import (
func TestRepositoryExists(t *testing.T) {
t.Parallel()
+
+ ctx := testhelper.Context(t)
cfgBuilder := testcfg.NewGitalyCfgBuilder(testcfg.WithStorages("default", "other", "broken"))
cfg := cfgBuilder.Build(t)
require.NoError(t, os.RemoveAll(cfg.Storages[2].Path), "third storage needs to be invalid")
- client, _ := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect())
+ client, socketPath := runRepositoryService(t, cfg, nil, testserver.WithDisablePraefect())
+ cfg.SocketPath = socketPath
- repo, _ := gittest.CloneRepo(t, cfg, cfg.Storages[0])
+ repo, _ := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
+ 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..ecc32563c 100644
--- a/internal/gitaly/service/repository/snapshot_test.go
+++ b/internal/gitaly/service/repository/snapshot_test.go
@@ -252,10 +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])
-
- // Delete the repository so we can re-use the path
- require.NoError(t, os.RemoveAll(repoCopyPath))
+ repoCopy := &gitalypb.Repository{
+ StorageName: cfg.Storages[0].Name,
+ RelativePath: gittest.NewRepositoryName(t, true),
+ }
createRepoReq := &gitalypb.CreateRepositoryFromSnapshotRequest{
Repository: repoCopy,
@@ -266,7 +266,8 @@ func copyRepoUsingSnapshot(t *testing.T, ctx context.Context, cfg config.Cfg, cl
rsp, err := client.CreateRepositoryFromSnapshot(ctx, createRepoReq)
require.NoError(t, err)
testhelper.ProtoEqual(t, rsp, &gitalypb.CreateRepositoryFromSnapshotResponse{})
- return repoCopy, repoCopyPath
+
+ return repoCopy, filepath.Join(cfg.Storages[0].Path, gittest.GetReplicaPath(ctx, t, cfg, repoCopy))
}
func TestGetSnapshotFailsIfRepositoryMissing(t *testing.T) {
diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go
index 399ef04d7..df6e855ed 100644
--- a/internal/gitaly/service/smarthttp/receive_pack_test.go
+++ b/internal/gitaly/service/smarthttp/receive_pack_test.go
@@ -20,8 +20,6 @@ import (
"gitlab.com/gitlab-org/gitaly/v15/internal/git/pktline"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
gitalyhook "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
- "gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service/hook"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitlab"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
@@ -761,28 +759,23 @@ func (t *testTransactionServer) VoteTransaction(ctx context.Context, in *gitalyp
func TestPostReceivePack_referenceTransactionHook(t *testing.T) {
t.Parallel()
- ctx := testhelper.Context(t)
+ ctxWithoutTransaction := testhelper.Context(t)
cfg := testcfg.Build(t)
testcfg.BuildGitalyHooks(t, cfg)
refTransactionServer := &testTransactionServer{}
- addr := testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterSmartHTTPServiceServer(srv, NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetTxManager(),
- deps.GetDiskCache(),
- ))
- gitalypb.RegisterHookServiceServer(srv, hook.NewServer(deps.GetHookManager(), deps.GetGitCmdFactory(), deps.GetPackObjectsCache(), deps.GetPackObjectsConcurrencyTracker()))
- }, testserver.WithDisablePraefect())
-
- ctx, err := txinfo.InjectTransaction(ctx, 1234, "primary", true)
+ server := startSmartHTTPServerWithOptions(t, cfg, nil, []testserver.GitalyServerOpt{
+ testserver.WithDisablePraefect(),
+ })
+ cfg.SocketPath = server.Address()
+
+ ctx, err := txinfo.InjectTransaction(ctxWithoutTransaction, 1234, "primary", true)
require.NoError(t, err)
ctx = metadata.IncomingToOutgoing(ctx)
- client := newMuxedSmartHTTPClient(t, ctx, addr, cfg.Auth.Token, func() backchannel.Server {
+ client := newMuxedSmartHTTPClient(t, ctx, server.Address(), cfg.Auth.Token, func() backchannel.Server {
srv := grpc.NewServer()
gitalypb.RegisterRefTransactionServer(srv, refTransactionServer)
return srv
@@ -792,7 +785,9 @@ 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(ctxWithoutTransaction, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
_, _, pushRequest := createPushRequest(t, cfg)
response := performPush(t, stream, &gitalypb.PostReceivePackRequest{
@@ -813,7 +808,10 @@ 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(ctxWithoutTransaction, t, cfg,
+ gittest.CreateRepositoryConfig{
+ 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
@@ -864,21 +862,18 @@ func TestPostReceivePack_notAllowed(t *testing.T) {
gitalyhook.NopUpdate,
gitalyhook.NopReferenceTransaction,
)
- addr := testserver.RunGitalyServer(t, cfg, nil, func(srv *grpc.Server, deps *service.Dependencies) {
- gitalypb.RegisterSmartHTTPServiceServer(srv, NewServer(
- deps.GetLocator(),
- deps.GetGitCmdFactory(),
- deps.GetTxManager(),
- deps.GetDiskCache(),
- ))
- gitalypb.RegisterHookServiceServer(srv, hook.NewServer(deps.GetHookManager(), deps.GetGitCmdFactory(), deps.GetPackObjectsCache(), deps.GetPackObjectsConcurrencyTracker()))
- }, testserver.WithDisablePraefect(), testserver.WithHookManager(hookManager))
-
- ctx, err := txinfo.InjectTransaction(testhelper.Context(t), 1234, "primary", true)
+
+ server := startSmartHTTPServerWithOptions(t, cfg, nil, []testserver.GitalyServerOpt{
+ testserver.WithDisablePraefect(), testserver.WithHookManager(hookManager),
+ })
+ cfg.SocketPath = server.Address()
+
+ ctxWithoutTransaction := testhelper.Context(t)
+ ctx, err := txinfo.InjectTransaction(ctxWithoutTransaction, 1234, "primary", true)
require.NoError(t, err)
ctx = metadata.IncomingToOutgoing(ctx)
- client := newMuxedSmartHTTPClient(t, ctx, addr, cfg.Auth.Token, func() backchannel.Server {
+ client := newMuxedSmartHTTPClient(t, ctx, server.Address(), cfg.Auth.Token, func() backchannel.Server {
srv := grpc.NewServer()
gitalypb.RegisterRefTransactionServer(srv, refTransactionServer)
return srv
@@ -887,7 +882,9 @@ 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(ctxWithoutTransaction, t, cfg, gittest.CreateRepositoryConfig{
+ Seed: gittest.SeedGitLabTest,
+ })
_, _, pushRequest := createPushRequest(t, cfg)
request := &gitalypb.PostReceivePackRequest{Repository: repo, GlId: "key-1234", GlRepository: "some_repo"}
@@ -897,7 +894,11 @@ 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{
+ 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..0f9317696 100644
--- a/internal/gitaly/service/ssh/receive_pack_test.go
+++ b/internal/gitaly/service/ssh/receive_pack_test.go
@@ -731,7 +731,11 @@ 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{
+ 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