diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-20 15:47:12 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-26 17:01:45 +0300 |
commit | ca1875cbde566360179748ec789054718b0bd104 (patch) | |
tree | 93f0ef150b08cbc5ee9c315026ffa90a04ba8bb7 | |
parent | 7987a5e423caefacbae8d0100c855fe3d613f443 (diff) |
testhelper: Don't clutter system temporary directory
During test execution, we create a lot of temporary files which we never
clean up, like for example the internal socket directory. While reigning
in on all of these "leaks" probably doesn't make a whole lot of sense,
it would still be nice to not leave behind so much garbage after test
runs. After a few hours of working, it's certainly impossible for me to
find anything of relevance in my "/tmp" directory because it's littered
with piles of Gitaly files.
Fix this by overriding the temporary directory during tests: instead of
creating them in the global temporary directory, we instead create them
in a "tmp" directory inside of our global test directory.
-rw-r--r-- | internal/testhelper/configure.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/testhelper/configure.go b/internal/testhelper/configure.go index 10196f22f..ec9e49661 100644 --- a/internal/testhelper/configure.go +++ b/internal/testhelper/configure.go @@ -140,6 +140,18 @@ func configureTestDirectory() (_ func(), returnedErr error) { return nil, err } + // In many locations throughout Gitaly, we create temporary files and directories. By + // default, these would clutter the "real" temporary directory with useless cruft that stays + // around after our tests. To avoid this, we thus set the TMPDIR environment variable to + // point into a directory inside of out test directory. + globalTempDir := filepath.Join(testDirectory, "tmp") + if err := os.Mkdir(globalTempDir, 0o755); err != nil { + return nil, fmt.Errorf("creating global temporary directory: %w", err) + } + if err := os.Setenv("TMPDIR", globalTempDir); err != nil { + return nil, fmt.Errorf("setting global temporary directory: %w", err) + } + return cleanup, nil } |