mirror of
https://github.com/prometheus/alertmanager
synced 2025-02-16 18:47:10 +00:00
Add SortedPairs test (#1102)
This commit is contained in:
parent
fd0ace8d88
commit
4763f67e4f
@ -1,9 +1,10 @@
|
|||||||
package template
|
package template
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPairNames(t *testing.T) {
|
func TestPairNames(t *testing.T) {
|
||||||
@ -28,6 +29,37 @@ func TestPairValues(t *testing.T) {
|
|||||||
require.EqualValues(t, expected, pairs.Values())
|
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) {
|
func TestKVRemove(t *testing.T) {
|
||||||
kv := KV{
|
kv := KV{
|
||||||
"key1": "val1",
|
"key1": "val1",
|
||||||
|
Loading…
Reference in New Issue
Block a user