-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgodog_helpers_test.go
50 lines (41 loc) · 1.29 KB
/
godog_helpers_test.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 kubernetes_ctx_test
import (
"github.com/cucumber/godog"
)
// MockScenarioContext returns a mocked ScenarioContext.
func MockScenarioContext() *scenarioContextMock {
return &scenarioContextMock{}
}
type (
scenarioContextMock struct {
beforeScenarioList []func(sc *godog.Scenario)
afterScenarioList []func(sc *godog.Scenario, err error)
beforeStepList []func(sc *godog.Step)
afterStepList []func(sc *godog.Step, err error)
stepList []stepMock
}
stepMock struct {
expr interface{}
fnc interface{}
}
)
func (s *scenarioContextMock) BeforeScenario(fn func(sc *godog.Scenario)) {
s.beforeScenarioList = append(s.beforeScenarioList, fn)
}
func (s *scenarioContextMock) AfterScenario(fn func(sc *godog.Scenario, err error)) {
s.afterScenarioList = append(s.afterScenarioList, fn)
}
func (s *scenarioContextMock) BeforeStep(fn func(st *godog.Step)) {
s.beforeStepList = append(s.beforeStepList, fn)
}
func (s *scenarioContextMock) AfterStep(fn func(st *godog.Step, err error)) {
s.afterStepList = append(s.afterStepList, fn)
}
func (s *scenarioContextMock) Step(expr, stepFunc interface{}) {
s.stepList = append(s.stepList, stepMock{expr: expr, fnc: stepFunc})
}
func (s *scenarioContextMock) RunScenario() {
for _, fn := range s.beforeScenarioList {
fn(nil)
}
}