refactor(models): typed Status constants with IsBroken() predicate

Replace ~150 bare status string comparisons with typed models.Status
constants (StatusUp, StatusDown, StatusPending, StatusLate, StatusStale,
StatusSSLExp). Single IsBroken() method replaces the duplicated
isBroken lambda in monitor.go and isDown function in sla.go.

Adding a new status value (e.g. DEGRADED) now requires one constant
definition instead of grep-and-pray across 16 files.

CheckResult.Status stays string — the checker is the boundary between
raw protocol results and typed status. Cast happens at the edge in
handleStatusChange.
This commit is contained in:
2026-06-11 15:56:51 -04:00
parent c3ae0bd80a
commit f00acbc280
16 changed files with 152 additions and 137 deletions
+13 -13
View File
@@ -137,24 +137,24 @@ func TestComputeDailyBreakdown(t *testing.T) {
}
}
func TestIsDown(t *testing.T) {
if !isDown("DOWN") {
t.Error("DOWN should be down")
func TestIsBroken(t *testing.T) {
if !models.StatusDown.IsBroken() {
t.Error("DOWN should be broken")
}
if !isDown("SSL EXP") {
t.Error("SSL EXP should be down")
if !models.StatusSSLExp.IsBroken() {
t.Error("SSL EXP should be broken")
}
if isDown("UP") {
t.Error("UP should not be down")
if models.StatusUp.IsBroken() {
t.Error("UP should not be broken")
}
if isDown("LATE") {
t.Error("LATE should not be down")
if models.StatusLate.IsBroken() {
t.Error("LATE should not be broken")
}
if isDown("STALE") {
t.Error("STALE should not be down")
if models.StatusStale.IsBroken() {
t.Error("STALE should not be broken")
}
if isDown("PENDING") {
t.Error("PENDING should not be down")
if models.StatusPending.IsBroken() {
t.Error("PENDING should not be broken")
}
}