Add SortedPairs test (#1102)

This commit is contained in:
Jose Donizetti 2017-11-15 17:25:23 -02:00 committed by stuart nelson
parent fd0ace8d88
commit 4763f67e4f
1 changed files with 33 additions and 1 deletions

View File

@ -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",