Files
ITWorx-Pulse-Public/internal/service/health_test.go
T
ITWorx Pulse release export bd774932d5
Public source validation / validate (push) Failing after 3m8s
Publish ITWorx Pulse source
2026-09-03 02:09:19 +02:00

42 lines
963 B
Go

package service
import (
"io"
"net/http"
"net/http/httptest"
"testing"
)
func TestHealthMuxExposesTextHealthContracts(t *testing.T) {
server := httptest.NewServer(HealthMux())
defer server.Close()
checks := []struct {
path string
body string
}{
{path: "/healthz", body: "ok\n"},
{path: "/readyz", body: "ready\n"},
}
for _, check := range checks {
response, err := http.Get(server.URL + check.path)
if err != nil {
t.Fatalf("GET %s: %v", check.path, err)
}
if response.StatusCode != http.StatusOK {
t.Errorf("GET %s status = %d, want %d", check.path, response.StatusCode, http.StatusOK)
}
if response.Body == nil {
t.Fatalf("GET %s returned no body", check.path)
}
body, err := io.ReadAll(response.Body)
response.Body.Close()
if err != nil {
t.Fatalf("read GET %s body: %v", check.path, err)
}
if string(body) != check.body {
t.Errorf("GET %s body = %q, want %q", check.path, body, check.body)
}
}
}