From b10fd9aea3b169d60f9815d5baba6da7393c44ca Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 10 Jul 2022 15:22:49 +0100 Subject: [PATCH] model/labels: add a basic test for ScratchBuilder Signed-off-by: Bryan Boreham --- model/labels/labels_test.go | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/model/labels/labels_test.go b/model/labels/labels_test.go index 96b6ff9bcf..3a1732d22a 100644 --- a/model/labels/labels_test.go +++ b/model/labels/labels_test.go @@ -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) { lbls := FromStrings("foo", "bar", "baz", "qux") require.Equal(t, lbls.Hash(), lbls.Hash())