summaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/ginkgo/internal/leafnodes/suite_nodes.go
blob: 80f16ed7861cd4bba3feeeacb5bdd123737aacb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package leafnodes

import (
	"time"

	"github.com/onsi/ginkgo/internal/failer"
	"github.com/onsi/ginkgo/types"
)

type SuiteNode interface {
	Run(parallelNode int, parallelTotal int, syncHost string) bool
	Passed() bool
	Summary() *types.SetupSummary
}

type simpleSuiteNode struct {
	runner  *runner
	outcome types.SpecState
	failure types.SpecFailure
	runTime time.Duration
}

func (node *simpleSuiteNode) Run(parallelNode int, parallelTotal int, syncHost string) bool {
	t := time.Now()
	node.outcome, node.failure = node.runner.run()
	node.runTime = time.Since(t)

	return node.outcome == types.SpecStatePassed
}

func (node *simpleSuiteNode) Passed() bool {
	return node.outcome == types.SpecStatePassed
}

func (node *simpleSuiteNode) Summary() *types.SetupSummary {
	return &types.SetupSummary{
		ComponentType: node.runner.nodeType,
		CodeLocation:  node.runner.codeLocation,
		State:         node.outcome,
		RunTime:       node.runTime,
		Failure:       node.failure,
	}
}

func NewBeforeSuiteNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer) SuiteNode {
	return &simpleSuiteNode{
		runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeBeforeSuite, 0),
	}
}

func NewAfterSuiteNode(body interface{}, codeLocation types.CodeLocation, timeout time.Duration, failer *failer.Failer) SuiteNode {
	return &simpleSuiteNode{
		runner: newRunner(body, codeLocation, timeout, failer, types.SpecComponentTypeAfterSuite, 0),
	}
}