From 5591c58b48c2f182fae0a128911eb1768fc1b1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Sun, 27 Oct 2019 00:07:49 +0100 Subject: [PATCH] fix(tests): add more dedup tests --- internal/alertmanager/dedup_test.go | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/internal/alertmanager/dedup_test.go b/internal/alertmanager/dedup_test.go index 77a9f470ef..91145d49db 100644 --- a/internal/alertmanager/dedup_test.go +++ b/internal/alertmanager/dedup_test.go @@ -90,6 +90,19 @@ func TestDedupAlertsWithoutLabels(t *testing.T) { } } +func TestDedupSilences(t *testing.T) { + os.Setenv("ALERTMANAGER_URI", "http://localhost") + config.Config.Read() + if err := pullAlerts(); err != nil { + t.Error(err) + } + silences := alertmanager.DedupSilences() + expected := 72 + if len(silences) != expected { + t.Errorf("Expected %d silences keys, got %d", expected, len(silences)) + } +} + func TestDedupAutocomplete(t *testing.T) { if err := pullAlerts(); err != nil { t.Error(err) @@ -121,6 +134,32 @@ func TestDedupColors(t *testing.T) { } } +func TestDedupKnownLabels(t *testing.T) { + os.Setenv("ALERTMANAGER_URI", "http://localhost") + config.Config.Read() + if err := pullAlerts(); err != nil { + t.Error(err) + } + labels := alertmanager.DedupKnownLabels() + expected := 6 + if len(labels) != expected { + t.Errorf("Expected %d knownLabels keys, got %d", expected, len(labels)) + } +} + +func TestDedupKnownLabelValues(t *testing.T) { + os.Setenv("ALERTMANAGER_URI", "http://localhost") + config.Config.Read() + if err := pullAlerts(); err != nil { + t.Error(err) + } + values := alertmanager.DedupKnownLabelValues("alertname") + expected := 4 + if len(values) != expected { + t.Errorf("Expected %d knownLabelValues keys, got %d", expected, len(values)) + } +} + func TestStripReceivers(t *testing.T) { os.Setenv("RECEIVERS_STRIP", "by-name by-cluster-service") os.Setenv("ALERTMANAGER_URI", "http://localhost")