suite: put suite setup inside test run

Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit d32e6bbde8)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Tibor Vass 2019-09-09 21:43:11 +00:00 committed by Sebastiaan van Stijn
parent d98c74d38d
commit 4c3e2dc441
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 15 additions and 11 deletions

View File

@ -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)
}