From 4763f67e4f0400e84c2b8d3782b3297c33588127 Mon Sep 17 00:00:00 2001 From: Jose Donizetti Date: Wed, 15 Nov 2017 17:25:23 -0200 Subject: [PATCH] Add SortedPairs test (#1102) --- template/template_test.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/template/template_test.go b/template/template_test.go index 8d512ee4..a3ae1983 100644 --- a/template/template_test.go +++ b/template/template_test.go @@ -1,9 +1,10 @@ package template import ( + "testing" + "github.com/prometheus/common/model" "github.com/stretchr/testify/require" - "testing" ) func TestPairNames(t *testing.T) { @@ -28,6 +29,37 @@ func TestPairValues(t *testing.T) { require.EqualValues(t, expected, pairs.Values()) } +func TestKVSortedPairs(t *testing.T) { + kv := KV{"d": "dVal", "b": "bVal", "c": "cVal"} + + expectedPairs := Pairs{ + {"b", "bVal"}, + {"c", "cVal"}, + {"d", "dVal"}, + } + + for i, p := range kv.SortedPairs() { + require.EqualValues(t, p.Name, expectedPairs[i].Name) + require.EqualValues(t, p.Value, expectedPairs[i].Value) + } + + // validates alertname always comes first + kv = KV{"d": "dVal", "b": "bVal", "c": "cVal", "alertname": "alert", "a": "aVal"} + + expectedPairs = Pairs{ + {"alertname", "alert"}, + {"a", "aVal"}, + {"b", "bVal"}, + {"c", "cVal"}, + {"d", "dVal"}, + } + + for i, p := range kv.SortedPairs() { + require.EqualValues(t, p.Name, expectedPairs[i].Name) + require.EqualValues(t, p.Value, expectedPairs[i].Value) + } +} + func TestKVRemove(t *testing.T) { kv := KV{ "key1": "val1",