-
Notifications
You must be signed in to change notification settings - Fork 0
/
badaas_e2e_test.go
56 lines (46 loc) · 1.17 KB
/
badaas_e2e_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
package main
import (
"net/http"
"net/http/cookiejar"
"os"
"testing"
"time"
"github.com/cucumber/godog"
"github.com/cucumber/godog/colors"
"github.com/spf13/pflag"
)
type TestContext struct {
statusCode int
json map[string]interface{}
httpClient *http.Client
}
var opts = godog.Options{Output: colors.Colored(os.Stdout)}
func init() {
godog.BindCommandLineFlags("godog.", &opts)
}
func TestMain(m *testing.M) {
pflag.Parse()
opts.Paths = pflag.Args()
status := godog.TestSuite{
Name: "godogs",
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
os.Exit(status)
}
func InitializeScenario(ctx *godog.ScenarioContext) {
t := &TestContext{}
jar, err := cookiejar.New(nil)
if err != nil {
panic(err)
}
t.httpClient = &http.Client{
Transport: http.DefaultTransport,
Timeout: time.Duration(5 * time.Second),
Jar: jar,
}
ctx.Step(`^I request "(.+)"$`, t.requestGET)
ctx.Step(`^I expect status code is "(\d+)"$`, t.assertStatusCode)
ctx.Step(`^I expect response field "(.+)" is "(.+)"$`, t.assertResponseFieldIsEquals)
ctx.Step(`^I request "(.+)" with method "(.+)" with json$`, t.requestWithJson)
}