From 4e7a966a49820ddea9e5ae8c8d28e8bf3375b0c7 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Mon, 16 Aug 2021 14:59:21 +0300 Subject: [PATCH] [#331] pkg/object: Add COMMON_PREFIX matchtype enum constant and test case for it Signed-off-by: Pavel Karpy --- pkg/object/search.go | 6 ++++++ pkg/object/search_test.go | 17 +++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/object/search.go b/pkg/object/search.go index 438d0aa..cf703f5 100644 --- a/pkg/object/search.go +++ b/pkg/object/search.go @@ -18,6 +18,7 @@ const ( MatchStringEqual MatchStringNotEqual MatchNotPresent + MatchCommonPrefix ) func (m SearchMatchType) ToV2() v2object.MatchType { @@ -28,6 +29,8 @@ func (m SearchMatchType) ToV2() v2object.MatchType { return v2object.MatchStringNotEqual case MatchNotPresent: return v2object.MatchNotPresent + case MatchCommonPrefix: + return v2object.MatchCommonPrefix default: return v2object.MatchUnknown } @@ -41,6 +44,8 @@ func SearchMatchFromV2(t v2object.MatchType) (m SearchMatchType) { m = MatchStringNotEqual case v2object.MatchNotPresent: m = MatchNotPresent + case v2object.MatchCommonPrefix: + m = MatchCommonPrefix default: m = MatchUnknown } @@ -54,6 +59,7 @@ func SearchMatchFromV2(t v2object.MatchType) (m SearchMatchType) { // * MatchStringEqual: STRING_EQUAL; // * MatchStringNotEqual: STRING_NOT_EQUAL; // * MatchNotPresent: NOT_PRESENT; +// * MatchCommonPrefix: COMMON_PREFIX; // * MatchUnknown, default: MATCH_TYPE_UNSPECIFIED. func (m SearchMatchType) String() string { return m.ToV2().String() diff --git a/pkg/object/search_test.go b/pkg/object/search_test.go index 36870bb..33b52e9 100644 --- a/pkg/object/search_test.go +++ b/pkg/object/search_test.go @@ -10,14 +10,13 @@ import ( "github.com/stretchr/testify/require" ) -var ( - eqV2Matches = map[object.SearchMatchType]v2object.MatchType{ - object.MatchUnknown: v2object.MatchUnknown, - object.MatchStringEqual: v2object.MatchStringEqual, - object.MatchStringNotEqual: v2object.MatchStringNotEqual, - object.MatchNotPresent: v2object.MatchNotPresent, - } -) +var eqV2Matches = map[object.SearchMatchType]v2object.MatchType{ + object.MatchUnknown: v2object.MatchUnknown, + object.MatchStringEqual: v2object.MatchStringEqual, + object.MatchStringNotEqual: v2object.MatchStringNotEqual, + object.MatchNotPresent: v2object.MatchNotPresent, + object.MatchCommonPrefix: v2object.MatchCommonPrefix, +} func TestMatch(t *testing.T) { t.Run("known matches", func(t *testing.T) { @@ -181,6 +180,7 @@ func TestSearchFiltersEncoding(t *testing.T) { fs := object.NewSearchFilters() fs.AddFilter("key 1", "value 2", object.MatchStringEqual) fs.AddFilter("key 2", "value 2", object.MatchStringNotEqual) + fs.AddFilter("key 2", "value 2", object.MatchCommonPrefix) t.Run("json", func(t *testing.T) { data, err := fs.MarshalJSON() @@ -199,6 +199,7 @@ func TestSearchMatchType_String(t *testing.T) { } testEnumStrings(t, new(object.SearchMatchType), []enumStringItem{ + {val: toPtr(object.MatchCommonPrefix), str: "COMMON_PREFIX"}, {val: toPtr(object.MatchStringEqual), str: "STRING_EQUAL"}, {val: toPtr(object.MatchStringNotEqual), str: "STRING_NOT_EQUAL"}, {val: toPtr(object.MatchNotPresent), str: "NOT_PRESENT"},