-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
79 lines (74 loc) · 1.81 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
package main
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestConfigFmt(t *testing.T) {
c := []byte(`
{
"bgp": {
"peers": [
{
"address": "10.88.0.253",
"as": 65512
},
{
"address": "10.88.0.254",
"as": 65512
}
],
"local": {
"routerID": "10.88.0.200",
"as": 65512,
"listenPort": -1
}
},
"service": {
"name": "matchbox",
"ip": "10.88.2.1",
"ports": [
{
"servicePort": 80,
"targetLocalPort": 8080
},
{
"servicePort": 443,
"targetLocalPort": 8081
}
],
"protocol": "tcp",
"httphealthcheck": {
"port": 8080
}
}
}
`)
conf := &config{
Service: serviceConfig{
PrefixLength: 32,
},
}
err := json.Unmarshal(c, conf)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, 2, len(conf.Bgp.Peers))
assert.Equal(t, "10.88.0.253", conf.Bgp.Peers[0].Address)
assert.Equal(t, uint32(65512), conf.Bgp.Peers[0].AS)
assert.Equal(t, "10.88.0.254", conf.Bgp.Peers[1].Address)
assert.Equal(t, uint32(65512), conf.Bgp.Peers[1].AS)
assert.Equal(t, "10.88.0.200", conf.Bgp.Local.RouterId)
assert.Equal(t, uint32(65512), conf.Bgp.Local.AS)
assert.Equal(t, int32(-1), conf.Bgp.Local.ListenPort)
assert.Equal(t, "matchbox", conf.Service.Name)
assert.Equal(t, "10.88.2.1", conf.Service.IP)
assert.Equal(t, 32, conf.Service.PrefixLength)
assert.Equal(t, 2, len(conf.Service.Ports))
assert.Equal(t, uint16(80), conf.Service.Ports[0].ServicePort)
assert.Equal(t, uint16(8080), conf.Service.Ports[0].TargetPort)
assert.Equal(t, uint16(443), conf.Service.Ports[1].ServicePort)
assert.Equal(t, uint16(8081), conf.Service.Ports[1].TargetPort)
assert.Equal(t, "tcp", conf.Service.Protocol)
assert.Equal(t, 8080, conf.Service.HttpHealthCheck.Port)
}