mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
model/labels: add a basic test for ScratchBuilder
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
cbf432d2ac
commit
b10fd9aea3
|
@ -596,6 +596,46 @@ func TestBuilder(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestScratchBuilder(t *testing.T) {
|
||||||
|
for i, tcase := range []struct {
|
||||||
|
add []Label
|
||||||
|
want Labels
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
add: []Label{},
|
||||||
|
want: EmptyLabels(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
add: []Label{{"aaa", "111"}},
|
||||||
|
want: FromStrings("aaa", "111"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
add: []Label{{"aaa", "111"}, {"bbb", "222"}, {"ccc", "333"}},
|
||||||
|
want: FromStrings("aaa", "111", "bbb", "222", "ccc", "333"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
add: []Label{{"bbb", "222"}, {"aaa", "111"}, {"ccc", "333"}},
|
||||||
|
want: FromStrings("aaa", "111", "bbb", "222", "ccc", "333"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
add: []Label{{"ddd", "444"}},
|
||||||
|
want: FromStrings("ddd", "444"),
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
overwriteTarget := EmptyLabels()
|
||||||
|
t.Run(fmt.Sprint(i), func(t *testing.T) {
|
||||||
|
b := ScratchBuilder{}
|
||||||
|
for _, lbl := range tcase.add {
|
||||||
|
b.Add(lbl.Name, lbl.Value)
|
||||||
|
}
|
||||||
|
b.Sort()
|
||||||
|
require.Equal(t, tcase.want, b.Labels())
|
||||||
|
b.Overwrite(&overwriteTarget)
|
||||||
|
require.Equal(t, tcase.want, overwriteTarget)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLabels_Hash(t *testing.T) {
|
func TestLabels_Hash(t *testing.T) {
|
||||||
lbls := FromStrings("foo", "bar", "baz", "qux")
|
lbls := FromStrings("foo", "bar", "baz", "qux")
|
||||||
require.Equal(t, lbls.Hash(), lbls.Hash())
|
require.Equal(t, lbls.Hash(), lbls.Hash())
|
||||||
|
|
Loading…
Reference in a new issue