diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-08-19 14:04:28 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-08-20 14:20:19 +0300 |
commit | 6f2467328e066fbaaeb65ec33b06c967b354f8f8 (patch) | |
tree | 9fc38280fc3a5f5e27207f36bcf14ffe9153927a /internal/testhelper | |
parent | 658cd92c2f23e27ebcc066108f645e609ee1dfd4 (diff) |
tests: Verify we never call Git resolved via PATH
When configuring Gitaly setups, admins can choose which Git executable
they want Gitaly to use for all Git invocations by specifing the
`config.git_path` key. Because of this, Gitaly is never allowed to
lookup Git via the PATH environment, but always needs to consult the
configured value. While most of our code (except for tests which have
been fixed with preceding commits) always honored this, there were two
locations which didn't, which wen't silently under the radar waiting for
trouble.
This commit introduces an improved test setup which will always catch
such bugs: we simply set up a Git executable in a separate directory
which writes an error message and immediately aborts with a strange
error value and then adjust our PATH variable to have the executable's
directory as first item. As a result, whenever Git is being executed
with an unqualified path, we'll pick this binary instead of the real Git
and produce an error. Tests would quickly catch this, e.g. like the
following:
```
--- FAIL: TestSuccessfulIsAncestorRequestWithAltGitObjectDirs (0.04s)
commit.go:80: stdout: , stderr: Git executable from $PATH was picked up. Please fix code to use `command.GitPath()` instead.
```
The real Git binary is injected via the `GITALY_TESTING_GIT_BINARY`
environment variable, which is being picked up by our configuration
code.
Diffstat (limited to 'internal/testhelper')
-rwxr-xr-x | internal/testhelper/testdata/home/bin/git | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/testhelper/testdata/home/bin/git b/internal/testhelper/testdata/home/bin/git new file mode 100755 index 000000000..78f4de70b --- /dev/null +++ b/internal/testhelper/testdata/home/bin/git @@ -0,0 +1,12 @@ +#!/bin/sh + +# This wrapper has the single intention of catching any Git invocations via +# $PATH instead of via either our Git DSL or via `config.GitPath()`. Our tests +# are thus set up with PATH including this binary. As the binary always prints +# an error message and exits with a weird status code, tests should fail +# quickly and with a hopefully helpful message making the actual error quick to +# spot. + +echo 'Git executable from $PATH was picked up. Please fix code to use `command.GitPath()` instead.' >&2 + +exit 63 |