-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain_test.go
43 lines (34 loc) · 1010 Bytes
/
main_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 main
import (
"net/http"
"net/http/httptest"
"testing"
"encoding/json"
)
func TestHealthCheckHandler(t *testing.T){
req, err := http.NewRequest("GET", "/healthcheck", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
handler := http.HandlerFunc(HealthCheckHandler)
handler.ServeHTTP(rr, req)
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
healthStruct := HealthCheckInfo{}
jsonErr := json.Unmarshal(rr.Body.Bytes(), &healthStruct)
if jsonErr != nil {
t.Errorf("Response can't be unmarshalled: %v", rr.Body.String())
}
if healthStruct.MyApplication[0].Description == "" {
t.Errorf("No description in healthcheck.")
}
if healthStruct.MyApplication[0].LastCommitSHA == "" {
t.Errorf("No commit SHA in healthcheck.")
}
if healthStruct.MyApplication[0].Version == "" {
t.Errorf("No version in healthcheck.")
}
}