mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-25 07:32:19 +00:00
Add SortedPairs test (#1102)
This commit is contained in:
parent
fd0ace8d88
commit
4763f67e4f
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user