diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-04-23 10:56:50 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-04-23 10:56:50 +0300 |
commit | cb09d8e15dc18b9d8e8dd3e5d0de0f29e7e4efa4 (patch) | |
tree | a0388277e745cac96447b36b043ed788514fa120 /cmd | |
parent | ee7a254f5dec7ccb30424715f84ea899b82f6f81 (diff) |
testhelper: Convert `TempDir()` to use `t.Cleanup()`
Convert `TempDir()` to use `t.Cleanup()` instead of returning a cleanup
function.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/gitaly-backup/create_test.go | 3 | ||||
-rw-r--r-- | cmd/gitaly-hooks/hooks_test.go | 18 | ||||
-rw-r--r-- | cmd/gitaly-lfs-smudge/lfs_smudge_test.go | 9 | ||||
-rw-r--r-- | cmd/gitaly-ssh/auth_test.go | 3 | ||||
-rw-r--r-- | cmd/praefect/subcmd_test.go | 3 |
5 files changed, 12 insertions, 24 deletions
diff --git a/cmd/gitaly-backup/create_test.go b/cmd/gitaly-backup/create_test.go index 4adaa916c..e14944dda 100644 --- a/cmd/gitaly-backup/create_test.go +++ b/cmd/gitaly-backup/create_test.go @@ -24,8 +24,7 @@ func TestCreateSubcommand(t *testing.T) { gitalyAddr := testserver.RunGitalyServer(t, cfg, nil, setup.RegisterAll) - path, cleanup := testhelper.TempDir(t) - t.Cleanup(cleanup) + path := testhelper.TempDir(t) var repos []*gitalypb.Repository for i := 0; i < 5; i++ { diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go index de1633e95..a79baf910 100644 --- a/cmd/gitaly-hooks/hooks_test.go +++ b/cmd/gitaly-hooks/hooks_test.go @@ -104,8 +104,7 @@ func testMain(m *testing.M) int { } func TestHooksPrePostWithSymlinkedStoragePath(t *testing.T) { - tempDir, cleanup := testhelper.TempDir(t) - defer cleanup() + tempDir := testhelper.TempDir(t) cfg, repo, repoPath := testcfg.BuildWithRepo(t) testhelper.ConfigureGitalyHooksBin(t, cfg) @@ -248,8 +247,7 @@ func TestHooksUpdate(t *testing.T) { glUsername := "iamgitlab" glProtocol := "ssh" - customHooksDir, cleanup := testhelper.TempDir(t) - defer cleanup() + customHooksDir := testhelper.TempDir(t) cfg := testcfg.Build(t, testcfg.WithBase(config.Cfg{ Auth: auth.Config{Token: "abc123"}, @@ -283,8 +281,7 @@ func testHooksUpdate(t *testing.T, cfg config.Cfg, glValues glHookValues) { cmd.Env = envForHooks(t, cfg, repo, glValues, proxyValues{}) cmd.Dir = repoPath - tempDir, cleanup := testhelper.TempDir(t) - defer cleanup() + tempDir := testhelper.TempDir(t) customHookArgsPath := filepath.Join(tempDir, "containsarguments") dumpArgsToTempfileScript := fmt.Sprintf(`#!/usr/bin/env ruby @@ -511,8 +508,7 @@ func TestCheckOK(t *testing.T) { serverURL, cleanup := testhelper.NewGitlabTestServer(t, c) defer cleanup() - tempDir, cleanup := testhelper.TempDir(t) - defer cleanup() + tempDir := testhelper.TempDir(t) gitlabShellDir := filepath.Join(tempDir, "gitlab-shell") require.NoError(t, os.MkdirAll(gitlabShellDir, 0755)) @@ -556,8 +552,7 @@ func TestCheckBadCreds(t *testing.T) { serverURL, cleanup := testhelper.NewGitlabTestServer(t, c) defer cleanup() - tempDir, cleanup := testhelper.TempDir(t) - defer cleanup() + tempDir := testhelper.TempDir(t) gitlabShellDir := filepath.Join(tempDir, "gitlab-shell") require.NoError(t, os.MkdirAll(gitlabShellDir, 0755)) @@ -697,8 +692,7 @@ func TestGitalyHooksPackObjects(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { defer runHookServiceServer(t, cfg)() - tempDir, cleanTempDir := testhelper.TempDir(t) - defer cleanTempDir() + tempDir := testhelper.TempDir(t) args := append(baseArgs[1:], tc.extraArgs...) args = append(args, repoPath, tempDir) diff --git a/cmd/gitaly-lfs-smudge/lfs_smudge_test.go b/cmd/gitaly-lfs-smudge/lfs_smudge_test.go index 097d0df60..d87c2b1fe 100644 --- a/cmd/gitaly-lfs-smudge/lfs_smudge_test.go +++ b/cmd/gitaly-lfs-smudge/lfs_smudge_test.go @@ -69,7 +69,7 @@ func (m *mapConfig) Get(key string) string { } func runTestServer(t *testing.T, options testhelper.GitlabTestServerOptions) (config.Gitlab, func()) { - tempDir, cleanup := testhelper.TempDir(t) + tempDir := testhelper.TempDir(t) testhelper.WriteShellSecretFile(t, tempDir, secretToken) secretFilePath := filepath.Join(tempDir, ".gitlab_shell_secret") @@ -79,7 +79,6 @@ func runTestServer(t *testing.T, options testhelper.GitlabTestServerOptions) (co c := config.Gitlab{URL: serverURL, SecretFile: secretFilePath, HTTPSettings: config.HTTPSettings{CAFile: certPath}} return c, func() { - cleanup() serverCleanup() } } @@ -116,8 +115,7 @@ func TestSuccessfulLfsSmudge(t *testing.T) { }) require.NoError(t, err) - tmpDir, cleanup := testhelper.TempDir(t) - defer cleanup() + tmpDir := testhelper.TempDir(t) env := map[string]string{ "GL_REPOSITORY": "project-1", @@ -225,8 +223,7 @@ func TestUnsuccessfulLfsSmudge(t *testing.T) { tlsCfg, err := json.Marshal(tc.tlsCfg) require.NoError(t, err) - tmpDir, cleanup := testhelper.TempDir(t) - defer cleanup() + tmpDir := testhelper.TempDir(t) env := map[string]string{ "GL_REPOSITORY": "project-1", diff --git a/cmd/gitaly-ssh/auth_test.go b/cmd/gitaly-ssh/auth_test.go index 4a5c713f3..f1b1d218b 100644 --- a/cmd/gitaly-ssh/auth_test.go +++ b/cmd/gitaly-ssh/auth_test.go @@ -39,8 +39,7 @@ func TestConnectivity(t *testing.T) { certPoolPath := filepath.Join(cwd, "testdata", "certs") - tempDir, cleanup := testhelper.TempDir(t) - defer cleanup() + tempDir := testhelper.TempDir(t) relativeSocketPath, err := filepath.Rel(cwd, filepath.Join(tempDir, "gitaly.socket")) require.NoError(t, err) diff --git a/cmd/praefect/subcmd_test.go b/cmd/praefect/subcmd_test.go index ea91e60df..d966b77d0 100644 --- a/cmd/praefect/subcmd_test.go +++ b/cmd/praefect/subcmd_test.go @@ -33,7 +33,7 @@ func registerServerService(impl gitalypb.ServerServiceServer) svcRegistrar { func listenAndServe(t testing.TB, svcs []svcRegistrar) (net.Listener, testhelper.Cleanup) { t.Helper() - tmp, clean := testhelper.TempDir(t) + tmp := testhelper.TempDir(t) ln, err := net.Listen("unix", filepath.Join(tmp, "gitaly")) require.NoError(t, err) @@ -57,6 +57,5 @@ func listenAndServe(t testing.TB, svcs []svcRegistrar) (net.Listener, testhelper return ln, func() { srv.Stop() - clean() } } |