-
Notifications
You must be signed in to change notification settings - Fork 4
/
get_test.go
94 lines (75 loc) · 1.91 KB
/
get_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
package main
import (
"testing"
)
func runGetTest(t *testing.T, options getOptions, correctResult string) {
result, err := get(options)
if err != nil {
t.Fatal(err)
}
if result.String() != correctResult {
t.Fatalf("Wanted %s\nGot %s", correctResult, result)
}
}
func TestGetKeySimple(t *testing.T) {
options := getOptions{
json: readTestFile(t, "test.json"),
path: "service.name",
delimiter: ".",
}
runGetTest(t, options, `"redis_mysql"`)
}
func TestGetKeyNestedArray(t *testing.T) {
options := getOptions{
json: readTestFile(t, "test.json"),
path: "service.tags.0",
delimiter: ".",
}
runGetTest(t, options, `"master"`)
options = getOptions{
json: readTestFile(t, "test.json"),
path: "service.checks.0.script",
delimiter: ".",
}
runGetTest(t, options, `"/usr/local/bin/check_redis.py"`)
}
func TestGetKeyValueString(t *testing.T) {
options := getOptions{
json: readTestFile(t, "test.json"),
path: "service.name=redis_mysql",
delimiter: ".",
}
runGetTest(t, options, `"redis_mysql"`)
}
func TestGetKeyValueNumber(t *testing.T) {
options := getOptions{
json: readTestFile(t, "test.json"),
path: "service.port=8000",
delimiter: ".",
}
runGetTest(t, options, "8000")
}
func TestGetHash(t *testing.T) {
options := getOptions{
json: readTestFile(t, "test.json"),
path: "service.foo={}",
delimiter: ".",
}
runGetTest(t, options, `{"bar":"baz"}`)
}
func TestGetGlobArray(t *testing.T) {
options := getOptions{
json: readTestFile(t, "test.json"),
path: "service.checks.*.interval",
delimiter: ".",
}
runGetTest(t, options, `"10s"`)
}
func TestGetGlobArrayValue(t *testing.T) {
options := getOptions{
json: readTestFile(t, "test.json"),
path: "service..checks..*..script=/usr/local/bin/check_mysql.py",
delimiter: "..",
}
runGetTest(t, options, `"/usr/local/bin/check_mysql.py"`)
}