mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Prevent simplified routing zero duration GroupInterval and RepeatInterval (#86561)
Prevent zero duration GroupInterval and RepeatInterval
This commit is contained in:
parent
71445002b7
commit
a20197229e
@ -81,11 +81,11 @@ func (s *NotificationSettings) Validate() error {
|
|||||||
if s.GroupWait != nil && *s.GroupWait < 0 {
|
if s.GroupWait != nil && *s.GroupWait < 0 {
|
||||||
return errors.New("group wait must be a positive duration")
|
return errors.New("group wait must be a positive duration")
|
||||||
}
|
}
|
||||||
if s.GroupInterval != nil && *s.GroupInterval < 0 {
|
if s.GroupInterval != nil && *s.GroupInterval <= 0 {
|
||||||
return errors.New("group interval must be a positive duration")
|
return errors.New("group interval must be greater than zero")
|
||||||
}
|
}
|
||||||
if s.RepeatInterval != nil && *s.RepeatInterval < 0 {
|
if s.RepeatInterval != nil && *s.RepeatInterval <= 0 {
|
||||||
return errors.New("repeat interval must be a positive duration")
|
return errors.New("repeat interval must be greater than zero")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,11 @@ func TestValidate(t *testing.T) {
|
|||||||
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithGroupInterval(util.Pointer(-1*time.Second))),
|
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithGroupInterval(util.Pointer(-1*time.Second))),
|
||||||
expErrorContains: "group interval",
|
expErrorContains: "group interval",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "group interval zero is invalid",
|
||||||
|
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithGroupInterval(util.Pointer(0*time.Second))),
|
||||||
|
expErrorContains: "group interval",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "repeat interval empty is valid",
|
name: "repeat interval empty is valid",
|
||||||
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithRepeatInterval(nil)),
|
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithRepeatInterval(nil)),
|
||||||
@ -87,6 +92,11 @@ func TestValidate(t *testing.T) {
|
|||||||
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithRepeatInterval(util.Pointer(-1*time.Second))),
|
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithRepeatInterval(util.Pointer(-1*time.Second))),
|
||||||
expErrorContains: "repeat interval",
|
expErrorContains: "repeat interval",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "repeat interval zero is invalid",
|
||||||
|
notificationSettings: CopyNotificationSettings(validNotificationSettings(), NSMuts.WithRepeatInterval(util.Pointer(0*time.Second))),
|
||||||
|
expErrorContains: "repeat interval",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range testCases {
|
for _, tt := range testCases {
|
||||||
|
Loading…
Reference in New Issue
Block a user