From 20ede88fe753526b49dd0aae9ef68b4b9d344087 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Fri, 20 Nov 2020 09:55:15 +0300 Subject: [PATCH] [#204] sdk/object: Add SearchFilters method to filter by object ID Signed-off-by: Leonard Lyubich --- pkg/object/search.go | 5 +++++ pkg/object/search_test.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/pkg/object/search.go b/pkg/object/search.go index b9383e2f..6c596d62 100644 --- a/pkg/object/search.go +++ b/pkg/object/search.go @@ -242,3 +242,8 @@ func (f *SearchFilters) AddNonChildfreeFilter() { func (f *SearchFilters) AddParentIDFilter(m SearchMatchType, id *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) +} diff --git a/pkg/object/search_test.go b/pkg/object/search_test.go index ca28f1fe..b3407cc8 100644 --- a/pkg/object/search_test.go +++ b/pkg/object/search_test.go @@ -106,3 +106,20 @@ func TestSearchFilters_AddParentIDFilter(t *testing.T) { require.Equal(t, par.String(), fsV2[0].GetValue()) 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()) + }) +}