fix(alerting): Unable to set maintenance interval to all day (#475)

This commit is contained in:
Sergey Khokhlov 2023-05-18 01:45:18 +03:00 committed by GitHub
parent 2a45a151da
commit c3e1835dd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -82,7 +82,7 @@ func (c *Config) ValidateAndSetDefaults() error {
if err != nil { if err != nil {
return err return err
} }
if c.Duration <= 0 || c.Duration >= 24*time.Hour { if c.Duration <= 0 || c.Duration > 24*time.Hour {
return errInvalidMaintenanceDuration return errInvalidMaintenanceDuration
} }
return nil return nil

View File

@ -211,6 +211,14 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
}, },
expected: true, 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", name: "under-maintenance-starting-4h-ago-for-3h",
cfg: &Config{ cfg: &Config{
@ -236,6 +244,15 @@ func TestConfig_IsUnderMaintenance(t *testing.T) {
}, },
expected: false, 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 { for _, scenario := range scenarios {
t.Run(scenario.name, func(t *testing.T) { t.Run(scenario.name, func(t *testing.T) {