test: Add edge case tests for ClearActiveAlerts and sanitizeAlertKey

- TestClearActiveAlertsEmptyMaps: tests early return when both maps empty
- sanitizeAlertKey: test for input with only slashes/backslashes -> root

Coverage improvement:
- sanitizeAlertKey: 96.4% → 100%
- alerts package: 52.8%
This commit is contained in:
rcourtman 2025-12-01 16:15:50 +00:00
parent 6e779742d8
commit 876d81ea12
2 changed files with 26 additions and 0 deletions

View file

@ -4121,3 +4121,24 @@ func TestUnacknowledgeAlertSuccess(t *testing.T) {
t.Error("expected ackState entry to be deleted")
}
}
func TestClearActiveAlertsEmptyMaps(t *testing.T) {
t.Parallel()
m := NewManager()
// Ensure maps are empty initially
if len(m.activeAlerts) != 0 {
t.Fatalf("expected activeAlerts to be empty, got %d", len(m.activeAlerts))
}
if len(m.pendingAlerts) != 0 {
t.Fatalf("expected pendingAlerts to be empty, got %d", len(m.pendingAlerts))
}
// Call ClearActiveAlerts on empty manager - should return early without panic
m.ClearActiveAlerts()
// Verify maps are still empty (function returned early)
if len(m.activeAlerts) != 0 {
t.Errorf("expected activeAlerts to remain empty, got %d", len(m.activeAlerts))
}
}

View file

@ -96,6 +96,11 @@ func TestSanitizeAlertKey(t *testing.T) {
},
// Edge cases
{
name: "only slashes and backslashes becomes root",
input: "//\\\\",
want: "root",
},
{
name: "only special chars becomes disk",
input: "@#$%",