diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-11-19 16:24:24 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2020-11-19 16:24:24 +0300 |
commit | d0d2e010ee004c93b3acd269c97fe8501f54c1c2 (patch) | |
tree | c9dabce1757c244be7727b1413f83dfdc3842db4 /internal/bootstrap | |
parent | d5024702496569b6de051046e5e295c44de94be5 (diff) |
Replace most uses of `ioutil.TempDir()` with `testhelper.TempDir()`
While many of our tests use `ioutil.TempDir`, this is bad practice as
it'll typically create directories directly in `/tmp`. Instead, tests
are expected to call `testhelper.TempDir`, which does roughly the same
but instead creates temporary directories in the global test directory.
This commit converts many users of `ioutil.TempDir()` to
`testhelper.TempDir()`. Remaining users either have no `testing.T`
around or cannot use `internal/testhelper` due to cyclic dependencies.
Diffstat (limited to 'internal/bootstrap')
-rw-r--r-- | internal/bootstrap/bootstrap_test.go | 11 | ||||
-rw-r--r-- | internal/bootstrap/testhelper_test.go | 18 |
2 files changed, 27 insertions, 2 deletions
diff --git a/internal/bootstrap/bootstrap_test.go b/internal/bootstrap/bootstrap_test.go index de824fc2b..bf8230c93 100644 --- a/internal/bootstrap/bootstrap_test.go +++ b/internal/bootstrap/bootstrap_test.go @@ -14,6 +14,7 @@ import ( "time" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/testhelper" ) type mockUpgrader struct { @@ -59,7 +60,10 @@ func (s *testServer) slowRequest(duration time.Duration) <-chan error { } func TestCreateUnixListener(t *testing.T) { - socketPath := filepath.Join(os.TempDir(), "gitaly-test-unix-socket") + tempDir, cleanup := testhelper.TempDir(t) + defer cleanup() + + socketPath := filepath.Join(tempDir, "gitaly-test-unix-socket") if err := os.Remove(socketPath); err != nil { require.True(t, os.IsNotExist(err), "cannot delete dangling socket: %v", err) } @@ -288,9 +292,12 @@ func makeBootstrap(t *testing.T) (*Bootstrap, *testServer) { } } + tempDir, cleanup := testhelper.TempDir(t) + defer cleanup() + for network, address := range map[string]string{ "tcp": "127.0.0.1:0", - "unix": filepath.Join(os.TempDir(), "gitaly-test-unix-socket"), + "unix": filepath.Join(tempDir, "gitaly-test-unix-socket"), } { b.RegisterStarter(start(network, address)) } diff --git a/internal/bootstrap/testhelper_test.go b/internal/bootstrap/testhelper_test.go new file mode 100644 index 000000000..ad7c28be0 --- /dev/null +++ b/internal/bootstrap/testhelper_test.go @@ -0,0 +1,18 @@ +package bootstrap + +import ( + "os" + "testing" + + "gitlab.com/gitlab-org/gitaly/internal/testhelper" +) + +func TestMain(m *testing.M) { + os.Exit(testMain(m)) +} + +func testMain(m *testing.M) int { + cleanup := testhelper.Configure() + defer cleanup() + return m.Run() +} |