This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user