-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
54 lines (47 loc) · 1.88 KB
/
main_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
package main
import (
"context"
"testing"
"github.com/caarlos0/env/v7"
"github.com/cucumber/godog"
)
func InitializeScenario(ctx *godog.ScenarioContext) {
var cfg config
err := env.Parse(&cfg)
if err != nil {
panic(err)
}
api := &httpFeature{cfg: cfg, validator: newValidator()}
conjur := &conjur{api: api}
conjurdb := &conjurdb{cfg}
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
api.resetResponse(sc)
api.validator.ignoreRouteError = false
return ctx, nil
})
ctx.Step(`^my basic auth credentials are incorrect$`, api.myBasicAuthCredentialsAreIncorrect)
ctx.Step(`^my request doesn\'t include the X-Broker-API-Version header$`, api.myRequestDoesntIncludeTheXBrokerAPIVersionHeader)
ctx.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendRequestTo)
ctx.Step(`^I send "([^"]*)" request to "([^"]*)" with body:$`, api.iSendRequestToWithBody)
ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSONBody)
ctx.Step(`^the response should match json "([^"]*)"$`, api.theResponseShouldMatchJSON)
ctx.Step(`^conjur credentials are invalid$`, conjur.conjurCredentialsAreInvalid)
ctx.Step(`^conjur credentials are valid$`, conjur.conjurCredentialsAreValid)
ctx.Step(`^I create conjur client$`, conjur.iCreateConjurClientFromAPIResponse)
ctx.Step(`^conjur resource "([^"]*)" exists$`, conjurdb.conjurResourceExists)
ctx.Step(`^I ignore route error$`, api.validator.iIgnoreRouteNotExists)
}
func TestIntegration(t *testing.T) {
suite := godog.TestSuite{
ScenarioInitializer: InitializeScenario,
Options: &godog.Options{
Format: "pretty",
Paths: []string{"features"},
TestingT: t, // Testing instance that will run subtests.
},
}
if suite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}