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