diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-06 09:53:36 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-10-07 08:37:22 +0300 |
commit | d8b43e951b747acc49a8d1fff1d59be9867a5eca (patch) | |
tree | ac836f0ff0cd7db109900e2f0bb7b10a0dfff835 /internal/helper/repo_test.go | |
parent | 27de9ce6c8a34f387ea2f3a00ca08fdbb4f74099 (diff) |
testhelper: Unify setup of test suites
Setup of a test package's main function is quite repetitive: we call a
separate `testMain()` function such that we can use `defer` calls, this
function calls `MustHaveNoChildProcess()` and `Configure()`, and then we
return the result of `m.Run()`. This is almost always exactly the same,
with some exceptions where we need to have additional setup code.
Unify this code via a single `testhelper.Run()` function which does all
of this. It allows us greater flexibility in the setup code such that we
can easily perform additional validation after the tests without having
to modify all callsites.
Note that this change removes calls to the goleak package in some
places. These will resurface in a later commit in this patch series,
where we instead move this call into `testhelper.Run()` such that it is
executed by default.
Diffstat (limited to 'internal/helper/repo_test.go')
-rw-r--r-- | internal/helper/repo_test.go | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/internal/helper/repo_test.go b/internal/helper/repo_test.go index fb5961c52..c65665131 100644 --- a/internal/helper/repo_test.go +++ b/internal/helper/repo_test.go @@ -1,7 +1,6 @@ package helper import ( - "os" "testing" "github.com/stretchr/testify/assert" @@ -10,14 +9,7 @@ import ( ) func TestMain(m *testing.M) { - os.Exit(testMain(m)) -} - -func testMain(m *testing.M) int { - defer testhelper.MustHaveNoChildProcess() - cleanup := testhelper.Configure() - defer cleanup() - return m.Run() + testhelper.Run(m) } func TestRepoPathEqual(t *testing.T) { |