From b962029031774bb4dc7498711f5b6943e8f1ac22 Mon Sep 17 00:00:00 2001 From: Hu Shuai Date: Sun, 5 Jul 2020 12:17:19 +0800 Subject: [PATCH] Add a unit test for MergeLabels in storage/remote/codec.go. (#7499) This PR is about adding a unit test for MergeLabels in storage/remote/codec.go. Signed-off-by: Hu Shuai --- storage/remote/codec_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/storage/remote/codec_test.go b/storage/remote/codec_test.go index daf4b496d..64736906e 100644 --- a/storage/remote/codec_test.go +++ b/storage/remote/codec_test.go @@ -210,3 +210,22 @@ func TestNegotiateResponseType(t *testing.T) { testutil.NotOk(t, err, "expected error due to not supported requested response types") testutil.Equals(t, "server does not support any of the requested response types: [20]; supported: map[SAMPLES:{} STREAMED_XOR_CHUNKS:{}]", err.Error()) } + +func TestMergeLabels(t *testing.T) { + for _, tc := range []struct { + primary, secondary, expected []prompb.Label + }{ + { + primary: []prompb.Label{{Name: "aaa", Value: "foo"}, {Name: "bbb", Value: "foo"}, {Name: "ddd", Value: "foo"}}, + secondary: []prompb.Label{{Name: "bbb", Value: "bar"}, {Name: "ccc", Value: "bar"}}, + expected: []prompb.Label{{Name: "aaa", Value: "foo"}, {Name: "bbb", Value: "foo"}, {Name: "ccc", Value: "bar"}, {Name: "ddd", Value: "foo"}}, + }, + { + primary: []prompb.Label{{Name: "bbb", Value: "bar"}, {Name: "ccc", Value: "bar"}}, + secondary: []prompb.Label{{Name: "aaa", Value: "foo"}, {Name: "bbb", Value: "foo"}, {Name: "ddd", Value: "foo"}}, + expected: []prompb.Label{{Name: "aaa", Value: "foo"}, {Name: "bbb", Value: "bar"}, {Name: "ccc", Value: "bar"}, {Name: "ddd", Value: "foo"}}, + }, + } { + testutil.Equals(t, tc.expected, MergeLabels(tc.primary, tc.secondary)) + } +}