[#204] sdk/object: Add SearchFilters method to filter by object ID

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-20 09:55:15 +03:00 committed by Alex Vanin
parent fe6677f30f
commit 20ede88fe7
2 changed files with 22 additions and 0 deletions

View file

@ -242,3 +242,8 @@ func (f *SearchFilters) AddNonChildfreeFilter() {
func (f *SearchFilters) AddParentIDFilter(m SearchMatchType, id *ID) { func (f *SearchFilters) AddParentIDFilter(m SearchMatchType, id *ID) {
f.addReservedFilter(m, fKeyParent, id) f.addReservedFilter(m, fKeyParent, id)
} }
// AddObjectIDFilter adds filter by object identifier.
func (f *SearchFilters) AddObjectIDFilter(m SearchMatchType, id *ID) {
f.addReservedFilter(m, fKeyObjectID, id)
}

View file

@ -106,3 +106,20 @@ func TestSearchFilters_AddParentIDFilter(t *testing.T) {
require.Equal(t, par.String(), fsV2[0].GetValue()) require.Equal(t, par.String(), fsV2[0].GetValue())
require.Equal(t, v2object.MatchStringEqual, fsV2[0].GetMatchType()) require.Equal(t, v2object.MatchStringEqual, fsV2[0].GetMatchType())
} }
func TestSearchFilters_AddObjectIDFilter(t *testing.T) {
id := testOID()
fs := new(object.SearchFilters)
fs.AddObjectIDFilter(object.MatchStringEqual, id)
t.Run("v2", func(t *testing.T) {
fsV2 := fs.ToV2()
require.Len(t, fsV2, 1)
require.Equal(t, v2object.FilterHeaderObjectID, fsV2[0].GetKey())
require.Equal(t, id.String(), fsV2[0].GetValue())
require.Equal(t, v2object.MatchStringEqual, fsV2[0].GetMatchType())
})
}