-
Notifications
You must be signed in to change notification settings - Fork 10
/
traverse_test.go
98 lines (78 loc) · 3.5 KB
/
traverse_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
package healthchecks
import (
"encoding/json"
"testing"
)
func TestTraverse(t *testing.T) {
traverseResponse := Traverse(testStatusEndpoints, []string{}, "", ABOUT_PROTOCOL_HTTP, "test/about.json", "test/version.txt", emptyCustomData)
testAboutResponse := AboutResponse{}
err := json.Unmarshal([]byte(traverseResponse), &testAboutResponse)
if err != nil {
t.Errorf("Response body is an invalid About format, was: `%s`", traverseResponse)
}
assertEqualAboutData(t, testAboutResponse, emptyCustomData, defaultServiceId)
}
func TestTraverseInvalidDependency(t *testing.T) {
traverseResponse := Traverse(testStatusEndpoints, []string{"something"}, "", ABOUT_PROTOCOL_HTTP, "test/about.json", "test/version.txt", emptyCustomData)
expected := `["CRIT",{"description":"Can't traverse","result":"CRIT","details":"Status path 'something' is not registered"}]`
if traverseResponse != expected {
t.Errorf("Response body should be `%s`, was: `%s`", expected, traverseResponse)
}
}
func TestTraverseInvalidAction(t *testing.T) {
traverseResponse := Traverse(testStatusEndpoints, []string{}, "something", ABOUT_PROTOCOL_HTTP, "test/about.json", "test/version.txt", emptyCustomData)
expected := `["CRIT",{"description":"Unsupported action","result":"CRIT","details":"Unsupported traversal action 'something'"}]`
if traverseResponse != expected {
t.Errorf("Response body should be `%s`, was: `%s`", expected, traverseResponse)
}
}
func TestTraverseNotTraversable(t *testing.T) {
se := []StatusEndpoint{
testStatusEndpointA,
testStatusEndpointB,
testStatusEndpointC,
testStatusEndpointNotTraversable,
}
traverseResponse := Traverse(se, []string{"sss"}, "", ABOUT_PROTOCOL_HTTP, "test/about.json", "test/version.txt", emptyCustomData)
expected := `["CRIT",{"description":"Can't traverse","result":"CRIT","details":"SSS is not traversable"}]`
if traverseResponse != expected {
t.Errorf("Response body should be `%s`, was: `%s`", expected, traverseResponse)
}
}
func TestTraverseMissingTraverseCheck(t *testing.T) {
se := []StatusEndpoint{
testStatusEndpointA,
testStatusEndpointB,
testStatusEndpointC,
testStatusEndpointMissingTraverseChecker,
}
traverseResponse := Traverse(se, []string{"ttt"}, "", ABOUT_PROTOCOL_HTTP, "test/about.json", "test/version.txt", emptyCustomData)
expected := `["CRIT",{"description":"Can't traverse","result":"CRIT","details":"TTT does not have a TraverseCheck() function defined"}]`
if traverseResponse != expected {
t.Errorf("Response body should be `%s`, was: `%s`", expected, traverseResponse)
}
}
func TestTraverseDependencyFound(t *testing.T) {
se := []StatusEndpoint{
testStatusEndpointA,
testStatusEndpointB,
testStatusEndpointTraversable,
}
traverseResponse := Traverse(se, []string{"uuu"}, "", ABOUT_PROTOCOL_HTTP, "test/about.json", "test/version.txt", emptyCustomData)
expected := `{"Name":"UUU","Body":"Hello","Time":1294706395881547000}`
if traverseResponse != expected {
t.Errorf("Response body should be `%s`, was: `%s`", expected, traverseResponse)
}
}
func TestTraverseDependencyFoundWithError(t *testing.T) {
se := []StatusEndpoint{
testStatusEndpointA,
testStatusEndpointB,
testStatusEndpointTraversableError,
}
traverseResponse := Traverse(se, []string{"vvv"}, "", ABOUT_PROTOCOL_HTTP, "test/about.json", "test/version.txt", emptyCustomData)
expected := `["CRIT",{"description":"Traverse","result":"CRIT","details":"Test Error"}]`
if traverseResponse != expected {
t.Errorf("Response body should be `%s`, was: `%s`", expected, traverseResponse)
}
}