diff --git a/alert/alert.go b/alert/alert.go index 0d744721..f8cc8fe1 100644 --- a/alert/alert.go +++ b/alert/alert.go @@ -71,6 +71,18 @@ func Notify(channel *Channel) Option { } } +// NotifyChannels appends the given notification channels to the list of +// channels for this alert. +func NotifyChannels(channels ...*Channel) Option { + return func(alert *Alert) { + for _, channel := range channels { + alert.Builder.Notifications = append(alert.Builder.Notifications, sdk.AlertNotification{ + UID: channel.UID, + }) + } + } +} + // NotifyChannel adds a notification for this alert given a channel UID. func NotifyChannel(channelUID string) Option { return func(alert *Alert) { diff --git a/alert/alert_test.go b/alert/alert_test.go index 7a3639e9..6085a488 100644 --- a/alert/alert_test.go +++ b/alert/alert_test.go @@ -35,6 +35,19 @@ func TestNotificationCanBeSet(t *testing.T) { req.Empty(a.Builder.Notifications[0].ID) } +func TestNotificationCanBeSetInBulk(t *testing.T) { + req := require.New(t) + channel := &Channel{ID: 1, UID: "channel"} + otherChannel := &Channel{ID: 2, UID: "other-channel"} + + a := New("", NotifyChannels(channel, otherChannel)) + + req.Len(a.Builder.Notifications, 2) + req.ElementsMatch([]string{"channel", "other-channel"}, []string{a.Builder.Notifications[0].UID, a.Builder.Notifications[1].UID}) + req.Empty(a.Builder.Notifications[0].ID) + req.Empty(a.Builder.Notifications[1].ID) +} + func TestNotificationCanBeSetByChannelID(t *testing.T) { req := require.New(t)