Files
ktm-booking-bot/backend/cmd/server/health_test.go
Samuel Pua 7cf10b07d4
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit
Feat(ktm-booking): Initial commit
2022-09-27 02:50:07 +08:00

40 lines
815 B
Go

package main
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func TestHealthStatus(t *testing.T) {
handler := http.HandlerFunc(healthHandler)
req, err := http.NewRequest("GET", "/health", nil)
if err != nil {
t.Errorf("Error creating a new request: %v", err)
}
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
if rr.Result().StatusCode != 200 {
t.Errorf("Health did not respond with status-code 200")
}
responseBytes, err := ioutil.ReadAll(rr.Result().Body)
if err != nil {
t.Errorf("Error reading response body: %v", err)
}
var results map[string]any
err = json.Unmarshal(responseBytes, &results)
if err != nil {
t.Errorf("Error decoding response body: %v", err)
}
if results["status"] != "ok" {
t.Errorf("Health status is not ok")
}
}