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:
authorPavlo Strokov <pstrokov@gitlab.com>2021-02-17 17:56:35 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2021-02-20 10:13:08 +0300
commit0d7cc52bf85a948fb5205398c3048500d6796618 (patch)
tree702a8a109af246f5a753822ac322e292fe528369
parenta33a5c088e0b87b85e6d198ff7e4401ac44a4521 (diff)
Remove dependency of the EnableGitProtocolV2Support on config.Config
EnableGitProtocolV2Support modifies global variable config.Config internally which is not great. It is changed to accept a config.Cfg entity and return a modified copy of it. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/2699
-rw-r--r--internal/gitaly/service/smarthttp/inforefs_test.go5
-rw-r--r--internal/gitaly/service/smarthttp/receive_pack_test.go5
-rw-r--r--internal/gitaly/service/smarthttp/upload_pack_test.go5
-rw-r--r--internal/gitaly/service/ssh/receive_pack_test.go8
-rw-r--r--internal/gitaly/service/ssh/upload_pack_test.go4
-rw-r--r--internal/testhelper/git_protocol.go8
6 files changed, 24 insertions, 11 deletions
diff --git a/internal/gitaly/service/smarthttp/inforefs_test.go b/internal/gitaly/service/smarthttp/inforefs_test.go
index ffdcc6250..0b3e026a6 100644
--- a/internal/gitaly/service/smarthttp/inforefs_test.go
+++ b/internal/gitaly/service/smarthttp/inforefs_test.go
@@ -95,8 +95,11 @@ func TestSuccessfulInfoRefsUploadPackWithGitConfigOptions(t *testing.T) {
}
func TestSuccessfulInfoRefsUploadPackWithGitProtocol(t *testing.T) {
- restore := testhelper.EnableGitProtocolV2Support(t)
+ defer func(old config.Cfg) { config.Config = old }(config.Config)
+
+ cfg, restore := testhelper.EnableGitProtocolV2Support(t, config.Config)
defer restore()
+ config.Config = cfg
serverSocketPath, stop := runSmartHTTPServer(t)
defer stop()
diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go
index 0dae7d785..2355e9748 100644
--- a/internal/gitaly/service/smarthttp/receive_pack_test.go
+++ b/internal/gitaly/service/smarthttp/receive_pack_test.go
@@ -108,8 +108,11 @@ func TestSuccessfulReceivePackRequest(t *testing.T) {
}
func TestSuccessfulReceivePackRequestWithGitProtocol(t *testing.T) {
- restore := testhelper.EnableGitProtocolV2Support(t)
+ defer func(old config.Cfg) { config.Config = old }(config.Config)
+
+ cfg, restore := testhelper.EnableGitProtocolV2Support(t, config.Config)
defer restore()
+ config.Config = cfg
serverSocketPath, stop := runSmartHTTPServer(t)
defer stop()
diff --git a/internal/gitaly/service/smarthttp/upload_pack_test.go b/internal/gitaly/service/smarthttp/upload_pack_test.go
index 161a3c0bd..0e015f2b8 100644
--- a/internal/gitaly/service/smarthttp/upload_pack_test.go
+++ b/internal/gitaly/service/smarthttp/upload_pack_test.go
@@ -178,8 +178,11 @@ func TestUploadPackRequestWithGitProtocol(t *testing.T) {
}
func testUploadPackRequestWithGitProtocol(t *testing.T, ctx context.Context) {
- restore := testhelper.EnableGitProtocolV2Support(t)
+ defer func(old config.Cfg) { config.Config = old }(config.Config)
+
+ cfg, restore := testhelper.EnableGitProtocolV2Support(t, config.Config)
defer restore()
+ config.Config = cfg
serverSocketPath, stop := runSmartHTTPServer(t)
defer stop()
diff --git a/internal/gitaly/service/ssh/receive_pack_test.go b/internal/gitaly/service/ssh/receive_pack_test.go
index de18fc0de..f58368d3f 100644
--- a/internal/gitaly/service/ssh/receive_pack_test.go
+++ b/internal/gitaly/service/ssh/receive_pack_test.go
@@ -140,8 +140,10 @@ func TestReceivePackPushSuccess(t *testing.T) {
}
func TestReceivePackPushSuccessWithGitProtocol(t *testing.T) {
- restore := testhelper.EnableGitProtocolV2Support(t)
+ defer func(old config.Cfg) { config.Config = old }(config.Config)
+ cfg, restore := testhelper.EnableGitProtocolV2Support(t, config.Config)
defer restore()
+ config.Config = cfg
serverSocketPath, stop := runSSHServer(t)
defer stop()
@@ -241,8 +243,10 @@ func TestSSHReceivePackToHooks(t *testing.T) {
glRepository := "some_repo"
glID := "key-123"
- restore := testhelper.EnableGitProtocolV2Support(t)
+ defer func(old config.Cfg) { config.Config = old }(config.Config)
+ cfg, restore := testhelper.EnableGitProtocolV2Support(t, config.Config)
defer restore()
+ config.Config = cfg
serverSocketPath, stop := runSSHServer(t)
defer stop()
diff --git a/internal/gitaly/service/ssh/upload_pack_test.go b/internal/gitaly/service/ssh/upload_pack_test.go
index 16944d384..8518accc5 100644
--- a/internal/gitaly/service/ssh/upload_pack_test.go
+++ b/internal/gitaly/service/ssh/upload_pack_test.go
@@ -431,8 +431,10 @@ func TestUploadPackCloneSuccessWithGitProtocol(t *testing.T) {
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
- restore := testhelper.EnableGitProtocolV2Support(t)
+ defer func(old config.Cfg) { config.Config = old }(config.Config)
+ cfg, restore := testhelper.EnableGitProtocolV2Support(t, config.Config)
defer restore()
+ config.Config = cfg
serverSocketPath, stop := runSSHServer(t)
defer stop()
diff --git a/internal/testhelper/git_protocol.go b/internal/testhelper/git_protocol.go
index d0043303d..fb6fe5805 100644
--- a/internal/testhelper/git_protocol.go
+++ b/internal/testhelper/git_protocol.go
@@ -14,7 +14,7 @@ import (
// wrapper that allows the protocol to be tested. It returns a function that
// restores the given settings as well as an array of environment variables
// which need to be set when invoking Git with this setup.
-func EnableGitProtocolV2Support(t testing.TB) func() {
+func EnableGitProtocolV2Support(t testing.TB, cfg config.Cfg) (config.Cfg, Cleanup) {
envPath := filepath.Join(testDirectory, "git-env")
script := fmt.Sprintf(`#!/bin/sh
@@ -28,11 +28,9 @@ exec "%s" "$@"
cleanupExe := WriteExecutable(t, path, []byte(script))
- oldGitBinPath := config.Config.Git.BinPath
- config.Config.Git.BinPath = path
- return func() {
+ cfg.Git.BinPath = path
+ return cfg, func() {
assert.NoError(t, os.Remove(envPath))
- config.Config.Git.BinPath = oldGitBinPath
cleanupExe()
cleanupDir()
}