From ceba1579a711103c56c30e510a07d61444191717 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 15 Apr 2021 10:49:43 +0200 Subject: testhelper: Convert `WriteExecutable()` to use `t.Cleanup()` Now that the minimum required Go version is 1.14, we have started to make use of `t.Cleanup()` to clean up temporary test state. Convert `WriteExecutable()` and some of its user to use it, too, instead of returning cleanup functions. --- cmd/gitaly-hooks/hooks_test.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'cmd/gitaly-hooks') diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go index dfad57eea..f0fd73693 100644 --- a/cmd/gitaly-hooks/hooks_test.go +++ b/cmd/gitaly-hooks/hooks_test.go @@ -158,8 +158,7 @@ func testHooksPrePostReceive(t *testing.T, cfg config.Cfg, repo *gitalypb.Reposi for _, hookName := range hookNames { t.Run(fmt.Sprintf("hookName: %s", hookName), func(t *testing.T) { - customHookOutputPath, cleanup := gittest.WriteEnvToCustomHook(t, repoPath, hookName) - defer cleanup() + customHookOutputPath := gittest.WriteEnvToCustomHook(t, repoPath, hookName) gitlabAPI, err := gitalyhook.NewGitlabAPI(cfg.Gitlab, cfg.TLS) require.NoError(t, err) @@ -281,12 +280,10 @@ require 'json' open('%s', 'w') { |f| f.puts(JSON.dump(ARGV)) } `, customHookArgsPath) // write a custom hook to path/to/repo.git/custom_hooks/update.d/dumpargsscript which dumps the args into a tempfile - cleanup = testhelper.WriteExecutable(t, filepath.Join(repoPath, "custom_hooks", "update.d", "dumpargsscript"), []byte(dumpArgsToTempfileScript)) - defer cleanup() + testhelper.WriteExecutable(t, filepath.Join(repoPath, "custom_hooks", "update.d", "dumpargsscript"), []byte(dumpArgsToTempfileScript)) // write a custom hook to path/to/repo.git/custom_hooks/update which dumps the env into a tempfile - customHookOutputPath, cleanup := gittest.WriteEnvToCustomHook(t, repoPath, "update") - defer cleanup() + customHookOutputPath := gittest.WriteEnvToCustomHook(t, repoPath, "update") var stdout, stderr bytes.Buffer @@ -350,8 +347,7 @@ func TestHooksPostReceiveFailed(t *testing.T) { stop := runHookServiceServerWithAPI(t, cfg, gitlabAPI) defer stop() - customHookOutputPath, cleanup := gittest.WriteEnvToCustomHook(t, repoPath, "post-receive") - defer cleanup() + customHookOutputPath := gittest.WriteEnvToCustomHook(t, repoPath, "post-receive") var stdout, stderr bytes.Buffer @@ -460,8 +456,7 @@ func TestHooksNotAllowed(t *testing.T) { cfg.Gitlab.URL = serverURL cfg.Gitlab.SecretFile = testhelper.WriteShellSecretFile(t, cfg.GitlabShell.Dir, "the wrong token") - customHookOutputPath, cleanup := gittest.WriteEnvToCustomHook(t, repoPath, "post-receive") - defer cleanup() + customHookOutputPath := gittest.WriteEnvToCustomHook(t, repoPath, "post-receive") gitlabAPI, err := gitalyhook.NewGitlabAPI(cfg.Gitlab, cfg.TLS) require.NoError(t, err) -- cgit v1.2.3