forked from motiv-labs/janus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
93 lines (77 loc) · 2.03 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
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
package main
import (
"context"
"net/url"
"os"
"strconv"
"testing"
"github.com/cucumber/godog"
"github.com/stretchr/testify/assert"
"github.com/hellofresh/janus/features/bootstrap"
"github.com/hellofresh/janus/pkg/api"
"github.com/hellofresh/janus/pkg/config"
)
const defaultUpstreamsPort = 9089
var (
apiRepo api.Repository
cfg *config.Specification
cfgChan chan api.ConfigurationMessage
portSecondary int
apiPortSecondary int
upstreamsPort int
)
func InitializeTestSuite(ctx *godog.TestSuiteContext) {
var err error
ctx.BeforeSuite(func() {
cfg, err = config.LoadEnv()
if err != nil {
panic(err)
}
dsnURL, err := url.Parse(cfg.Database.DSN)
if nil != err {
panic(err)
}
switch dsnURL.Scheme {
case "mongodb":
apiRepo, err = api.NewMongoAppRepository(cfg.Database.DSN, cfg.BackendFlushInterval)
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 err != nil {
panic(err)
}
apiPortSecondary, err = strconv.Atoi(os.Getenv("API_PORT_SECONDARY"))
if err != nil {
panic(err)
}
upstreamsPort = defaultUpstreamsPort
if dynamicUpstreamsPort, exists := os.LookupEnv("DYNAMIC_UPSTREAMS_PORT"); exists {
upstreamsPort, err = strconv.Atoi(dynamicUpstreamsPort)
if err != nil {
panic(err)
}
}
cfgChan = make(chan api.ConfigurationMessage, 100)
if listener, ok := apiRepo.(api.Listener); ok {
listener.Listen(context.Background(), cfgChan)
}
})
}
func InitializeScenario(ctx *godog.ScenarioContext) {
bootstrap.RegisterRequestContext(ctx, cfg.Port, cfg.Web.Port, portSecondary, apiPortSecondary, defaultUpstreamsPort, upstreamsPort, cfg.Web.Credentials)
bootstrap.RegisterAPIContext(ctx, apiRepo, cfgChan)
bootstrap.RegisterMiscContext(ctx)
}
func Test_Fake(t *testing.T) {
assert.True(t, true)
}