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-19 13:29:56 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-08-20 11:36:24 +0300
commitfc5219d4ffc79a64164f83c7fd488483ad0bb45e (patch)
tree0276d15e7c477ed39851b79c51c1f5e651abd336 /internal/testhelper
parentabb1fcd6457b02dd4bffd697ebf92c76fac9bbdf (diff)
tests: Fix Git environment wrapper using wrong executable
In order to test our support for Git protocol v2, we have set up a wrapper script around Git which captures its environment and writes it to a file. This allows us to check whether required options are set up correctly for protocol v2 to be enabled. The wrapper script we currently use doesn't invoke the correct Git executable, though, as it will simply use the one present in `$PATH`. Fix the issue by writing a temporary script containing the correct path configured via `config.Config.Git.Binary`. All the other alternatives like injecting another environment variable would've been non-trivial to implement, as we'd need to manually inject them at the right spots. Note that there's one peculiarity here: as we're about to migrate to use `command.GitPath()` everywhere, it will cause us to invoke the wrapper multiple times. To fix this, this commit starts appending to the environment file instead of overwriting it on each execution, deleting the file after the test is done.
Diffstat (limited to 'internal/testhelper')
-rwxr-xr-xinternal/testhelper/env_git4
-rw-r--r--internal/testhelper/git_protocol.go39
2 files changed, 30 insertions, 13 deletions
diff --git a/internal/testhelper/env_git b/internal/testhelper/env_git
deleted file mode 100755
index 7739eaeef..000000000
--- a/internal/testhelper/env_git
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-mkdir -p testdata
-env | grep ^GIT_PROTOCOL= > testdata/git-env
-exec git "$@"
diff --git a/internal/testhelper/git_protocol.go b/internal/testhelper/git_protocol.go
index ab0377551..a57b85906 100644
--- a/internal/testhelper/git_protocol.go
+++ b/internal/testhelper/git_protocol.go
@@ -1,20 +1,41 @@
package testhelper
import (
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/config"
)
-// EnableGitProtocolV2Support replaces the git binary in config with an
-// `env_git` wrapper that allows the protocol to be tested. It returns a
-// function that restores the given settings.
-//
-// Because we don't know how to get to that wrapper script from the current
-// working directory, callers must create a symbolic link to the `env_git` file
-// in their own `testdata` directories.
-func EnableGitProtocolV2Support() func() {
+// EnableGitProtocolV2Support replaces the git binary in config with a
+// 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.T) func() {
+ script := fmt.Sprintf(`#!/bin/sh
+mkdir -p testdata
+env | grep ^GIT_PROTOCOL= >>testdata/git-env
+exec "%s" "$@"
+`, command.GitPath())
+
+ dir, err := ioutil.TempDir("", "gitaly-test-*")
+ require.NoError(t, err)
+
+ path := path.Join(dir, "git")
+
+ cleanup, err := WriteExecutable(path, []byte(script))
+ require.NoError(t, err)
+
oldGitBinPath := config.Config.Git.BinPath
- config.Config.Git.BinPath = "testdata/env_git"
+ config.Config.Git.BinPath = path
return func() {
+ os.Remove("testdata/git-env")
config.Config.Git.BinPath = oldGitBinPath
+ cleanup()
}
}