From c3e1835dd64ecd395b718c92cadf120f09c5e333 Mon Sep 17 00:00:00 2001 From: Sergey Khokhlov Date: Thu, 18 May 2023 01:45:18 +0300 Subject: [PATCH] fix(alerting): Unable to set maintenance interval to all day (#475) --- config/maintenance/maintenance.go | 2 +- config/maintenance/maintenance_test.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config/maintenance/maintenance.go b/config/maintenance/maintenance.go index fe721477..dc66fefe 100644 --- a/config/maintenance/maintenance.go +++ b/config/maintenance/maintenance.go @@ -82,7 +82,7 @@ func (c *Config) ValidateAndSetDefaults() error { if err != nil { return err } - if c.Duration <= 0 || c.Duration >= 24*time.Hour { + if c.Duration <= 0 || c.Duration > 24*time.Hour { return errInvalidMaintenanceDuration } return nil diff --git a/config/maintenance/maintenance_test.go b/config/maintenance/maintenance_test.go index 7f97734e..76ef9eb2 100644 --- a/config/maintenance/maintenance_test.go +++ b/config/maintenance/maintenance_test.go @@ -211,6 +211,14 @@ func TestConfig_IsUnderMaintenance(t *testing.T) { }, expected: true, }, + { + name: "under-maintenance-starting-22h-ago-for-24h", + cfg: &Config{ + Start: fmt.Sprintf("%02d:00", normalizeHour(now.Hour()-22)), + Duration: 24 * time.Hour, + }, + expected: true, + }, { name: "under-maintenance-starting-4h-ago-for-3h", cfg: &Config{ @@ -236,6 +244,15 @@ func TestConfig_IsUnderMaintenance(t *testing.T) { }, expected: false, }, + { + name: "not-under-maintenance-today-with-24h-duration", + cfg: &Config{ + Start: fmt.Sprintf("%02d:00", now.Hour()), + Duration: 24 * time.Hour, + Every: []string{now.Add(48 * time.Hour).Weekday().String()}, + }, + expected: false, + }, } for _, scenario := range scenarios { t.Run(scenario.name, func(t *testing.T) {