Skip to content

Commit 971b5e1

Browse files
authored
Add cleanup function for testing.M (#691)
1 parent 4e1854d commit 971b5e1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test_main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ var testPackage *TestPackage
1919
// docker containers stepping on each other. For MSCs, use the MSC name. For versioned releases, use the version number
2020
// along with any sub-directory name.
2121
func TestMain(m *testing.M, namespace string) {
22+
TestMainWithCleanup(m, namespace, nil)
23+
}
24+
25+
// TestMainWithCleanup is TestMain but with a cleanup function prior to terminating the test suite.
26+
// This function should be used for per-suite cleanup operations e.g tearing down containers, killing
27+
// child processes, etc.
28+
func TestMainWithCleanup(m *testing.M, namespace string, cleanup func()) {
2229
var err error
2330
testPackage, err = NewTestPackage(namespace)
2431
if err != nil {
@@ -27,6 +34,9 @@ func TestMain(m *testing.M, namespace string) {
2734
}
2835
exitCode := m.Run()
2936
testPackage.Cleanup()
37+
if cleanup != nil {
38+
cleanup()
39+
}
3040
os.Exit(exitCode)
3141
}
3242

0 commit comments

Comments
 (0)