From 06493b7034e31099246d7ecc9bcde73dedcb383d Mon Sep 17 00:00:00 2001 From: ZouYu Date: Wed, 22 Apr 2020 15:02:47 +0800 Subject: [PATCH] add unit test TestLabels_String for pkg/labels/labels.go (#7150) Signed-off-by: ZouYu --- pkg/labels/labels_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/labels/labels_test.go b/pkg/labels/labels_test.go index cf82a8dde..576a26752 100644 --- a/pkg/labels/labels_test.go +++ b/pkg/labels/labels_test.go @@ -19,6 +19,39 @@ import ( "github.com/prometheus/prometheus/util/testutil" ) +func TestLabels_String(t *testing.T) { + cases := []struct { + lables Labels + expected string + }{ + { + lables: Labels{ + { + Name: "t1", + Value: "t1", + }, + { + Name: "t2", + Value: "t2", + }, + }, + expected: "{t1=\"t1\", t2=\"t2\"}", + }, + { + lables: Labels{}, + expected: "{}", + }, + { + lables: nil, + expected: "{}", + }, + } + for _, c := range cases { + str := c.lables.String() + testutil.Equals(t, c.expected, str) + } +} + func TestLabels_MatchLabels(t *testing.T) { labels := Labels{ {