Skip to content

Commit

Permalink
Update TestTimeMuteStage and TestTimeActiveStage tests
Browse files Browse the repository at this point in the history
This commit updates the TestTimeMuteStage and TestTimeActiveStage
tests as the marker contains the names of all matching active
and mute time intervals.

Signed-off-by: George Robinson <[email protected]>
  • Loading branch information
grobinson-grafana committed Apr 11, 2024
1 parent ac1d714 commit 2021070
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"io"
"reflect"
"sort"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -827,12 +828,6 @@ func TestTimeMuteStage(t *testing.T) {
}
eveningsAndWeekends := map[string][]timeinterval.TimeInterval{
"evenings": {{
Weekdays: []timeinterval.WeekdayRange{{
InclusiveRange: timeinterval.InclusiveRange{
Begin: 1, // Monday
End: 5, // Friday
},
}},
Times: []timeinterval.TimeRange{{
StartMinute: 0, // 00:00
EndMinute: 540, // 09:00
Expand Down Expand Up @@ -877,11 +872,17 @@ func TestTimeMuteStage(t *testing.T) {
alerts: []*types.Alert{{Alert: model.Alert{Labels: model.LabelSet{"foo": "bar"}}}},
mutedBy: []string{"weekends"},
}, {
name: "Should be muted at 12pm UTC",
name: "Should be muted at 12pm UTC on a weekday",
intervals: eveningsAndWeekends,
now: time.Date(2024, 1, 1, 10, 0, 0, 0, time.UTC),
alerts: []*types.Alert{{Alert: model.Alert{Labels: model.LabelSet{"foo": "bar"}}}},
mutedBy: []string{"evenings"},
}, {
name: "Should be muted at 12pm UTC on a weekend",
intervals: eveningsAndWeekends,
now: time.Date(2024, 1, 6, 10, 0, 0, 0, time.UTC),
alerts: []*types.Alert{{Alert: model.Alert{Labels: model.LabelSet{"foo": "bar"}}}},
mutedBy: []string{"weekends"},
mutedBy: []string{"evenings", "weekends"},
}}

for _, test := range tests {
Expand All @@ -897,6 +898,8 @@ func TestTimeMuteStage(t *testing.T) {
for name := range test.intervals {
muteTimeIntervalNames = append(muteTimeIntervalNames, name)
}
// Sort the names so we can compare mutedBy with test.mutedBy.
sort.Strings(muteTimeIntervalNames)

ctx := context.Background()
ctx = WithNow(ctx, test.now)
Expand Down Expand Up @@ -1012,6 +1015,8 @@ func TestTimeActiveStage(t *testing.T) {
for name := range test.intervals {
activeTimeIntervalNames = append(activeTimeIntervalNames, name)
}
// Sort the names so we can compare mutedBy with test.mutedBy.
sort.Strings(activeTimeIntervalNames)

ctx := context.Background()
ctx = WithNow(ctx, test.now)
Expand Down

0 comments on commit 2021070

Please sign in to comment.