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:
parent
985ed1090a
commit
a45ee57da7
2 changed files with 21 additions and 1 deletions
|
|
@ -84,7 +84,7 @@ func (s *Server) handleHealth(w http.ResponseWriter, _ *http.Request) {
|
||||||
for i, h := range sorted {
|
for i, h := range sorted {
|
||||||
upstreams[i] = upstreamStatus{
|
upstreams[i] = upstreamStatus{
|
||||||
URL: h.URL,
|
URL: h.URL,
|
||||||
Status: strings.ToLower(h.Status.String()),
|
Status: h.Status.String(),
|
||||||
LatencyMs: h.EMALatency,
|
LatencyMs: h.EMALatency,
|
||||||
ConsecutiveFails: h.ConsecutiveFails,
|
ConsecutiveFails: h.ConsecutiveFails,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -431,6 +431,26 @@ func TestHealthEndpointDegraded(t *testing.T) {
|
||||||
if len(resp.Upstreams) != 2 {
|
if len(resp.Upstreams) != 2 {
|
||||||
t.Errorf("upstreams = %d, want 2", len(resp.Upstreams))
|
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) {
|
func TestHealthEndpointAllDown(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue