labels: add test for Builder.Range

Including mutating the Builder being Ranged over.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
pull/12145/head
Bryan Boreham 2 years ago
parent 8f6d5dcd45
commit 3c4ab7a069

@ -529,6 +529,11 @@ func TestBuilder(t *testing.T) {
base: FromStrings("aaa", "111"), base: FromStrings("aaa", "111"),
want: FromStrings("aaa", "111"), want: FromStrings("aaa", "111"),
}, },
{
base: FromStrings("aaa", "111", "bbb", "222", "ccc", "333"),
set: []Label{{"aaa", "444"}, {"bbb", "555"}, {"ccc", "666"}},
want: FromStrings("aaa", "444", "bbb", "555", "ccc", "666"),
},
{ {
base: FromStrings("aaa", "111", "bbb", "222", "ccc", "333"), base: FromStrings("aaa", "111", "bbb", "222", "ccc", "333"),
del: []string{"bbb"}, del: []string{"bbb"},
@ -591,7 +596,15 @@ func TestBuilder(t *testing.T) {
b.Keep(tcase.keep...) b.Keep(tcase.keep...)
} }
b.Del(tcase.del...) b.Del(tcase.del...)
require.Equal(t, tcase.want, b.Labels(tcase.base)) require.Equal(t, tcase.want, b.Labels(EmptyLabels()))
// Check what happens when we call Range and mutate the builder.
b.Range(func(l Label) {
if l.Name == "aaa" || l.Name == "bbb" {
b.Del(l.Name)
}
})
require.Equal(t, tcase.want.BytesWithoutLabels(nil, "aaa", "bbb"), b.Labels(tcase.base).Bytes(nil))
}) })
} }
} }

Loading…
Cancel
Save