diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-04-15 12:02:22 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-04-19 10:23:54 +0300 |
commit | 92408deb93d019442f5c781266a0b734373692f7 (patch) | |
tree | 9468a2895d8296091acbbe45551b30ec9f25516a /cmd | |
parent | ceba1579a711103c56c30e510a07d61444191717 (diff) |
gittest: Do not precreate hook env in `WriteEnvToCustomHook()`
With `WriteEnvToCustomHook()`, we install a custom hook which prints the
hook environment variables into a file. This can be used either to
verify that the hook is run with the expected set of envvars, or to
check whether the hook ran in the first place.
The latter usecase is a bit convoluted though: because of how the setup
is done, we always precreate the file into which the envvars get printed
into. As a result, we cannot derive whether a hook ran based on the
existence of the env file, but instead must verify that it is still
empty.
Refactor `WriteEnvToCustomHook()` by using a temporary directory,
which easily allows us to not precreate the env file.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/gitaly-hooks/hooks_test.go | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go index f0fd73693..d2e0ffa8f 100644 --- a/cmd/gitaly-hooks/hooks_test.go +++ b/cmd/gitaly-hooks/hooks_test.go @@ -370,9 +370,7 @@ func TestHooksPostReceiveFailed(t *testing.T) { require.Equal(t, 1, code, "exit status") require.Empty(t, stdout.String()) require.Empty(t, stderr.String()) - - output := string(testhelper.MustReadFile(t, customHookOutputPath)) - require.Empty(t, output, "custom hook should not have run") + require.NoFileExists(t, customHookOutputPath) }, }, { @@ -384,9 +382,7 @@ func TestHooksPostReceiveFailed(t *testing.T) { require.Empty(t, stdout.String()) require.Empty(t, stderr.String()) - - output := string(testhelper.MustReadFile(t, customHookOutputPath)) - require.Empty(t, output, "custom hook should not have run") + require.NoFileExists(t, customHookOutputPath) }, }, } @@ -484,9 +480,7 @@ func TestHooksNotAllowed(t *testing.T) { require.Error(t, cmd.Run()) require.Equal(t, "GitLab: 401 Unauthorized\n", stderr.String()) require.Equal(t, "", stdout.String()) - - output := string(testhelper.MustReadFile(t, customHookOutputPath)) - require.Empty(t, output, "custom hook should not have run") + require.NoFileExists(t, customHookOutputPath) } func TestCheckOK(t *testing.T) { |