From 4c3e2dc441d7d55ba9e774656c9bc988d872a895 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Mon, 9 Sep 2019 21:43:11 +0000 Subject: [PATCH] suite: put suite setup inside test run Signed-off-by: Tibor Vass (cherry picked from commit d32e6bbde815f37aa1cb23f602ab6371b509f3b2) Signed-off-by: Sebastiaan van Stijn --- internal/test/suite/suite.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/internal/test/suite/suite.go b/internal/test/suite/suite.go index cd00de4e54..c13be854e0 100644 --- a/internal/test/suite/suite.go +++ b/internal/test/suite/suite.go @@ -21,6 +21,14 @@ func Run(t *testing.T, suite interface{}) { suiteSetupDone := false + defer func() { + if suiteSetupDone { + if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok { + tearDownAllSuite.TearDownSuite(t) + } + } + }() + methodFinder := reflect.TypeOf(suite) suiteName := methodFinder.Elem().Name() for index := 0; index < methodFinder.NumMethod(); index++ { @@ -28,20 +36,16 @@ func Run(t *testing.T, suite interface{}) { if !methodFilter(method.Name, method.Type) { continue } - if !suiteSetupDone { - if setupAllSuite, ok := suite.(SetupAllSuite); ok { - setupAllSuite.SetUpSuite(t) - } - defer func() { - if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok { - tearDownAllSuite.TearDownSuite(t) - } - }() - suiteSetupDone = true - } t.Run(suiteName+"/"+method.Name, func(t *testing.T) { defer failOnPanic(t) + if !suiteSetupDone { + if setupAllSuite, ok := suite.(SetupAllSuite); ok { + setupAllSuite.SetUpSuite(t) + } + suiteSetupDone = true + } + if setupTestSuite, ok := suite.(SetupTestSuite); ok { setupTestSuite.SetUpTest(t) }