Files
mesh-controller/internal/catalogue/unhealthy_test.go
T
jochen 58889235d1
mesh/merge-gate head 58889235d163 merged into trunk 535c7641ac41 — pass: builds build-agent, mesh-controller → ace, g14, novox, shanks; no bus step; every …
mesh/repo-check head 58889235d163 merged into trunk 535c7641ac41 — pass: its merge-check.sh passed
mesh/delivery delivered
Raise a module's unhealthy urgent when its manifest says why (hq ADR 0355, issue 691)
A broken service people rely on, such as mail, was said only as a warning on
the desktop. A module may now declare unhealthy urgent with what people lose;
the module check refuses it without why or with another severity.
2026-10-14 15:13:57 +02:00

54 lines
2.1 KiB
Go

package catalogue
import (
"strings"
"testing"
)
// A module may declare its unhealthy urgent, with why; the module check refuses it without why and with any
// severity but urgent or warning (novox/hq ADR 0355).
func TestAnUnhealthyDeclaredUrgentIsUrgent(t *testing.T) {
m, err := ParseManifest([]byte(`{"module":"mail","version":"1",` +
`"unhealthy":{"severity":"urgent","why":"mail is refused or stuck for everyone with a mailbox"}}`))
if err != nil {
t.Fatalf("a manifest declaring its unhealthy urgent with why was refused: %v", err)
}
if !m.UnhealthyIsUrgent() {
t.Errorf("a manifest declaring its unhealthy urgent reads as not urgent: %+v", m.Unhealthy)
}
}
func TestAManifestWithoutUnhealthyIsNotUrgent(t *testing.T) {
m, err := ParseManifest([]byte(`{"module":"notes","version":"1"}`))
if err != nil {
t.Fatal(err)
}
if m.UnhealthyIsUrgent() {
t.Errorf("a manifest saying nothing of its unhealthy reads as urgent")
}
warning := Manifest{Module: "notes", Unhealthy: &UnhealthyPolicy{Severity: UnhealthyWarning, Why: "notes wait"}}
if warning.UnhealthyIsUrgent() || len(warning.unhealthyProblems()) != 0 {
t.Errorf("a warning said with why reads as urgent or is refused: %v", warning.unhealthyProblems())
}
}
func TestAnUnhealthyWithoutWhyIsRefused(t *testing.T) {
for _, why := range []string{"", " "} {
if problems := (Manifest{Module: "mail", Unhealthy: &UnhealthyPolicy{Severity: UnhealthyUrgent, Why: why}}).unhealthyProblems(); len(problems) == 0 {
t.Errorf("urgent with why %q was accepted", why)
}
}
if _, err := ParseManifest([]byte(`{"module":"mail","version":"1","unhealthy":{"severity":"urgent"}}`)); err == nil ||
!strings.Contains(err.Error(), "unhealthy says why") {
t.Errorf("a manifest declaring its unhealthy urgent without why parsed: %v", err)
}
}
func TestAnUnhealthySeverityOtherThanUrgentOrWarningIsRefused(t *testing.T) {
if _, err := ParseManifest([]byte(`{"module":"mail","version":"1","unhealthy":{"severity":"loud","why":"mail stops"}}`)); err == nil ||
!strings.Contains(err.Error(), `not "loud"`) {
t.Errorf("a manifest declaring its unhealthy loud parsed: %v", err)
}
}