fix(monitor): inject time into ComputeDailyBreakdown for testability
CI / test (pull_request) Successful in 2m30s
CI / lint (pull_request) Successful in 56s
CI / vulncheck (pull_request) Successful in 51s

Test failed near midnight when outage events fell in previous day's
bucket. Accept a now parameter instead of calling time.Now() internally.
This commit was merged in pull request #91.
This commit is contained in:
2026-06-04 21:29:03 -04:00
parent 7bff79b09c
commit c471a72ff5
3 changed files with 5 additions and 5 deletions
+3 -2
View File
@@ -118,13 +118,14 @@ func TestComputeSLA_LateNotDown(t *testing.T) {
}
func TestComputeDailyBreakdown(t *testing.T) {
now := time.Now()
// Use a fixed time well past midnight so the outage always falls within today's window.
now := time.Date(2026, 6, 4, 15, 0, 0, 0, time.UTC)
changes := []models.StateChange{
{ToStatus: "UP", ChangedAt: now.Add(-1 * time.Hour)},
{ToStatus: "DOWN", FromStatus: "UP", ChangedAt: now.Add(-2 * time.Hour)},
}
days := ComputeDailyBreakdown(changes, "UP", 7)
days := ComputeDailyBreakdown(changes, "UP", 7, now)
if len(days) != 7 {
t.Fatalf("expected 7 days, got %d", len(days))