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>2023-01-10 11:52:51 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2023-01-12 12:56:15 +0300
commit077fe1a8996e3ee6ef0e288491962154cb89e0af (patch)
treede0416cae1fbf35a617980210f0b3effbaf4b7b3 /internal
parent863ea5eccf9b0f4e2de290b7cf04ec5e8f8ddf45 (diff)
testcfg: Convert callers of `BuildWithRepo()`
The `BuildWithRepo()` function builds a Gitaly configuration and at the same time creates a seed repository. There's two issues with this: - It is a layering violation as the configuration-related code should not depend on the repository-related logic. This means that e.g. the `gittest` package cannot depend on the `testcfg` package even though it is at a conceptually higher level. - It hides away the parameters used to create the repository. This means that we use seed repositories by default, but also that we skip creation via the Repository service. Both are bad and should require the caller to explicitly state that they want this. Convert callers of `BuildWithRepo()` to instead use `Build()` to build the configuration and `gittest.CreateRepository()` to create the repository. Remove the now-unused `BuildWithRepo()` function.
Diffstat (limited to 'internal')
-rw-r--r--internal/backup/locator_test.go27
-rw-r--r--internal/git/hooks_options_test.go14
-rw-r--r--internal/git/hooks_payload_test.go10
-rw-r--r--internal/git/quarantine/quarantine_test.go22
-rw-r--r--internal/gitaly/hook/custom_test.go54
-rw-r--r--internal/gitaly/hook/postreceive_test.go27
-rw-r--r--internal/gitaly/hook/prereceive_test.go27
-rw-r--r--internal/gitaly/hook/transactions_test.go19
-rw-r--r--internal/gitaly/hook/update_test.go17
-rw-r--r--internal/gitaly/rubyserver/proxy_test.go22
-rw-r--r--internal/gitaly/rubyserver/rubyserver_test.go7
-rw-r--r--internal/gitaly/server/auth_test.go9
-rw-r--r--internal/gitaly/service/hook/post_receive_test.go19
-rw-r--r--internal/gitaly/service/hook/pre_receive_test.go9
-rw-r--r--internal/gitaly/service/operations/branches_test.go14
-rw-r--r--internal/gitaly/service/repository/fetch_bundle_test.go7
-rw-r--r--internal/gitaly/service/repository/fetch_remote_test.go16
-rw-r--r--internal/gitaly/service/repository/replicate_test.go21
-rw-r--r--internal/gitaly/service/repository/search_files_test.go10
-rw-r--r--internal/gitlab/http_client_test.go30
-rw-r--r--internal/middleware/commandstatshandler/commandstatshandler_test.go10
-rw-r--r--internal/praefect/coordinator_test.go10
-rw-r--r--internal/praefect/middleware/errorhandler_test.go7
-rw-r--r--internal/praefect/replicator_test.go33
-rw-r--r--internal/praefect/server_factory_test.go12
-rw-r--r--internal/praefect/server_test.go20
-rw-r--r--internal/testhelper/testcfg/gitaly.go27
27 files changed, 370 insertions, 130 deletions
diff --git a/internal/backup/locator_test.go b/internal/backup/locator_test.go
index 0f2665c4e..9fbefc8f5 100644
--- a/internal/backup/locator_test.go
+++ b/internal/backup/locator_test.go
@@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"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"
)
@@ -19,12 +20,18 @@ import (
func TestLegacyLocator(t *testing.T) {
t.Parallel()
- _, repo, _ := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ RelativePath: t.Name(),
+ })
l := LegacyLocator{}
t.Run("Begin/Commit Full", func(t *testing.T) {
t.Parallel()
- ctx := testhelper.Context(t)
expected := &Step{
SkippableOnNotFound: true,
@@ -41,7 +48,6 @@ func TestLegacyLocator(t *testing.T) {
t.Run("FindLatest", func(t *testing.T) {
t.Parallel()
- ctx := testhelper.Context(t)
expected := &Backup{
Steps: []Step{
@@ -66,7 +72,14 @@ func TestPointerLocator(t *testing.T) {
const backupID = "abc123"
- _, repo, _ := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ RelativePath: t.Name(),
+ })
t.Run("Begin/Commit full", func(t *testing.T) {
t.Parallel()
@@ -75,7 +88,6 @@ func TestPointerLocator(t *testing.T) {
var l Locator = PointerLocator{
Sink: NewFilesystemSink(backupPath),
}
- ctx := testhelper.Context(t)
const expectedIncrement = "001"
expected := &Step{
@@ -127,7 +139,6 @@ func TestPointerLocator(t *testing.T) {
backupPath := testhelper.TempDir(t)
sink := NewFilesystemSink(backupPath)
var l Locator = PointerLocator{Sink: sink}
- ctx := testhelper.Context(t)
if tc.setup != nil {
tc.setup(t, ctx, sink)
@@ -174,7 +185,6 @@ func TestPointerLocator(t *testing.T) {
var l Locator = PointerLocator{
Sink: NewFilesystemSink(backupPath),
}
- ctx := testhelper.Context(t)
_, err := l.FindLatest(ctx, repo)
require.ErrorIs(t, err, ErrDoesntExist)
@@ -217,7 +227,6 @@ func TestPointerLocator(t *testing.T) {
Sink: NewFilesystemSink(backupPath),
Fallback: LegacyLocator{},
}
- ctx := testhelper.Context(t)
expectedFallback := &Backup{
Steps: []Step{
@@ -259,7 +268,6 @@ func TestPointerLocator(t *testing.T) {
var l Locator = PointerLocator{
Sink: NewFilesystemSink(backupPath),
}
- ctx := testhelper.Context(t)
_, err := l.FindLatest(ctx, repo)
require.ErrorIs(t, err, ErrDoesntExist)
@@ -277,7 +285,6 @@ func TestPointerLocator(t *testing.T) {
var l Locator = PointerLocator{
Sink: NewFilesystemSink(backupPath),
}
- ctx := testhelper.Context(t)
_, err := l.FindLatest(ctx, repo)
require.ErrorIs(t, err, ErrDoesntExist)
diff --git a/internal/git/hooks_options_test.go b/internal/git/hooks_options_test.go
index 504d78bc5..d6689df9a 100644
--- a/internal/git/hooks_options_test.go
+++ b/internal/git/hooks_options_test.go
@@ -17,8 +17,13 @@ import (
)
func TestWithRefHook(t *testing.T) {
- cfg, repo, _ := testcfg.BuildWithRepo(t)
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
opt := git.WithRefTxHook(repo)
subCmd := git.Command{Name: "update-ref", Args: []string{"refs/heads/master", git.ObjectHashSHA1.ZeroOID.String()}}
@@ -61,10 +66,15 @@ func TestWithRefHook(t *testing.T) {
}
func TestWithPackObjectsHookEnv(t *testing.T) {
- cfg, repo, _ := testcfg.BuildWithRepo(t)
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
cfg.PackObjectsCache.Enabled = true
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
userID := "user-123"
username := "username"
protocol := "protocol"
diff --git a/internal/git/hooks_payload_test.go b/internal/git/hooks_payload_test.go
index 0707dbb21..5f82e7486 100644
--- a/internal/git/hooks_payload_test.go
+++ b/internal/git/hooks_payload_test.go
@@ -8,13 +8,21 @@ 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/metadata/featureflag"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/v15/internal/transaction/txinfo"
)
func TestHooksPayload(t *testing.T) {
- cfg, repo, _ := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
tx := txinfo.Transaction{
ID: 1234,
diff --git a/internal/git/quarantine/quarantine_test.go b/internal/git/quarantine/quarantine_test.go
index bee26511e..1a3867fc1 100644
--- a/internal/git/quarantine/quarantine_test.go
+++ b/internal/git/quarantine/quarantine_test.go
@@ -40,12 +40,16 @@ func (e entry) create(t *testing.T, root string) {
}
func TestQuarantine_lifecycle(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
locator := config.NewLocator(cfg)
t.Run("quarantine directory gets created", func(t *testing.T) {
- ctx := testhelper.Context(t)
-
quarantine, err := New(ctx, repo, locator)
require.NoError(t, err)
@@ -69,7 +73,7 @@ func TestQuarantine_lifecycle(t *testing.T) {
})
t.Run("context cancellation cleans up quarantine directory", func(t *testing.T) {
- ctx, cancel := context.WithCancel(testhelper.Context(t))
+ ctx, cancel := context.WithCancel(ctx)
quarantine, err := New(ctx, repo, locator)
require.NoError(t, err)
@@ -132,11 +136,15 @@ func TestQuarantine_Migrate(t *testing.T) {
func TestQuarantine_localrepo(t *testing.T) {
ctx := testhelper.Context(t)
- cfg, repoProto, _ := testcfg.BuildWithRepo(t)
- locator := config.NewLocator(cfg)
-
+ cfg := testcfg.Build(t)
+ repoProto, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
repo := localrepo.NewTestRepo(t, cfg, repoProto)
+ locator := config.NewLocator(cfg)
+
quarantine, err := New(ctx, repoProto, locator)
require.NoError(t, err)
diff --git a/internal/gitaly/hook/custom_test.go b/internal/gitaly/hook/custom_test.go
index 494088fd6..d9273e04d 100644
--- a/internal/gitaly/hook/custom_test.go
+++ b/internal/gitaly/hook/custom_test.go
@@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
@@ -52,7 +53,13 @@ echo "$0"
exit 0`)
func TestCustomHooksSuccess(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
testCases := []struct {
hookName string
@@ -103,10 +110,15 @@ func TestCustomHooksSuccess(t *testing.T) {
}
func TestCustomHookPartialFailure(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
globalCustomHooksDir := testhelper.TempDir(t)
- ctx := testhelper.Context(t)
testCases := []struct {
hook string
@@ -181,12 +193,17 @@ func TestCustomHookPartialFailure(t *testing.T) {
}
func TestCustomHooksMultipleHooks(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
globalCustomHooksDir := testhelper.TempDir(t)
cfg.Hooks.CustomHooksDir = globalCustomHooksDir
- ctx := testhelper.Context(t)
var expectedExecutedScripts []string
@@ -227,12 +244,17 @@ func TestCustomHooksMultipleHooks(t *testing.T) {
}
func TestCustomHooksWithSymlinks(t *testing.T) {
- cfg, repo, _ := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
globalCustomHooksDir := testhelper.TempDir(t)
cfg.Hooks.CustomHooksDir = globalCustomHooksDir
- ctx := testhelper.Context(t)
globalHooksPath := filepath.Join(globalCustomHooksDir, "update.d")
@@ -295,12 +317,17 @@ func TestCustomHooksWithSymlinks(t *testing.T) {
}
func TestMultilineStdin(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
globalCustomHooksDir := testhelper.TempDir(t)
cfg.Hooks.CustomHooksDir = globalCustomHooksDir
- ctx := testhelper.Context(t)
projectHooksPath := filepath.Join(repoPath, "custom_hooks", "pre-receive.d")
@@ -325,12 +352,17 @@ old3 new3 ref3
}
func TestMultipleScriptsStdin(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
globalCustomHooksDir := testhelper.TempDir(t)
cfg.Hooks.CustomHooksDir = globalCustomHooksDir
- ctx := testhelper.Context(t)
projectUpdateHooks := 9
projectHooksPath := filepath.Join(repoPath, "custom_hooks", "pre-receive.d")
diff --git a/internal/gitaly/hook/postreceive_test.go b/internal/gitaly/hook/postreceive_test.go
index 9c6de0ff4..b2f311fcc 100644
--- a/internal/gitaly/hook/postreceive_test.go
+++ b/internal/gitaly/hook/postreceive_test.go
@@ -69,7 +69,14 @@ func TestPrintAlert(t *testing.T) {
}
func TestPostReceive_customHook(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
gitCmdFactory := gittest.NewCommandFactory(t, cfg)
locator := config.NewLocator(cfg)
@@ -83,8 +90,6 @@ func TestPostReceive_customHook(t *testing.T) {
Protocol: "web",
}
- ctx := testhelper.Context(t)
-
payload, err := git.NewHooksPayload(cfg, repo, nil, receiveHooksPayload, git.PostReceiveHook, featureflag.FromContext(ctx)).Env()
require.NoError(t, err)
@@ -240,7 +245,13 @@ func (m *postreceiveAPIMock) PostReceive(ctx context.Context, glRepository, glID
}
func TestPostReceive_gitlab(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
payload, err := git.NewHooksPayload(cfg, repo, nil, &git.UserDetails{
UserID: "1234",
@@ -329,8 +340,6 @@ func TestPostReceive_gitlab(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
gitlabAPI := postreceiveAPIMock{
postreceive: func(ctx context.Context, glRepo, glID, changes string, pushOptions ...string) (bool, []gitlab.PostReceiveMessage, error) {
return tc.postreceive(t, ctx, glRepo, glID, changes, pushOptions...)
@@ -358,8 +367,12 @@ func TestPostReceive_gitlab(t *testing.T) {
func TestPostReceive_quarantine(t *testing.T) {
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
- cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
quarantine, err := quarantine.New(ctx, repoProto, config.NewLocator(cfg))
require.NoError(t, err)
diff --git a/internal/gitaly/hook/prereceive_test.go b/internal/gitaly/hook/prereceive_test.go
index 20f1f7bd9..89a5dc656 100644
--- a/internal/gitaly/hook/prereceive_test.go
+++ b/internal/gitaly/hook/prereceive_test.go
@@ -28,7 +28,14 @@ import (
)
func TestPrereceive_customHooks(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
gitCmdFactory := gittest.NewCommandFactory(t, cfg)
locator := config.NewLocator(cfg)
@@ -42,8 +49,6 @@ func TestPrereceive_customHooks(t *testing.T) {
Protocol: "web",
}
- ctx := testhelper.Context(t)
-
payload, err := git.NewHooksPayload(cfg, repo, nil, receiveHooksPayload, git.PreReceiveHook, featureflag.FromContext(ctx)).Env()
require.NoError(t, err)
@@ -177,8 +182,12 @@ func TestPrereceive_customHooks(t *testing.T) {
func TestPrereceive_quarantine(t *testing.T) {
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
- cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
quarantine, err := quarantine.New(ctx, repoProto, config.NewLocator(cfg))
require.NoError(t, err)
@@ -252,7 +261,13 @@ func (m *prereceiveAPIMock) PostReceive(context.Context, string, string, string,
}
func TestPrereceive_gitlab(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
payload, err := git.NewHooksPayload(cfg, repo, nil, &git.UserDetails{
UserID: "1234",
@@ -352,8 +367,6 @@ func TestPrereceive_gitlab(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
gitlabAPI := prereceiveAPIMock{
allowed: func(ctx context.Context, params gitlab.AllowedParams) (bool, string, error) {
return tc.allowed(t, ctx, params)
diff --git a/internal/gitaly/hook/transactions_test.go b/internal/gitaly/hook/transactions_test.go
index 1000b8420..2e3fc87d4 100644
--- a/internal/gitaly/hook/transactions_test.go
+++ b/internal/gitaly/hook/transactions_test.go
@@ -24,7 +24,13 @@ import (
)
func TestHookManager_stopCalled(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
expectedTx := txinfo.Transaction{
ID: 1234, Node: "primary", Primary: true,
@@ -35,8 +41,6 @@ func TestHookManager_stopCalled(t *testing.T) {
t, gitlab.MockAllowed, gitlab.MockPreReceive, gitlab.MockPostReceive,
))
- ctx := testhelper.Context(t)
-
hooksPayload, err := git.NewHooksPayload(
cfg,
repo,
@@ -122,7 +126,13 @@ func TestHookManager_stopCalled(t *testing.T) {
}
func TestHookManager_contextCancellationCancelsVote(t *testing.T) {
- cfg, repo, _ := testcfg.BuildWithRepo(t)
+ ctx, cancel := context.WithCancel(testhelper.Context(t))
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
mockTxMgr := transaction.MockManager{
VoteFn: func(ctx context.Context, _ txinfo.Transaction, _ voting.Vote, _ voting.Phase) error {
@@ -146,7 +156,6 @@ func TestHookManager_contextCancellationCancelsVote(t *testing.T) {
nil,
).Env()
require.NoError(t, err)
- ctx, cancel := context.WithCancel(testhelper.Context(t))
changes := fmt.Sprintf("%s %s refs/heads/master", strings.Repeat("1", 40), git.ObjectHashSHA1.ZeroOID)
diff --git a/internal/gitaly/hook/update_test.go b/internal/gitaly/hook/update_test.go
index e9874a908..b0f90bc92 100644
--- a/internal/gitaly/hook/update_test.go
+++ b/internal/gitaly/hook/update_test.go
@@ -25,7 +25,14 @@ import (
)
func TestUpdate_customHooks(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
gitCmdFactory := gittest.NewCommandFactory(t, cfg)
locator := config.NewLocator(cfg)
@@ -39,8 +46,6 @@ func TestUpdate_customHooks(t *testing.T) {
Protocol: "web",
}
- ctx := testhelper.Context(t)
-
payload, err := git.NewHooksPayload(cfg, repo, nil, receiveHooksPayload, git.UpdateHook, featureflag.FromContext(ctx)).Env()
require.NoError(t, err)
@@ -208,8 +213,12 @@ func TestUpdate_customHooks(t *testing.T) {
func TestUpdate_quarantine(t *testing.T) {
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
- cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
quarantine, err := quarantine.New(ctx, repoProto, config.NewLocator(cfg))
require.NoError(t, err)
diff --git a/internal/gitaly/rubyserver/proxy_test.go b/internal/gitaly/rubyserver/proxy_test.go
index 0c11f56c6..b9e2a1480 100644
--- a/internal/gitaly/rubyserver/proxy_test.go
+++ b/internal/gitaly/rubyserver/proxy_test.go
@@ -6,6 +6,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
@@ -13,8 +14,13 @@ import (
)
func TestSetHeadersBlocksUnknownMetadata(t *testing.T) {
- cfg, repo, _ := testcfg.BuildWithRepo(t)
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
otherKey := "unknown-key"
otherValue := "test-value"
@@ -31,8 +37,13 @@ func TestSetHeadersBlocksUnknownMetadata(t *testing.T) {
}
func TestSetHeadersPreservesAllowlistedMetadata(t *testing.T) {
- cfg, repo, _ := testcfg.BuildWithRepo(t)
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
key := "gitaly-servers"
value := "test-value"
@@ -48,8 +59,13 @@ func TestSetHeadersPreservesAllowlistedMetadata(t *testing.T) {
}
func TestRubyFeatureHeaders(t *testing.T) {
- cfg, repo, _ := testcfg.BuildWithRepo(t)
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
key := "gitaly-feature-ruby-test-feature"
value := "true"
diff --git a/internal/gitaly/rubyserver/rubyserver_test.go b/internal/gitaly/rubyserver/rubyserver_test.go
index 7fe36d17b..0400f088a 100644
--- a/internal/gitaly/rubyserver/rubyserver_test.go
+++ b/internal/gitaly/rubyserver/rubyserver_test.go
@@ -38,8 +38,13 @@ func TestStopSafe(t *testing.T) {
}
func TestSetHeaders(t *testing.T) {
- cfg, repo, _ := testcfg.BuildWithRepo(t)
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
locator := config.NewLocator(cfg)
diff --git a/internal/gitaly/server/auth_test.go b/internal/gitaly/server/auth_test.go
index b0322c6f6..2c008077e 100644
--- a/internal/gitaly/server/auth_test.go
+++ b/internal/gitaly/server/auth_test.go
@@ -306,7 +306,8 @@ func TestStreamingNoAuth(t *testing.T) {
}
func TestAuthBeforeLimit(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t, testcfg.WithBase(config.Cfg{
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t, testcfg.WithBase(config.Cfg{
Auth: auth.Config{Token: "abc123"},
Concurrency: []config.Concurrency{{
RPC: "/gitaly.OperationService/UserCreateTag",
@@ -315,6 +316,11 @@ func TestAuthBeforeLimit(t *testing.T) {
},
))
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
gitlabURL, cleanup := gitlab.SetupAndStartGitlabServer(t, cfg.GitlabShell.Dir, &gitlab.TestServerOptions{
SecretToken: "secretToken",
GLID: gittest.GlID,
@@ -328,7 +334,6 @@ func TestAuthBeforeLimit(t *testing.T) {
serverSocketPath := runServer(t, cfg)
client, conn := newOperationClient(t, cfg.Auth.Token, serverSocketPath)
t.Cleanup(func() { conn.Close() })
- ctx := testhelper.Context(t)
defer func(d time.Duration) {
gitalyauth.SetTokenValidityDuration(d)
diff --git a/internal/gitaly/service/hook/post_receive_test.go b/internal/gitaly/service/hook/post_receive_test.go
index 58bcdc839..2bea73a50 100644
--- a/internal/gitaly/service/hook/post_receive_test.go
+++ b/internal/gitaly/service/hook/post_receive_test.go
@@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"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/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config/prometheus"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitlab"
@@ -63,7 +64,13 @@ func TestHooksMissingStdin(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
c := gitlab.TestServerOptions{
User: user,
@@ -96,7 +103,6 @@ func TestHooksMissingStdin(t *testing.T) {
client, conn := newHooksClient(t, serverSocketPath)
defer conn.Close()
- ctx := testhelper.Context(t)
hooksPayload, err := git.NewHooksPayload(
cfg,
@@ -187,7 +193,13 @@ To create a merge request for okay, visit:
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
tempDir := testhelper.TempDir(t)
gitlab.WriteShellSecretFile(t, tempDir, secretToken)
@@ -225,7 +237,6 @@ To create a merge request for okay, visit:
client, conn := newHooksClient(t, serverSocketPath)
defer conn.Close()
- ctx := testhelper.Context(t)
stream, err := client.PostReceiveHook(ctx)
require.NoError(t, err)
diff --git a/internal/gitaly/service/hook/pre_receive_test.go b/internal/gitaly/service/hook/pre_receive_test.go
index b1f64d6a7..c7e68af03 100644
--- a/internal/gitaly/service/hook/pre_receive_test.go
+++ b/internal/gitaly/service/hook/pre_receive_test.go
@@ -88,7 +88,13 @@ func TestPreReceiveHook_GitlabAPIAccess(t *testing.T) {
changes := "changes123"
protocol := "http"
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
gitObjectDirRel := "git/object/dir"
gitAlternateObjectRelDirs := []string{"alt/obj/dir/1", "alt/obj/dir/2"}
@@ -140,7 +146,6 @@ func TestPreReceiveHook_GitlabAPIAccess(t *testing.T) {
client, conn := newHooksClient(t, serverSocketPath)
defer conn.Close()
- ctx := testhelper.Context(t)
hooksPayload, err := git.NewHooksPayload(
cfg,
diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go
index 4c93de134..c94fa8281 100644
--- a/internal/gitaly/service/operations/branches_test.go
+++ b/internal/gitaly/service/operations/branches_test.go
@@ -125,7 +125,12 @@ func TestUserCreateBranch_Transactions(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
transactionServer := &testTransactionServer{}
@@ -787,7 +792,12 @@ func TestUserDeleteBranch_transaction(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
// This creates a new branch "delete-me" which exists both in the packed-refs file and as a
// loose reference. Git will create two reference transactions for this: one transaction to
diff --git a/internal/gitaly/service/repository/fetch_bundle_test.go b/internal/gitaly/service/repository/fetch_bundle_test.go
index d5df87904..27bb373ea 100644
--- a/internal/gitaly/service/repository/fetch_bundle_test.go
+++ b/internal/gitaly/service/repository/fetch_bundle_test.go
@@ -72,9 +72,14 @@ func TestServer_FetchBundle_transaction(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
testcfg.BuildGitalyHooks(t, cfg)
+ repoProto, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
hookManager := &mockHookManager{}
client, _ := runRepositoryService(t, cfg, nil, testserver.WithHookManager(hookManager), testserver.WithDisablePraefect())
diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go
index 68f03cb76..093a699b5 100644
--- a/internal/gitaly/service/repository/fetch_remote_test.go
+++ b/internal/gitaly/service/repository/fetch_remote_test.go
@@ -113,10 +113,15 @@ func TestFetchRemote_sshCommand(t *testing.T) {
t.Parallel()
- cfg, repo, _ := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
+ ctx := testhelper.Context(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
outputPath := filepath.Join(testhelper.TempDir(t), "output")
- ctx := testhelper.Context(t)
// We ain't got a nice way to intercept the SSH call, so we just write a custom git command
// which simply prints the GIT_SSH_COMMAND environment variable.
@@ -232,7 +237,12 @@ func TestFetchRemote_transaction(t *testing.T) {
// Reset the manager as creating the repository casts some votes.
txManager.Reset()
- targetCfg, targetRepoProto, targetRepoPath := testcfg.BuildWithRepo(t)
+ targetCfg := testcfg.Build(t)
+ targetRepoProto, targetRepoPath := gittest.CreateRepository(t, ctx, targetCfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ RelativePath: t.Name(),
+ })
targetGitCmdFactory := gittest.NewCommandFactory(t, targetCfg)
port := gittest.HTTPServer(t, ctx, targetGitCmdFactory, targetRepoPath, nil)
diff --git a/internal/gitaly/service/repository/replicate_test.go b/internal/gitaly/service/repository/replicate_test.go
index 209aef7be..7d2bdf319 100644
--- a/internal/gitaly/service/repository/replicate_test.go
+++ b/internal/gitaly/service/repository/replicate_test.go
@@ -546,13 +546,22 @@ func TestFetchInternalRemote_successful(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- remoteCfg, remoteRepo, remoteRepoPath := testcfg.BuildWithRepo(t)
+
+ remoteCfg := testcfg.Build(t)
+ remoteRepo, remoteRepoPath := gittest.CreateRepository(t, ctx, remoteCfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
testcfg.BuildGitalyHooks(t, remoteCfg)
gittest.WriteCommit(t, remoteCfg, remoteRepoPath, gittest.WithBranch("master"))
_, remoteAddr := runRepositoryService(t, remoteCfg, nil, testserver.WithDisablePraefect())
- localCfg, localRepoProto, localRepoPath := testcfg.BuildWithRepo(t)
+ localCfg := testcfg.Build(t)
+ localRepoProto, localRepoPath := gittest.CreateRepository(t, ctx, localCfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
localRepo := localrepo.NewTestRepo(t, localCfg, localRepoProto)
testcfg.BuildGitalySSH(t, localCfg)
testcfg.BuildGitalyHooks(t, localCfg)
@@ -615,8 +624,14 @@ func TestFetchInternalRemote_failure(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
- cfg, repoProto, _ := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
+
+ repoProto, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
repo := localrepo.NewTestRepo(t, cfg, repoProto)
+
ctx = testhelper.MergeIncomingMetadata(ctx, testcfg.GitalyServersMetadataFromCfg(t, cfg))
connsPool := client.NewPool()
diff --git a/internal/gitaly/service/repository/search_files_test.go b/internal/gitaly/service/repository/search_files_test.go
index e0b511d37..bb2957b52 100644
--- a/internal/gitaly/service/repository/search_files_test.go
+++ b/internal/gitaly/service/repository/search_files_test.go
@@ -203,7 +203,15 @@ func TestSearchFilesByContentLargeFile(t *testing.T) {
func TestSearchFilesByContentFailure(t *testing.T) {
t.Parallel()
- cfg, repo, _ := testcfg.BuildWithRepo(t)
+
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
gitCommandFactory := gittest.NewCommandFactory(t, cfg)
catfileCache := catfile.NewCache(cfg)
t.Cleanup(catfileCache.Stop)
diff --git a/internal/gitlab/http_client_test.go b/internal/gitlab/http_client_test.go
index 1179fbb3d..809b983b3 100644
--- a/internal/gitlab/http_client_test.go
+++ b/internal/gitlab/http_client_test.go
@@ -11,6 +11,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config/prometheus"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
@@ -32,11 +33,18 @@ type postReceiveRequest struct {
//
//go:generate openssl req -newkey rsa:4096 -new -nodes -x509 -days 3650 -out testdata/certs/server.crt -keyout testdata/certs/server.key -subj "/C=US/ST=California/L=San Francisco/O=GitLab/OU=GitLab-Shell/CN=localhost" -addext "subjectAltName = IP:127.0.0.1"
func TestAccess_verifyParams(t *testing.T) {
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
user, password := "user", "password"
secretToken := "topsecret"
glID, glRepository := "key-123", "repo-1"
- _, repo, repoPath := testcfg.BuildWithRepo(t)
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
changes := "changes1\nchanges2\nchanges3"
protocol := "protocol"
@@ -121,7 +129,6 @@ func TestAccess_verifyParams(t *testing.T) {
allowed: false,
},
}
- ctx := testhelper.Context(t)
for _, tc := range testCases {
allowed, _, err := c.Allowed(ctx, AllowedParams{
@@ -139,11 +146,18 @@ func TestAccess_verifyParams(t *testing.T) {
}
func TestAccess_escapedAndRelativeURLs(t *testing.T) {
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
user, password := "user", "password"
secretToken := "topsecret"
glID, glRepository := "key-123", "repo-1"
- _, repo, repoPath := testcfg.BuildWithRepo(t)
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
changes := "changes1\nchanges2\nchanges3"
protocol := "protocol"
@@ -230,7 +244,6 @@ func TestAccess_escapedAndRelativeURLs(t *testing.T) {
prometheus.Config{},
)
require.NoError(t, err)
- ctx := testhelper.Context(t)
allowed, _, err := c.Allowed(ctx, AllowedParams{
RepoPath: repo.RelativePath,
@@ -248,7 +261,13 @@ func TestAccess_escapedAndRelativeURLs(t *testing.T) {
}
func TestAccess_allowedResponseHandling(t *testing.T) {
- _, repo, repoPath := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
// set git quarantine directories
gitObjectDir := filepath.Join(repoPath, "quarantine", "object", "dir")
@@ -383,7 +402,6 @@ func TestAccess_allowedResponseHandling(t *testing.T) {
mockHistogramVec := promtest.NewMockHistogramVec()
c.latencyMetric = mockHistogramVec
- ctx := testhelper.Context(t)
allowed, message, err := c.Allowed(ctx, AllowedParams{
RepoPath: repo.RelativePath,
diff --git a/internal/middleware/commandstatshandler/commandstatshandler_test.go b/internal/middleware/commandstatshandler/commandstatshandler_test.go
index e3583531a..e1ce12996 100644
--- a/internal/middleware/commandstatshandler/commandstatshandler_test.go
+++ b/internal/middleware/commandstatshandler/commandstatshandler_test.go
@@ -74,7 +74,13 @@ func getBufDialer(listener *bufconn.Listener) func(context.Context, string) (net
}
func TestInterceptor(t *testing.T) {
- cfg, repo, _ := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
logger, hook := test.NewNullLogger()
@@ -88,8 +94,6 @@ func TestInterceptor(t *testing.T) {
require.NoError(t, err)
}()
- ctx := testhelper.Context(t)
-
tests := []struct {
name string
performRPC func(ctx context.Context, client gitalypb.RefServiceClient)
diff --git a/internal/praefect/coordinator_test.go b/internal/praefect/coordinator_test.go
index 8366f3414..de7ccf360 100644
--- a/internal/praefect/coordinator_test.go
+++ b/internal/praefect/coordinator_test.go
@@ -2064,7 +2064,13 @@ func TestCoordinator_grpcErrorHandling(t *testing.T) {
operationServer *mockOperationServer
}
- _, repoProto, _ := testcfg.BuildWithRepo(t)
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ repoProto, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
for _, tc := range []struct {
desc string
@@ -2098,8 +2104,6 @@ func TestCoordinator_grpcErrorHandling(t *testing.T) {
},
} {
t.Run(tc.desc, func(t *testing.T) {
- ctx := testhelper.Context(t)
-
var wg sync.WaitGroup
gitalies := make(map[string]gitalyNode)
for _, gitaly := range []string{"primary", "secondary-1", "secondary-2"} {
diff --git a/internal/praefect/middleware/errorhandler_test.go b/internal/praefect/middleware/errorhandler_test.go
index a57463063..4438001d4 100644
--- a/internal/praefect/middleware/errorhandler_test.go
+++ b/internal/praefect/middleware/errorhandler_test.go
@@ -10,6 +10,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/grpc-proxy/proxy"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/nodes/tracker"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/protoregistry"
@@ -96,7 +97,11 @@ func TestStreamInterceptor(t *testing.T) {
client := gitalypb.NewRepositoryServiceClient(praefectCC)
- _, repo, _ := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
for i := 0; i < threshold; i++ {
_, err = client.RepositoryExists(ctx, &gitalypb.RepositoryExistsRequest{
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go
index 4d1464254..86754130d 100644
--- a/internal/praefect/replicator_test.go
+++ b/internal/praefect/replicator_test.go
@@ -51,13 +51,18 @@ func TestReplMgr_ProcessBacklog(t *testing.T) {
ctx := testhelper.Context(t)
- primaryCfg, testRepoProto, testRepoPath := testcfg.BuildWithRepo(t, testcfg.WithStorages("primary"))
+ primaryCfg := testcfg.Build(t, testcfg.WithStorages("primary"))
+ testRepoProto, testRepoPath := gittest.CreateRepository(t, ctx, primaryCfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
testRepo := localrepo.NewTestRepo(t, primaryCfg, testRepoProto)
primaryCfg.SocketPath = testserver.RunGitalyServer(t, primaryCfg, nil, setup.RegisterAll, testserver.WithDisablePraefect())
testcfg.BuildGitalySSH(t, primaryCfg)
testcfg.BuildGitalyHooks(t, primaryCfg)
- backupCfg, _, _ := testcfg.BuildWithRepo(t, testcfg.WithStorages("backup"))
+ backupCfg := testcfg.Build(t, testcfg.WithStorages("backup"))
backupCfg.SocketPath = testserver.RunGitalyServer(t, backupCfg, nil, setup.RegisterAll, testserver.WithDisablePraefect())
testcfg.BuildGitalySSH(t, backupCfg)
testcfg.BuildGitalyHooks(t, backupCfg)
@@ -281,8 +286,13 @@ func TestReplicatorDowngradeAttempt(t *testing.T) {
func TestConfirmReplication(t *testing.T) {
ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
+
+ testRepoA, testRepoAPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
- cfg, testRepoA, testRepoAPath := testcfg.BuildWithRepo(t)
srvSocketPath := testserver.RunGitalyServer(t, cfg, nil, setup.RegisterAll, testserver.WithDisablePraefect())
testRepoB, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
@@ -347,10 +357,14 @@ func TestProcessBacklog_FailedJobs(t *testing.T) {
ctx := testhelper.Context(t)
- primaryCfg, testRepo, _ := testcfg.BuildWithRepo(t, testcfg.WithStorages("default"))
+ primaryCfg := testcfg.Build(t, testcfg.WithStorages("default"))
+ testRepo, _ := gittest.CreateRepository(t, ctx, primaryCfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
primaryAddr := testserver.RunGitalyServer(t, primaryCfg, nil, setup.RegisterAll, testserver.WithDisablePraefect())
- backupCfg, _, _ := testcfg.BuildWithRepo(t, testcfg.WithStorages("backup"))
+ backupCfg := testcfg.Build(t, testcfg.WithStorages("backup"))
backupAddr := testserver.RunGitalyServer(t, backupCfg, nil, setup.RegisterAll, testserver.WithDisablePraefect())
testcfg.BuildGitalySSH(t, backupCfg)
testcfg.BuildGitalyHooks(t, backupCfg)
@@ -453,12 +467,17 @@ func TestProcessBacklog_Success(t *testing.T) {
ctx := testhelper.Context(t)
ctx, cancel := context.WithCancel(ctx)
- primaryCfg, testRepo, _ := testcfg.BuildWithRepo(t, testcfg.WithStorages("primary"))
+ primaryCfg := testcfg.Build(t, testcfg.WithStorages("primary"))
primaryCfg.SocketPath = testserver.RunGitalyServer(t, primaryCfg, nil, setup.RegisterAll, testserver.WithDisablePraefect())
testcfg.BuildGitalySSH(t, primaryCfg)
testcfg.BuildGitalyHooks(t, primaryCfg)
- backupCfg, _, _ := testcfg.BuildWithRepo(t, testcfg.WithStorages("backup"))
+ testRepo, _ := gittest.CreateRepository(t, ctx, primaryCfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
+ backupCfg := testcfg.Build(t, testcfg.WithStorages("backup"))
backupCfg.SocketPath = testserver.RunGitalyServer(t, backupCfg, nil, setup.RegisterAll, testserver.WithDisablePraefect())
testcfg.BuildGitalySSH(t, backupCfg)
testcfg.BuildGitalyHooks(t, backupCfg)
diff --git a/internal/praefect/server_factory_test.go b/internal/praefect/server_factory_test.go
index 64c842ace..f0f15628f 100644
--- a/internal/praefect/server_factory_test.go
+++ b/internal/praefect/server_factory_test.go
@@ -44,9 +44,16 @@ import (
func TestServerFactory(t *testing.T) {
t.Parallel()
- cfg, repo, repoPath := testcfg.BuildWithRepo(t)
+
+ ctx := testhelper.Context(t)
+ cfg := testcfg.Build(t)
gitalyAddr := testserver.RunGitalyServer(t, cfg, nil, setup.RegisterAll, testserver.WithDisablePraefect())
+ repo, repoPath := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
+
certFile, keyFile := testhelper.GenerateCerts(t)
conf := config.Config{
@@ -218,7 +225,6 @@ func TestServerFactory(t *testing.T) {
require.NoError(t, err)
go func() { require.NoError(t, praefectServerFactory.Serve(listener, true)) }()
- ctx := testhelper.Context(t)
certPool, err := x509.SystemCertPool()
require.NoError(t, err)
@@ -250,8 +256,6 @@ func TestServerFactory(t *testing.T) {
})
t.Run("stops all listening servers", func(t *testing.T) {
- ctx := testhelper.Context(t)
-
praefectServerFactory := NewServerFactory(conf, logger, coordinator.StreamDirector, nodeMgr, txMgr, queue, rs, datastore.AssignmentStore{}, registry, nil, nil, nil)
defer praefectServerFactory.Stop()
diff --git a/internal/praefect/server_test.go b/internal/praefect/server_test.go
index 0fae7348c..2b2b3ee5e 100644
--- a/internal/praefect/server_test.go
+++ b/internal/praefect/server_test.go
@@ -493,7 +493,12 @@ func TestRemoveRepository(t *testing.T) {
praefectCfg := config.Config{VirtualStorages: []*config.VirtualStorage{{Name: "praefect"}}}
for i, name := range []string{"gitaly-1", "gitaly-2", "gitaly-3"} {
- gitalyCfgs[i], repos[i], _ = testcfg.BuildWithRepo(t, testcfg.WithStorages(name))
+ gitalyCfgs[i] = testcfg.Build(t, testcfg.WithStorages(name))
+ repos[i], _ = gittest.CreateRepository(t, ctx, gitalyCfgs[i], gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ RelativePath: t.Name(),
+ })
gitalyAddr := testserver.RunGitalyServer(t, gitalyCfgs[i], nil, setup.RegisterAll, testserver.WithDisablePraefect())
gitalyCfgs[i].SocketPath = gitalyAddr
@@ -815,7 +820,11 @@ func TestProxyWrites(t *testing.T) {
defer nodeMgr.Stop()
ctx := testhelper.Context(t)
- _, repo, _ := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
rs := datastore.MockRepositoryStore{
GetConsistentStoragesFunc: func(ctx context.Context, virtualStorage, relativePath string) (string, map[string]struct{}, error) {
@@ -1004,7 +1013,12 @@ func TestErrorThreshold(t *testing.T) {
defer testhelper.MustClose(t, conn)
cli := gitalypb.NewRepositoryServiceClient(conn)
- _, repo, _ := testcfg.BuildWithRepo(t)
+ cfg := testcfg.Build(t)
+
+ repo, _ := gittest.CreateRepository(t, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ Seed: gittest.SeedGitLabTest,
+ })
node := nodeMgr.Nodes()["default"][0]
require.Equal(t, "praefect-internal-0", node.GetStorage())
diff --git a/internal/testhelper/testcfg/gitaly.go b/internal/testhelper/testcfg/gitaly.go
index 8f90ec6be..faef5e2b6 100644
--- a/internal/testhelper/testcfg/gitaly.go
+++ b/internal/testhelper/testcfg/gitaly.go
@@ -7,10 +7,8 @@ import (
"testing"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
- "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
// UnconfiguredSocketPath is used to bypass config validation errors
@@ -147,28 +145,3 @@ func Build(tb testing.TB, opts ...Option) config.Cfg {
return cfgBuilder.Build(tb)
}
-
-// BuildWithRepo creates a minimal configuration setup with no options.
-// It also clones test repository at the storage and returns it with the full path to the repository.
-func BuildWithRepo(tb testing.TB, opts ...Option) (config.Cfg, *gitalypb.Repository, string) {
- tb.Helper()
-
- ctx := testhelper.Context(tb)
- cfg := Build(tb, opts...)
-
- // clone the test repo to the each storage
- repos := make([]*gitalypb.Repository, len(cfg.Storages))
- for i, gitalyStorage := range cfg.Storages {
- repo, _ := gittest.CreateRepository(tb, ctx, cfg, gittest.CreateRepositoryConfig{
- SkipCreationViaService: true,
- Storage: gitalyStorage,
- RelativePath: tb.Name(),
- Seed: gittest.SeedGitLabTest,
- })
-
- repos[i] = repo
- repos[i].StorageName = gitalyStorage.Name
- }
-
- return cfg, repos[0], filepath.Join(cfg.Storages[0].Path, repos[0].RelativePath)
-}