-
Notifications
You must be signed in to change notification settings - Fork 0
/
probes_test.go
74 lines (53 loc) · 1.24 KB
/
probes_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
package healthz
import (
"net/http"
"net/http/httptest"
"testing"
)
const (
alive = "/healthz/alive"
ready = "/healthz/ready"
)
func TestDefaults(t *testing.T) {
mux := CreateMux()
server := httptest.NewServer(mux)
defer server.Close()
res, err := http.Get(server.URL + alive)
if err != nil {
t.Fatal(err)
}
if res.StatusCode != http.StatusOK {
t.Errorf("expected %v got %v", http.StatusOK, res.StatusCode)
}
res, err = http.Get(server.URL + ready)
if err != nil {
t.Fatal(err)
}
if res.StatusCode != http.StatusOK {
t.Errorf("expected %v got %v", http.StatusOK, res.StatusCode)
}
}
func TestCustomWithFailure(t *testing.T) {
probe := func() bool {
return false
}
LivenessCheck(probe)
ReadinessCheck(probe)
mux := CreateMux()
server := httptest.NewServer(mux)
defer server.Close()
res, err := http.Get(server.URL + alive)
if err != nil {
t.Fatal(err)
}
if res.StatusCode != http.StatusServiceUnavailable {
t.Errorf("expected %v got %v", http.StatusServiceUnavailable, res.StatusCode)
}
res, err = http.Get(server.URL + ready)
if err != nil {
t.Fatal(err)
}
if res.StatusCode != http.StatusServiceUnavailable {
t.Errorf("expected %v got %v", http.StatusServiceUnavailable, res.StatusCode)
}
}