forked from cloudfoundry/switchboard
/
main_suite_test.go
116 lines (97 loc) · 2.82 KB
/
main_suite_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main_test
import (
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"testing"
"github.com/cloudfoundry-incubator/candiedyaml"
"github.com/cloudfoundry-incubator/switchboard/config"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
)
const (
switchboardPackage = "github.com/cloudfoundry-incubator/switchboard/"
)
func TestSwitchboard(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Switchboard Executable Suite")
}
var switchboardBinPath string
var switchboardPort uint
var switchboardAPIPort uint
var switchboardProfilerPort uint
var switchboardHealthPort uint
var backends []config.Backend
var configPath string
var rootConfig config.Config
var proxyConfig config.Proxy
var apiConfig config.API
var pidFile string
var staticDir string
var _ = BeforeSuite(func() {
var err error
switchboardBinPath, err = gexec.Build(switchboardPackage, "-race")
Expect(err).NotTo(HaveOccurred())
tempDir, err := ioutil.TempDir(os.TempDir(), "switchboard")
Expect(err).NotTo(HaveOccurred())
pidFile = filepath.Join(tempDir, "switchboard.pid")
configPath = filepath.Join(tempDir, "proxyConfig.yml")
testDir := getDirOfCurrentFile()
staticDir = filepath.Join(testDir, "static")
})
func initConfig() {
switchboardPort = uint(39900 + GinkgoParallelNode())
switchboardAPIPort = uint(39000 + GinkgoParallelNode())
switchboardProfilerPort = uint(6060 + GinkgoParallelNode())
switchboardHealthPort = uint(6160 + GinkgoParallelNode())
backend1 := config.Backend{
Host: "localhost",
Port: uint(45000 + GinkgoParallelNode()),
StatusPort: uint(45500 + GinkgoParallelNode()),
StatusEndpoint: "galera_healthcheck",
Name: "backend-0",
}
backend2 := config.Backend{
Host: "localhost",
Port: uint(46000 + GinkgoParallelNode()),
StatusPort: uint(46500 + GinkgoParallelNode()),
StatusEndpoint: "galera_healthcheck",
Name: "backend-1",
}
backends = []config.Backend{backend1, backend2}
proxyConfig = config.Proxy{
Backends: backends,
HealthcheckTimeoutMillis: 500,
Port: switchboardPort,
}
apiConfig = config.API{
Port: switchboardAPIPort,
Username: "username",
Password: "password",
}
rootConfig = config.Config{
Proxy: proxyConfig,
API: apiConfig,
ProfilerPort: switchboardProfilerPort,
HealthPort: switchboardHealthPort,
PidFile: pidFile,
StaticDir: staticDir,
}
}
func writeConfig() {
fileToWrite, err := os.Create(configPath)
Ω(err).ShouldNot(HaveOccurred())
encoder := candiedyaml.NewEncoder(fileToWrite)
err = encoder.Encode(rootConfig)
Ω(err).ShouldNot(HaveOccurred())
}
func getDirOfCurrentFile() string {
_, filename, _, _ := runtime.Caller(1)
return path.Dir(filename)
}
var _ = AfterSuite(func() {
gexec.CleanupBuildArtifacts()
})