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>2020-08-18 11:23:50 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-08-20 14:20:19 +0300
commit658cd92c2f23e27ebcc066108f645e609ee1dfd4 (patch)
tree0a11b4e3049354f12eb1fca19a711052d7216010
parent1184a055dea81ff9f2f72216823a87b8a003ae94 (diff)
config: Allow overriding Git binary via environment
In order to allow easy testing of Gitaly against custom Git binaries and different versions thereof, this commit introduces a new environment variable `GITALY_TESTING_GIT_BINARY`. If this variable is set, then we'll use its value as the Git binary for testing.
-rw-r--r--internal/config/config.go5
-rw-r--r--internal/config/config_test.go25
2 files changed, 21 insertions, 9 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index c7aef2f08..c43d4b6a8 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -323,6 +323,11 @@ func SetGitPath() error {
return nil
}
+ if path, ok := os.LookupEnv("GITALY_TESTING_GIT_BINARY"); ok {
+ Config.Git.BinPath = path
+ return nil
+ }
+
resolvedPath, err := exec.LookPath("git")
if err != nil {
return err
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index b747e20a4..383ffb61d 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -438,6 +438,10 @@ func TestValidateHooks(t *testing.T) {
}
func TestLoadGit(t *testing.T) {
+ defer func(oldGitSettings Git) {
+ Config.Git = oldGitSettings
+ }(Config.Git)
+
tmpFile := configFileReader(`[git]
bin_path = "/my/git/path"
catfile_cache_size = 50
@@ -455,10 +459,13 @@ func TestSetGitPath(t *testing.T) {
Config.Git = oldGitSettings
}(Config.Git)
- resolvedGitPath, err := exec.LookPath("git")
-
- if err != nil {
- t.Fatal(err)
+ var resolvedGitPath string
+ if path, ok := os.LookupEnv("GITALY_TESTING_GIT_BINARY"); ok {
+ resolvedGitPath = path
+ } else {
+ path, err := exec.LookPath("git")
+ require.NoError(t, err)
+ resolvedGitPath = path
}
testCases := []struct {
@@ -479,11 +486,11 @@ func TestSetGitPath(t *testing.T) {
}
for _, tc := range testCases {
- Config.Git.BinPath = tc.gitBinPath
-
- SetGitPath()
-
- assert.Equal(t, tc.expected, Config.Git.BinPath, tc.desc)
+ t.Run(tc.desc, func(t *testing.T) {
+ Config.Git.BinPath = tc.gitBinPath
+ SetGitPath()
+ assert.Equal(t, tc.expected, Config.Git.BinPath, tc.desc)
+ })
}
}