@@ -49,6 +49,52 @@ func Test_Checker_Check_Up(t *testing.T) {
49
49
check (t , resp , wants , http .StatusOK )
50
50
}
51
51
52
+ func Test_Checker_Check_Up_BodyCheck (t * testing.T ) {
53
+ mux := http .NewServeMux ()
54
+
55
+ server := httptest .NewServer (mux )
56
+
57
+ checker := NewChecker (fmt .Sprintf ("%s/up/" , server .URL ))
58
+ checker .ExpectedBodyString = "pong"
59
+
60
+ handler := health .NewHandler ()
61
+ handler .AddChecker ("Up" , checker )
62
+
63
+ mux .Handle ("/health/" , handler )
64
+ mux .HandleFunc ("/up/" , func (w http.ResponseWriter , r * http.Request ) {
65
+ fmt .Fprintln (w , "pong" )
66
+ })
67
+
68
+ resp , _ := http .Get (fmt .Sprintf ("%s/health/" , server .URL ))
69
+
70
+ wants := `{"Up":{"code":200,"status":"UP"},"status":"UP"}`
71
+
72
+ check (t , resp , wants , http .StatusOK )
73
+ }
74
+
75
+ func Test_Checker_Check_Down_BodyCheck (t * testing.T ) {
76
+ mux := http .NewServeMux ()
77
+
78
+ server := httptest .NewServer (mux )
79
+
80
+ checker := NewChecker (fmt .Sprintf ("%s/up/" , server .URL ))
81
+ checker .ExpectedBodyString = "pong"
82
+
83
+ handler := health .NewHandler ()
84
+ handler .AddChecker ("Down" , checker )
85
+
86
+ mux .Handle ("/health/" , handler )
87
+ mux .HandleFunc ("/up/" , func (w http.ResponseWriter , r * http.Request ) {
88
+ fmt .Fprintln (w , "fail" )
89
+ })
90
+
91
+ resp , _ := http .Get (fmt .Sprintf ("%s/health/" , server .URL ))
92
+
93
+ wants := `{"Down":{"body":"does not contain: pong","code":200,"status":"DOWN"},"status":"DOWN"}`
94
+
95
+ check (t , resp , wants , http .StatusServiceUnavailable )
96
+ }
97
+
52
98
func Test_Checker_Check_Down (t * testing.T ) {
53
99
mux := http .NewServeMux ()
54
100
@@ -67,7 +113,7 @@ func Test_Checker_Check_Down(t *testing.T) {
67
113
68
114
resp , _ := http .Get (fmt .Sprintf ("%s/health/" , server .URL ))
69
115
70
- wants := `{"Down":{"code":500,"status":"DOWN"},"status":"DOWN"}`
116
+ wants := `{"Down":{"code":500,"expectedCode":200," status":"DOWN"},"status":"DOWN"}`
71
117
72
118
check (t , resp , wants , http .StatusServiceUnavailable )
73
119
}
@@ -86,7 +132,7 @@ func Test_Checker_Check_Down_invalid(t *testing.T) {
86
132
87
133
resp , _ := http .Get (fmt .Sprintf ("%s/health/" , server .URL ))
88
134
89
- wants := `{"Down":{"code":400,"status":"DOWN"},"status":"DOWN"}`
135
+ wants := `{"Down":{"code":400,"error":"Get : unsupported protocol scheme \"\""," status":"DOWN"},"status":"DOWN"}`
90
136
check (t , resp , wants , http .StatusServiceUnavailable )
91
137
}
92
138
0 commit comments