You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

39 lines
815 B

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")
}
}