-
Notifications
You must be signed in to change notification settings - Fork 5
/
route_test.go
85 lines (79 loc) · 2.03 KB
/
route_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
/*
Copyright 2017 Ernest Micklei
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
DelayServiceResponse
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"io/ioutil"
"os"
"path"
"testing"
)
var routesData = `
[
{
"label": "oracle",
"service-hostname": "some-host-name",
"service-port": 1521,
"listen-port": 49997,
"transport": {
"throttle-service-response": 1,
"delay-service-response": 1,
"break-service-response": 1,
"sending-to-client": true,
"receiving-from-client": true,
"sending-to-service": true,
"receiving-from-service": true,
"verbose": false
}
}
]
`
func TestReadRoutes(t *testing.T) {
dir := os.TempDir()
loc := path.Join(dir, "routes.json")
err := ioutil.WriteFile(loc, []byte(routesData), 0666)
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir) // clean up
rs, err := readRoutes(loc)
if err != nil {
t.Fatal(err)
}
if got, want := len(rs), 1; got != want {
t.Errorf("got %v want %v", got, want)
}
for _, each := range rs {
if len(each.Label) == 0 {
t.Error("missing Label")
}
if len(each.ServiceHostname) == 0 {
t.Error("missing ServiceHostname")
}
if each.ServicePort == 0 {
t.Error("missing ServicePort")
}
if each.ListenPort == 0 {
t.Error("missing ListenPort")
}
if each.Transport.DelayServiceResponse == 0 {
t.Error("missing DelayServiceResponse")
}
if each.Transport.BreakServiceResponse == 0 {
t.Error("missing BreakServiceRespone")
}
if each.Transport.ThrottleServiceResponse == 0 {
t.Error("missing ThrottleServiceResponse")
}
}
}