Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit d32e6bbde815f37aa1cb23f602ab6371b509f3b2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -21,6 +21,14 @@ func Run(t *testing.T, suite interface{}) {
|
| 21 | 21 |
|
| 22 | 22 |
suiteSetupDone := false |
| 23 | 23 |
|
| 24 |
+ defer func() {
|
|
| 25 |
+ if suiteSetupDone {
|
|
| 26 |
+ if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
|
|
| 27 |
+ tearDownAllSuite.TearDownSuite(t) |
|
| 28 |
+ } |
|
| 29 |
+ } |
|
| 30 |
+ }() |
|
| 31 |
+ |
|
| 24 | 32 |
methodFinder := reflect.TypeOf(suite) |
| 25 | 33 |
suiteName := methodFinder.Elem().Name() |
| 26 | 34 |
for index := 0; index < methodFinder.NumMethod(); index++ {
|
| ... | ... |
@@ -28,20 +36,16 @@ func Run(t *testing.T, suite interface{}) {
|
| 28 | 28 |
if !methodFilter(method.Name, method.Type) {
|
| 29 | 29 |
continue |
| 30 | 30 |
} |
| 31 |
- if !suiteSetupDone {
|
|
| 32 |
- if setupAllSuite, ok := suite.(SetupAllSuite); ok {
|
|
| 33 |
- setupAllSuite.SetUpSuite(t) |
|
| 34 |
- } |
|
| 35 |
- defer func() {
|
|
| 36 |
- if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
|
|
| 37 |
- tearDownAllSuite.TearDownSuite(t) |
|
| 38 |
- } |
|
| 39 |
- }() |
|
| 40 |
- suiteSetupDone = true |
|
| 41 |
- } |
|
| 42 | 31 |
t.Run(suiteName+"/"+method.Name, func(t *testing.T) {
|
| 43 | 32 |
defer failOnPanic(t) |
| 44 | 33 |
|
| 34 |
+ if !suiteSetupDone {
|
|
| 35 |
+ if setupAllSuite, ok := suite.(SetupAllSuite); ok {
|
|
| 36 |
+ setupAllSuite.SetUpSuite(t) |
|
| 37 |
+ } |
|
| 38 |
+ suiteSetupDone = true |
|
| 39 |
+ } |
|
| 40 |
+ |
|
| 45 | 41 |
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
|
| 46 | 42 |
setupTestSuite.SetUpTest(t) |
| 47 | 43 |
} |