forked from cloudfoundry/gorouter
/
helpers.go
87 lines (66 loc) · 2 KB
/
helpers.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
package test_util
import (
"path/filepath"
"runtime"
"github.com/cloudfoundry-incubator/uaa-token-fetcher"
"github.com/cloudfoundry/gorouter/config"
"github.com/pivotal-golang/lager/lagertest"
"time"
. "github.com/onsi/gomega"
)
func SpecConfig(natsPort, statusPort, proxyPort uint16) *config.Config {
return generateConfig(natsPort, statusPort, proxyPort)
}
func SpecSSLConfig(natsPort, statusPort, proxyPort, SSLPort uint16) *config.Config {
c := generateConfig(natsPort, statusPort, proxyPort)
c.EnableSSL = true
_, filename, _, _ := runtime.Caller(0)
testPath, err := filepath.Abs(filepath.Join(filename, "..", "..", "test", "assets"))
Expect(err).NotTo(HaveOccurred())
c.SSLKeyPath = filepath.Join(testPath, "private.pem")
c.SSLCertPath = filepath.Join(testPath, "public.pem")
c.SSLPort = SSLPort
c.CipherString = "TLS_RSA_WITH_AES_128_CBC_SHA:TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"
return c
}
func generateConfig(natsPort, statusPort, proxyPort uint16) *config.Config {
logger := lagertest.NewTestLogger("test")
c := config.DefaultConfig(logger)
c.Port = proxyPort
c.Index = 2
c.TraceKey = "my_trace_key"
// Hardcode the IP to localhost to avoid leaving the machine while running tests
c.Ip = "127.0.0.1"
c.StartResponseDelayInterval = 10 * time.Millisecond
c.PublishStartMessageIntervalInSeconds = 10
c.PruneStaleDropletsInterval = 0
c.DropletStaleThreshold = 0
c.PublishActiveAppsInterval = 0
c.Zone = "z1"
c.EndpointTimeout = 500 * time.Millisecond
c.Status = config.StatusConfig{
Port: statusPort,
User: "user",
Pass: "pass",
}
c.Nats = []config.NatsConfig{
{
Host: "localhost",
Port: natsPort,
User: "nats",
Pass: "nats",
},
}
c.Logging = config.LoggingConfig{
File: "/dev/stdout",
Level: "info",
MetronAddress: "localhost:3457",
JobName: "router_test_z1_0",
}
c.OAuth = token_fetcher.OAuthConfig{
TokenEndpoint: "http://localhost",
Port: 8080,
}
c.RouteServiceSecret = "kCvXxNMB0JO2vinxoru9Hg=="
return c
}