From 33644a85dff22c9e505491c50ea916f4b38dfb01 Mon Sep 17 00:00:00 2001 From: Jose Donizetti Date: Sat, 11 Nov 2017 12:12:03 -0200 Subject: [PATCH] Add tests to template package (#1086) --- template/template_test.go | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 template/template_test.go diff --git a/template/template_test.go b/template/template_test.go new file mode 100644 index 00000000..8d512ee4 --- /dev/null +++ b/template/template_test.go @@ -0,0 +1,75 @@ +package template + +import ( + "github.com/prometheus/common/model" + "github.com/stretchr/testify/require" + "testing" +) + +func TestPairNames(t *testing.T) { + pairs := Pairs{ + {"name1", "value1"}, + {"name2", "value2"}, + {"name3", "value3"}, + } + + expected := []string{"name1", "name2", "name3"} + require.EqualValues(t, expected, pairs.Names()) +} + +func TestPairValues(t *testing.T) { + pairs := Pairs{ + {"name1", "value1"}, + {"name2", "value2"}, + {"name3", "value3"}, + } + + expected := []string{"value1", "value2", "value3"} + require.EqualValues(t, expected, pairs.Values()) +} + +func TestKVRemove(t *testing.T) { + kv := KV{ + "key1": "val1", + "key2": "val2", + "key3": "val3", + "key4": "val4", + } + + kv = kv.Remove([]string{"key2", "key4"}) + + expected := []string{"key1", "key3"} + require.EqualValues(t, expected, kv.Names()) +} + +func TestAlertsFiring(t *testing.T) { + alerts := Alerts{ + {Status: string(model.AlertFiring)}, + {Status: string(model.AlertResolved)}, + {Status: string(model.AlertFiring)}, + {Status: string(model.AlertResolved)}, + {Status: string(model.AlertResolved)}, + } + + for _, alert := range alerts.Firing() { + if alert.Status != string(model.AlertFiring) { + t.Errorf("unexpected status %q", alert.Status) + } + } +} + +func TestAlertsResolved(t *testing.T) { + alerts := Alerts{ + {Status: string(model.AlertFiring)}, + {Status: string(model.AlertResolved)}, + {Status: string(model.AlertFiring)}, + {Status: string(model.AlertResolved)}, + {Status: string(model.AlertResolved)}, + } + + for _, alert := range alerts.Resolved() { + if alert.Status != string(model.AlertResolved) { + t.Errorf("unexpected status %q", alert.Status) + } + } +}