Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame] | 1 | package leafnodes |
| 2 | |
| 3 | import ( |
| 4 | "time" |
| 5 | |
| 6 | "github.com/onsi/ginkgo/internal/failer" |
| 7 | "github.com/onsi/ginkgo/types" |
| 8 | ) |
| 9 | |
| 10 | type SuiteNode interface { |
| 11 | Run(parallelNode int, parallelTotal int, syncHost string) bool |
| 12 | Passed() bool |
| 13 | Summary() *types.SetupSummary |
| 14 | } |
| 15 | |
| 16 | type simpleSuiteNode struct { |
| 17 | runner *runner |
| 18 | outcome types.SpecState |
| 19 | failure types.SpecFailure |
| 20 | runTime time.Duration |
| 21 | } |
| 22 | |
| 23 | func (node *simpleSuiteNode) Run(parallelNode int, parallelTotal int, syncHost string) bool { |
| 24 | t := time.Now() |
| 25 | node.outcome, node.failure = node.runner.run() |
| 26 | node.runTime = time.Since(t) |
| 27 | |
| 28 | return node.outcome == types.SpecStatePassed |
| 29 | } |
| 30 | |
| 31 | func (node *simpleSuiteNode) Passed() bool { |
| 32 | return node.outcome == types.SpecStatePassed |
| 33 | } |
| 34 | |
| 35 | func (node *simpleSuiteNode) Summary() *types.SetupSummary { |
| 36 | return &types.SetupSummary{ |
| 37 | ComponentType: node.runner.nodeType, |
| 38 | CodeLocation: node.runner.codeLocation, |
| 39 | State: node.outcome, |
| 40 | RunTime: node.runTime, |
| 41 | Failure: node.failure, |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | func NewBeforeSuiteNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer) SuiteNode { |
| 46 | return &simpleSuiteNode{ |
| 47 | runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeBeforeSuite, 0), |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | func NewAfterSuiteNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer) SuiteNode { |
| 52 | return &simpleSuiteNode{ |
| 53 | runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeAfterSuite, 0), |
| 54 | } |
| 55 | } |