Feat(ktm-booking): Initial commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit
Some checks failed
ktm-booking-bot/ktm-booking-bot/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
39
backend/cmd/server/health_test.go
Normal file
39
backend/cmd/server/health_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user