-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig_test.go
118 lines (113 loc) · 2.78 KB
/
config_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
117
118
package gtm_test
import (
"strings"
"testing"
. "github.com/datianshi/simple-cf-gtm"
. "github.com/onsi/gomega"
"github.com/sclevine/spec"
)
func testConfig(t *testing.T, when spec.G, it spec.S) {
var configString string
var err error
var config *Config
when("Given a valid config string", func() {
it.Before(func() {
configString = `
{
"domains": [
{
"name" : ".xip.io",
"records": [
{
"name": "*.xip.io.",
"ips": [
{
"address": "192.168.0.2"
},
{
"address": "192.168.0.3"
}
],
"ttl" : 5
}
]
}
],
"port" : 5050,
"relay_server" : "8.8.8.8:53"
}
`
config, err = ParseConfig(strings.NewReader(configString))
})
it("Should not have err happen", func() {
Ω(err).ShouldNot(HaveOccurred())
})
it("Should have a valid domain config", func() {
Ω(len(config.Domains)).Should(Equal(1))
})
it("The port should be 5050", func() {
Ω(config.Port).Should(Equal(5050))
})
it("The domain ttl should be 5", func() {
Ω(config.Domains[0].Records[0].TTL).Should(Equal(5))
})
it("The domain's name should be .xip.io", func() {
Ω(config.Domains[0].DomainName).Should(Equal(".xip.io"))
})
it("The domain have two ips", func() {
Ω(len(config.Domains[0].Records[0].IPs)).Should(Equal(2))
})
it("The first ip is 192.168.0.2", func() {
Ω(config.Domains[0].Records[0].IPs[0].Address).Should(Equal("192.168.0.2"))
})
it("Relay Server should be 8.8.8.8:53", func() {
Ω(config.RelayServer).Should(Equal("8.8.8.8:53"))
})
when("When there is no health check config", func() {
it("Domain 1 record should have dummy health check", func() {
Ω(config.Domains[0].Records[0].HealthCheck).ShouldNot(BeNil())
})
})
})
when("When there is health check config", func() {
it.Before(func() {
configString = `
{
"domains": [
{
"name" : ".xip.io",
"records": [
{
"name" : "*.xip.io",
"ips": [
{
"address": "192.168.0.2"
},
{
"address": "192.168.0.3"
}
],
"ttl" : 5,
"health_check" : {
"type": "layer4",
"port": 5000,
"frequency": "5s"
}
}
]
}
],
"port" : 5050,
"relay_server" : "8.8.8.8:53"
}
`
config, err = ParseConfig(strings.NewReader(configString))
})
it("error should be nil", func() {
Ω(err).ShouldNot(HaveOccurred())
})
it("Domain 0 should have a health check function", func() {
Ω(config.Domains[0].Records[0].HealthCheck).ShouldNot(BeNil())
})
})
}