-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_test.go
47 lines (41 loc) · 1.35 KB
/
report_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
package healthz
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
var livenessAndReadinessReportsTestCases = []struct {
in Health
livenessOut int
readinessOut int
}{
{in: Redundant, livenessOut: http.StatusOK, readinessOut: http.StatusOK},
{in: Normal, livenessOut: http.StatusOK, readinessOut: http.StatusOK},
{in: Unknown, livenessOut: http.StatusOK, readinessOut: http.StatusServiceUnavailable},
{in: Warning, livenessOut: http.StatusOK, readinessOut: http.StatusServiceUnavailable},
{in: Error, livenessOut: http.StatusServiceUnavailable, readinessOut: http.StatusServiceUnavailable},
}
func TestLivenessAndReadinessReports(t *testing.T) {
h := NewHandler("Application V1.0.0", true)
for i, tCase := range livenessAndReadinessReportsTestCases {
h.SetGroupHealth(tCase.in)
{
r := httptest.NewRequest("GET", "http://127.0.0.1/liveness", strings.NewReader(""))
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
if w.Code != tCase.livenessOut {
t.Fatalf("case #%d: unexpected liveness response code: %d", i, w.Code)
}
}
{
r := httptest.NewRequest("GET", "http://127.0.0.1/readiness", strings.NewReader(""))
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
if w.Code != tCase.readinessOut {
t.Fatalf("case #%d: unexpected readiness response code: %d", i, w.Code)
}
}
}
}
//TODO: test reportJSON