-
Notifications
You must be signed in to change notification settings - Fork 0
/
healthcheck_test.go
143 lines (122 loc) · 3.48 KB
/
healthcheck_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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package tyrgin
import (
"errors"
"fmt"
"testing"
)
var defaultServiceID = "service-id"
var emptyCustomData map[string]interface{}
var testStatusEndpointA = StatusEndpoint{
Name: "AAA",
Slug: "aaa",
Type: "internal",
IsTraversable: true,
StatusCheck: MockStatusChecker{"AAA", OK, "all good"},
TraverseCheck: nil,
}
var testStatusEndpointB = StatusEndpoint{
Name: "BBB",
Slug: "bbb",
Type: "internal",
IsTraversable: true,
StatusCheck: MockStatusChecker{"BBB", OK, "all good"},
TraverseCheck: nil,
}
var testStatusEndpointC = StatusEndpoint{
Name: "CCC",
Slug: "ccc",
Type: "internal",
IsTraversable: true,
StatusCheck: MockStatusChecker{"CCC", OK, "all good"},
TraverseCheck: nil,
}
var testStatusEndpoints = []StatusEndpoint{
testStatusEndpointA,
testStatusEndpointB,
testStatusEndpointC,
}
var testStatusEndpointNotTraversable = StatusEndpoint{
Name: "SSS",
Slug: "sss",
Type: "internal",
IsTraversable: false,
StatusCheck: MockStatusChecker{"SSS", OK, "all good"},
TraverseCheck: nil,
}
var testStatusEndpointMissingTraverseChecker = StatusEndpoint{
Name: "TTT",
Slug: "ttt",
Type: "internal",
IsTraversable: true,
StatusCheck: MockStatusChecker{"TTT", OK, "all good"},
TraverseCheck: nil,
}
var testStatusEndpointTraversable = StatusEndpoint{
Name: "UUU",
Slug: "uuu",
Type: "internal",
IsTraversable: true,
StatusCheck: MockStatusChecker{"UUU", OK, "all good"},
TraverseCheck: MockStatusChecker{"UUU", OK, "all good"},
}
var testStatusEndpointTraversableError = StatusEndpoint{
Name: "VVV",
Slug: "vvv",
Type: "internal",
IsTraversable: true,
StatusCheck: MockStatusChecker{"VVV", OK, "all good"},
TraverseCheck: MockErrorTraverseChecker{"VVV"},
}
type MockStatusChecker struct {
Name string
Result AlertLevel
Details string
}
func (m MockStatusChecker) CheckStatus(name string) StatusList {
return StatusList{
StatusList: []Status{
{
Description: name,
Result: m.Result,
Details: m.Details,
},
},
}
}
type MockErrorTraverseChecker struct {
Name string
}
func (m MockErrorTraverseChecker) Traverse(traversalPath []string, action string) (string, error) {
return fmt.Sprintf(`{"Name":"%s","Body":"Hello","Time":1294706395881547000}`, m.Name), errors.New("Test Error")
}
func (m MockStatusChecker) Traverse(traversalPath []string, action string) (string, error) {
return fmt.Sprintf(`{"Name":"%s","Body":"Hello","Time":1294706395881547000}`, m.Name), nil
}
type MockTraverseChecker struct {
Error error
Response string
}
func (m MockTraverseChecker) Traverse(traversalPath []string, action string) (string, error) {
if m.Error != nil {
return "", m.Error
}
return m.Response, nil
}
func Test_findStatusEndpoint_found(t *testing.T) {
statusEndpoint := FindStatusEndpoint(testStatusEndpoints, "ccc")
if statusEndpoint == nil {
t.Error("StatusEndpoint could not be found but is in the list.")
}
}
func Test_findStatusEndpoint_notFound(t *testing.T) {
statusEndpoint := FindStatusEndpoint(testStatusEndpoints, "zzz")
if statusEndpoint != nil {
t.Error("StatusEndpoint was found but shouldn't have been in the list.")
}
}
func Test_findStatusEndpoint_emptySlug(t *testing.T) {
statusEndpoint := FindStatusEndpoint(testStatusEndpoints, "")
if statusEndpoint != nil {
t.Error("StatusEndpoint was returned for empty argument")
}
}