forked from motiv-labs/janus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
godog_test.go
101 lines (83 loc) · 2.02 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package janus
import (
"flag"
"net/url"
"os"
"strconv"
"testing"
"time"
"github.com/DATA-DOG/godog"
"github.com/hellofresh/janus/features/bootstrap"
"github.com/hellofresh/janus/pkg/api"
"github.com/hellofresh/janus/pkg/config"
"github.com/stretchr/testify/assert"
"gopkg.in/mgo.v2"
)
var (
runGoDogTests bool
stopOnFailure bool
)
func init() {
flag.BoolVar(&runGoDogTests, "godog", false, "Set this flag is you want to run godog BDD tests")
flag.BoolVar(&stopOnFailure, "stop-on-failure", false, "Stop processing on first failed scenario.. Flag is passed to godog")
flag.Parse()
}
func FeatureContext(s *godog.Suite) {
c, err := config.LoadEnv()
if nil != err {
panic(err)
}
var apiRepo api.Repository
dsnURL, err := url.Parse(c.Database.DSN)
switch dsnURL.Scheme {
case "mongodb":
session, err := mgo.Dial(c.Database.DSN)
if err != nil {
panic(err)
}
session.SetMode(mgo.Monotonic, true)
apiRepo, err = api.NewMongoAppRepository(session)
if err != nil {
panic(err)
}
case "file":
var apiPath = dsnURL.Path + "/apis"
apiRepo, err = api.NewFileSystemRepository(apiPath)
if err != nil {
panic(err)
}
default:
panic("invalid database")
}
portSecondary, err := strconv.Atoi(os.Getenv("PORT_SECONDARY"))
if nil != err {
panic(err)
}
apiPortSecondary, err := strconv.Atoi(os.Getenv("API_PORT_SECONDARY"))
if nil != err {
panic(err)
}
bootstrap.RegisterRequestContext(s, c.Port, c.Web.Port, portSecondary, apiPortSecondary, c.Web.Credentials)
bootstrap.RegisterAPIContext(s, c.Web.ReadOnly, apiRepo)
bootstrap.RegisterMiscContext(s)
}
func Test_Fake(t *testing.T) {
assert.True(t, true)
}
func TestMain(m *testing.M) {
if !runGoDogTests {
os.Exit(m.Run())
}
status := godog.RunWithOptions("Janus", func(s *godog.Suite) {
FeatureContext(s)
}, godog.Options{
Format: "pretty",
Paths: []string{"features"},
Randomize: time.Now().UTC().UnixNano(),
StopOnFailure: stopOnFailure,
})
if st := m.Run(); st > status {
status = st
}
os.Exit(status)
}