server: use uppercase per-upstream status in /health; verify in tests

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I26a71054250c71747e92c2803d8c39ed6a6a6964
This commit is contained in:
raf 2026-03-06 22:37:27 +03:00
commit a45ee57da7
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 21 additions and 1 deletions

View file

@ -84,7 +84,7 @@ func (s *Server) handleHealth(w http.ResponseWriter, _ *http.Request) {
for i, h := range sorted {
upstreams[i] = upstreamStatus{
URL: h.URL,
Status: strings.ToLower(h.Status.String()),
Status: h.Status.String(),
LatencyMs: h.EMALatency,
ConsecutiveFails: h.ConsecutiveFails,
}

View file

@ -431,6 +431,26 @@ func TestHealthEndpointDegraded(t *testing.T) {
if len(resp.Upstreams) != 2 {
t.Errorf("upstreams = %d, want 2", len(resp.Upstreams))
}
var foundDegraded bool
for _, u := range resp.Upstreams {
if u.URL == "https://up2.example.com" && u.Status == "DEGRADED" {
foundDegraded = true
}
}
if !foundDegraded {
t.Error("expected up2 to have status DEGRADED")
}
var foundActive bool
for _, u := range resp.Upstreams {
if u.URL == "https://up1.example.com" && u.Status == "ACTIVE" {
foundActive = true
}
}
if !foundActive {
t.Error("expected up1 to have status ACTIVE")
}
}
func TestHealthEndpointAllDown(t *testing.T) {