Files
Gardomatic/internal/api/healthcheck_test.go
T
kleiax 904d14b64c
CI / test (push) Canceled after 0s
Initial commit
2026-09-12 22:22:17 +02:00

31 lines
864 B
Go

package api
import (
"encoding/json"
"net/http/httptest"
"testing"
"time"
)
func TestHealthcheckIncludesServerTimeAndSystemInformation(t *testing.T) {
app := &application{config: Config{Env: "test"}}
request := httptest.NewRequest("GET", "/v1/healthcheck", nil)
response := httptest.NewRecorder()
app.healthcheckHandler(response, request)
var body struct {
Status string `json:"status"`
ServerTime time.Time `json:"server_time"`
SystemInfo struct {
Environment string `json:"environment"`
Version string `json:"version"`
} `json:"system_info"`
}
if err := json.Unmarshal(response.Body.Bytes(), &body); err != nil {
t.Fatal(err)
}
if body.Status != "available" || body.ServerTime.IsZero() || body.SystemInfo.Environment != "test" || body.SystemInfo.Version == "" {
t.Fatalf("unexpected health response: %+v", body)
}
}