From a1ca958f13f6d14294203fa5cc01159e7f23f4b9 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sat, 13 Apr 2024 09:51:51 +0100 Subject: [PATCH] LabelSet: add unit test for String method Signed-off-by: Bryan Boreham --- model/labelset_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/model/labelset_test.go b/model/labelset_test.go index 785886ce..033dcf36 100644 --- a/model/labelset_test.go +++ b/model/labelset_test.go @@ -123,6 +123,38 @@ func TestLabelSetMerge(t *testing.T) { } } +func TestLabelSet_String(t *testing.T) { + tests := []struct { + input LabelSet + want string + }{ + { + input: nil, + want: `{}`, + }, { + input: LabelSet{ + "foo": "bar", + }, + want: `{foo="bar"}`, + }, { + input: LabelSet{ + "foo": "bar", + "foo2": "bar", + "abc": "prometheus", + "foo11": "bar11", + }, + want: `{abc="prometheus", foo="bar", foo11="bar11", foo2="bar"}`, + }, + } + for _, tt := range tests { + t.Run("test", func(t *testing.T) { + if got := tt.input.String(); got != tt.want { + t.Errorf("LabelSet.String() = %v, want %v", got, tt.want) + } + }) + } +} + // Benchmark Results for LabelSet's String() method // --------------------------------------------------------------------------------------------------------- // goos: linux