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:
parent
d98c74d38d
commit
4c3e2dc441
1 changed files with 15 additions and 11 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue