-
Notifications
You must be signed in to change notification settings - Fork 15
/
health_check_test.go
43 lines (35 loc) · 988 Bytes
/
health_check_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
package parse
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestServerHealthCheckStatusIsOk(t *testing.T) {
setupTestServer(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, `{"status": "ok"}`)
})
defer teardownTestServer()
expected := map[string]interface{}{"status": "ok"}
result, err := ServerHealthCheck()
if err != nil {
t.Error("Error must be nil while server status is ok!")
}
if !reflect.DeepEqual(result, expected) {
t.Errorf("ServerHealthCheck result is not formatted!")
}
}
func TestServerHealthCheckStatusIsNotOk(t *testing.T) {
setupTestServer(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusGatewayTimeout)
fmt.Fprintf(w, "")
})
defer teardownTestServer()
result, err := ServerHealthCheck()
if err == nil {
t.Error("Error must be available while server status is not ok!")
}
if result != nil {
t.Errorf("ServerHealthCheck must return nil as response, while server status is not ok!")
}
}