-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscenario.go
50 lines (41 loc) · 929 Bytes
/
scenario.go
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
package elicit
import "testing"
type scenario struct {
context *Context
spec *spec
name string
steps []*step
tables []stringTable
result result
}
func (s *scenario) run(scenarioT *testing.T) {
if len(s.steps) == 0 {
s.result = pending
}
for _, step := range s.steps {
if s.result != passed {
scenarioT.SkipNow()
}
if hookErr := s.context.beforeStep.run("before step"); hookErr != nil {
s.result = panicked
step.result = panicked
scenarioT.Fail()
return
}
s.runStep(scenarioT, step)
}
}
func (s *scenario) runStep(scenarioT *testing.T, step *step) {
// Ensure after step hooks execute regardless of what happens in the step
defer func() {
if step.result > s.result {
s.result = step.result
}
if hookErr := s.context.afterStep.run("after step"); hookErr != nil {
s.result = panicked
step.result = panicked
scenarioT.Fail()
}
}()
step.run(scenarioT)
}