From d1d4a854098884fbcfe818cd3859e309d3692616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Thu, 10 Aug 2017 22:22:01 -0700 Subject: [PATCH] Add a test for total number of alerts we get from mock, should be 24 --- internal/alertmanager/dedup_test.go | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/internal/alertmanager/dedup_test.go b/internal/alertmanager/dedup_test.go index 1ed366400..bf8b424ab 100644 --- a/internal/alertmanager/dedup_test.go +++ b/internal/alertmanager/dedup_test.go @@ -35,9 +35,39 @@ func TestDedupAlerts(t *testing.T) { t.Error(err) } alertGroups := alertmanager.DedupAlerts() + if len(alertGroups) != 10 { t.Errorf("Expected %d alert groups, got %d", 10, len(alertGroups)) } + + totalAlerts := 0 + for _, ag := range alertGroups { + totalAlerts += len(ag.Alerts) + } + if totalAlerts != 24 { + t.Errorf("Expected %d total alerts, got %d", 24, totalAlerts) + } +} + +func TestDedupAlertsWithoutLabels(t *testing.T) { + config.Config.KeepLabels = []string{"xyz"} + if err := pullAlerts(); err != nil { + t.Error(err) + } + alertGroups := alertmanager.DedupAlerts() + config.Config.KeepLabels = []string{} + + if len(alertGroups) != 10 { + t.Errorf("Expected %d alert groups, got %d", 10, len(alertGroups)) + } + + totalAlerts := 0 + for _, ag := range alertGroups { + totalAlerts += len(ag.Alerts) + } + if totalAlerts != 24 { + t.Errorf("Expected %d total alerts, got %d", 24, totalAlerts) + } } func TestDedupAutocomplete(t *testing.T) {