diff --git a/test/acceptance.go b/test/acceptance.go index 67b1c8bc..7bd4630c 100644 --- a/test/acceptance.go +++ b/test/acceptance.go @@ -36,6 +36,13 @@ type AcceptanceOpts struct { baseTime time.Time } +func (opts *AcceptanceOpts) alertString(a *model.Alert) string { + if a.EndsAt.IsZero() { + return fmt.Sprintf("%s[%v:]", a, opts.relativeTime(a.StartsAt)) + } + return fmt.Sprintf("%s[%v:%v]", a, opts.relativeTime(a.StartsAt), opts.relativeTime(a.EndsAt)) +} + // expandTime returns the absolute time for the relative time // calculated from the test's base time. func (opts *AcceptanceOpts) expandTime(rel float64) time.Time { diff --git a/test/acceptance/inhibit_test.go b/test/acceptance/inhibit_test.go index d92690c0..c0e52960 100644 --- a/test/acceptance/inhibit_test.go +++ b/test/acceptance/inhibit_test.go @@ -52,15 +52,15 @@ inhibit_rules: am.Push(At(2.2), Alert("alertname", "JobDown", "job", "testjob", "zone", "aa")) co.Want(Between(2, 2.5), - Alert("alertname", "test1", "job", "testjob", "zone", "aa"), - Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa"), - Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab"), + Alert("alertname", "test1", "job", "testjob", "zone", "aa").Active(1), + Alert("alertname", "InstanceDown", "job", "testjob", "zone", "aa").Active(1), + Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab").Active(1), ) co.Want(Between(3, 3.5), - Alert("alertname", "test1", "job", "testjob", "zone", "aa"), - Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab"), - Alert("alertname", "JobDown", "job", "testjob", "zone", "aa"), + Alert("alertname", "test1", "job", "testjob", "zone", "aa").Active(1), + Alert("alertname", "InstanceDown", "job", "testjob", "zone", "ab").Active(1), + Alert("alertname", "JobDown", "job", "testjob", "zone", "aa").Active(2.2), ) at.Run() diff --git a/test/collector.go b/test/collector.go index 6f7fb53f..6b9d91c6 100644 --- a/test/collector.go +++ b/test/collector.go @@ -2,7 +2,6 @@ package test import ( "fmt" - "sort" "testing" "time" @@ -29,12 +28,15 @@ func batchesEqual(as, bs model.Alerts, opts *AcceptanceOpts) bool { return false } - // Ensure sorting. - sort.Sort(as) - sort.Sort(bs) - - for i, a := range as { - if !equalAlerts(a, bs[i], opts) { + for _, a := range as { + found := false + for _, b := range bs { + if equalAlerts(a, b, opts) { + found = true + break + } + } + if !found { return false } } @@ -83,7 +85,7 @@ func (c *Collector) check() string { report += fmt.Sprintf("---\n") for _, e := range exp { - report += fmt.Sprintf("- %v\n", e) + report += fmt.Sprintf("- %v\n", c.opts.alertString(e)) } for at, got := range c.collected { @@ -137,7 +139,7 @@ func (c *Collector) check() string { for _, alerts := range col { report += fmt.Sprintf("@ %v\n", at) for _, a := range alerts { - report += fmt.Sprintf("- %v\n", a) + report += fmt.Sprintf("- %v\n", c.opts.alertString(a)) } } }