[#331] pkg/object: Add COMMON_PREFIX matchtype enum constant and test case for it

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-08-16 14:59:21 +03:00 committed by Alex Vanin
parent e6cd9c48ed
commit 4e7a966a49
2 changed files with 15 additions and 8 deletions

View file

@ -18,6 +18,7 @@ const (
MatchStringEqual MatchStringEqual
MatchStringNotEqual MatchStringNotEqual
MatchNotPresent MatchNotPresent
MatchCommonPrefix
) )
func (m SearchMatchType) ToV2() v2object.MatchType { func (m SearchMatchType) ToV2() v2object.MatchType {
@ -28,6 +29,8 @@ func (m SearchMatchType) ToV2() v2object.MatchType {
return v2object.MatchStringNotEqual return v2object.MatchStringNotEqual
case MatchNotPresent: case MatchNotPresent:
return v2object.MatchNotPresent return v2object.MatchNotPresent
case MatchCommonPrefix:
return v2object.MatchCommonPrefix
default: default:
return v2object.MatchUnknown return v2object.MatchUnknown
} }
@ -41,6 +44,8 @@ func SearchMatchFromV2(t v2object.MatchType) (m SearchMatchType) {
m = MatchStringNotEqual m = MatchStringNotEqual
case v2object.MatchNotPresent: case v2object.MatchNotPresent:
m = MatchNotPresent m = MatchNotPresent
case v2object.MatchCommonPrefix:
m = MatchCommonPrefix
default: default:
m = MatchUnknown m = MatchUnknown
} }
@ -54,6 +59,7 @@ func SearchMatchFromV2(t v2object.MatchType) (m SearchMatchType) {
// * MatchStringEqual: STRING_EQUAL; // * MatchStringEqual: STRING_EQUAL;
// * MatchStringNotEqual: STRING_NOT_EQUAL; // * MatchStringNotEqual: STRING_NOT_EQUAL;
// * MatchNotPresent: NOT_PRESENT; // * MatchNotPresent: NOT_PRESENT;
// * MatchCommonPrefix: COMMON_PREFIX;
// * MatchUnknown, default: MATCH_TYPE_UNSPECIFIED. // * MatchUnknown, default: MATCH_TYPE_UNSPECIFIED.
func (m SearchMatchType) String() string { func (m SearchMatchType) String() string {
return m.ToV2().String() return m.ToV2().String()

View file

@ -10,14 +10,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var ( var eqV2Matches = map[object.SearchMatchType]v2object.MatchType{
eqV2Matches = map[object.SearchMatchType]v2object.MatchType{ object.MatchUnknown: v2object.MatchUnknown,
object.MatchUnknown: v2object.MatchUnknown, object.MatchStringEqual: v2object.MatchStringEqual,
object.MatchStringEqual: v2object.MatchStringEqual, object.MatchStringNotEqual: v2object.MatchStringNotEqual,
object.MatchStringNotEqual: v2object.MatchStringNotEqual, object.MatchNotPresent: v2object.MatchNotPresent,
object.MatchNotPresent: v2object.MatchNotPresent, object.MatchCommonPrefix: v2object.MatchCommonPrefix,
} }
)
func TestMatch(t *testing.T) { func TestMatch(t *testing.T) {
t.Run("known matches", func(t *testing.T) { t.Run("known matches", func(t *testing.T) {
@ -181,6 +180,7 @@ func TestSearchFiltersEncoding(t *testing.T) {
fs := object.NewSearchFilters() fs := object.NewSearchFilters()
fs.AddFilter("key 1", "value 2", object.MatchStringEqual) fs.AddFilter("key 1", "value 2", object.MatchStringEqual)
fs.AddFilter("key 2", "value 2", object.MatchStringNotEqual) fs.AddFilter("key 2", "value 2", object.MatchStringNotEqual)
fs.AddFilter("key 2", "value 2", object.MatchCommonPrefix)
t.Run("json", func(t *testing.T) { t.Run("json", func(t *testing.T) {
data, err := fs.MarshalJSON() data, err := fs.MarshalJSON()
@ -199,6 +199,7 @@ func TestSearchMatchType_String(t *testing.T) {
} }
testEnumStrings(t, new(object.SearchMatchType), []enumStringItem{ testEnumStrings(t, new(object.SearchMatchType), []enumStringItem{
{val: toPtr(object.MatchCommonPrefix), str: "COMMON_PREFIX"},
{val: toPtr(object.MatchStringEqual), str: "STRING_EQUAL"}, {val: toPtr(object.MatchStringEqual), str: "STRING_EQUAL"},
{val: toPtr(object.MatchStringNotEqual), str: "STRING_NOT_EQUAL"}, {val: toPtr(object.MatchStringNotEqual), str: "STRING_NOT_EQUAL"},
{val: toPtr(object.MatchNotPresent), str: "NOT_PRESENT"}, {val: toPtr(object.MatchNotPresent), str: "NOT_PRESENT"},