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/praefect/replicator_test.go | |
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/praefect/replicator_test.go')
-rw-r--r-- | internal/praefect/replicator_test.go | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go index 114cfbe14..2629cad84 100644 --- a/internal/praefect/replicator_test.go +++ b/internal/praefect/replicator_test.go @@ -2,7 +2,6 @@ package praefect import ( "context" - "io/ioutil" "net" "os" "path/filepath" @@ -82,10 +81,9 @@ func testMain(m *testing.M) int { func TestReplMgr_ProcessBacklog(t *testing.T) { backupStorageName := "backup" - backupDir, err := ioutil.TempDir(testhelper.GitlabTestStoragePath(), backupStorageName) - require.NoError(t, err) + backupDir, cleanup := testhelper.TempDir(t) + defer cleanup() - defer func() { os.RemoveAll(backupDir) }() defer func(oldStorages []gitaly_config.Storage) { gitaly_config.Config.Storages = oldStorages }(gitaly_config.Config.Storages) gitaly_config.Config.Storages = append(gitaly_config.Config.Storages, @@ -537,9 +535,8 @@ func TestConfirmReplication(t *testing.T) { func TestProcessBacklog_FailedJobs(t *testing.T) { backupStorageName := "backup" - backupDir, err := ioutil.TempDir(testhelper.GitlabTestStoragePath(), backupStorageName) - require.NoError(t, err) - defer os.RemoveAll(backupDir) + backupDir, cleanup := testhelper.TempDir(t) + defer cleanup() defer func(oldStorages []gitaly_config.Storage) { gitaly_config.Config.Storages = oldStorages }(gitaly_config.Config.Storages) gitaly_config.Config.Storages = append(gitaly_config.Config.Storages, gitaly_config.Storage{ @@ -668,9 +665,8 @@ func TestProcessBacklog_FailedJobs(t *testing.T) { func TestProcessBacklog_Success(t *testing.T) { defer func(oldStorages []gitaly_config.Storage) { gitaly_config.Config.Storages = oldStorages }(gitaly_config.Config.Storages) - backupDir, err := ioutil.TempDir("", "") - require.NoError(t, err) - defer os.RemoveAll(backupDir) + backupDir, cleanup := testhelper.TempDir(t) + defer cleanup() gitaly_config.Config.Storages = append(gitaly_config.Config.Storages, gitaly_config.Storage{ Name: "backup", @@ -740,7 +736,7 @@ func TestProcessBacklog_Success(t *testing.T) { }, } - _, err = queueInterceptor.Enqueue(ctx, eventType1) + _, err := queueInterceptor.Enqueue(ctx, eventType1) require.NoError(t, err) _, err = queueInterceptor.Enqueue(ctx, eventType1) |