-
Notifications
You must be signed in to change notification settings - Fork 2
/
godog_test.go
84 lines (68 loc) · 1.54 KB
/
godog_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package grpcsteps_test
import (
"bytes"
"fmt"
"time"
"github.com/cucumber/godog"
)
type suiteT interface {
Logf(format string, args ...interface{})
Errorf(format string, args ...interface{})
}
type suiteOption func(ts *godog.TestSuite)
func runSuite(t suiteT, opts ...suiteOption) {
buf := bytes.NewBuffer(nil)
suite := godog.TestSuite{
Options: &godog.Options{
Format: "pretty",
Output: buf,
Strict: true,
Randomize: time.Now().UTC().UnixNano(),
},
}
for _, o := range opts {
o(&suite)
}
if status := suite.Run(); status != 0 {
t.Errorf(buf.String())
}
}
func initSuite(init func(ctx *godog.TestSuiteContext)) suiteOption {
return func(ts *godog.TestSuite) {
ts.TestSuiteInitializer = init
}
}
func afterSuite(fn func()) suiteOption {
return initSuite(func(tsc *godog.TestSuiteContext) {
tsc.AfterSuite(fn)
})
}
func initScenario(initializers ...func(ctx *godog.ScenarioContext)) suiteOption {
return func(ts *godog.TestSuite) {
ts.ScenarioInitializer = func(ctx *godog.ScenarioContext) {
for _, i := range initializers {
i(ctx)
}
}
}
}
func featureFiles(paths ...string) suiteOption {
return func(ts *godog.TestSuite) {
ts.Options.Paths = paths
}
}
func noColors() suiteOption {
return func(ts *godog.TestSuite) {
ts.Options.NoColors = true
}
}
type testT struct {
error error
}
func (t *testT) Logf(format string, args ...interface{}) {
fmt.Printf(format, args...)
fmt.Println()
}
func (t *testT) Errorf(format string, args ...interface{}) {
t.error = fmt.Errorf(format, args...)
}