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:
@@ -56,19 +56,19 @@ func TestSiteOrder(t *testing.T) {
|
||||
|
||||
func TestFmtStatus(t *testing.T) {
|
||||
tests := []struct {
|
||||
status string
|
||||
status models.Status
|
||||
paused bool
|
||||
inMaint bool
|
||||
wantSub string
|
||||
}{
|
||||
{"DOWN", false, false, "▼ DOWN"},
|
||||
{"UP", false, false, "▲ UP"},
|
||||
{"SSL EXP", false, false, "▼ SSL EXP"},
|
||||
{"LATE", false, false, "◆ LATE"},
|
||||
{"STALE", false, false, "◆ STALE"},
|
||||
{"PENDING", false, false, "○ PENDING"},
|
||||
{"DOWN", true, false, "◇ PAUSED"},
|
||||
{"DOWN", false, true, "◼ MAINT"},
|
||||
{models.StatusDown, false, false, "▼ DOWN"},
|
||||
{models.StatusUp, false, false, "▲ UP"},
|
||||
{models.StatusSSLExp, false, false, "▼ SSL EXP"},
|
||||
{models.StatusLate, false, false, "◆ LATE"},
|
||||
{models.StatusStale, false, false, "◆ STALE"},
|
||||
{models.StatusPending, false, false, "○ PENDING"},
|
||||
{models.StatusDown, true, false, "◇ PAUSED"},
|
||||
{models.StatusDown, false, true, "◼ MAINT"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
got := styledModel.fmtStatus(tt.status, tt.paused, tt.inMaint)
|
||||
|
||||
Reference in New Issue
Block a user