From e4111ff3e7a42d61bd0934b78bf9a9cbd4e64015 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 5 Nov 2020 19:31:23 +0300 Subject: [PATCH] [#190] sdk/object: Implement AddParentIDFilter method on SearchFilters Signed-off-by: Leonard Lyubich --- pkg/object/search.go | 4 ++++ pkg/object/search_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/pkg/object/search.go b/pkg/object/search.go index ac83220..23eeb2c 100644 --- a/pkg/object/search.go +++ b/pkg/object/search.go @@ -234,3 +234,7 @@ func (f *SearchFilters) AddChildfreeFilter() { func (f *SearchFilters) AddNonChildfreeFilter() { f.addChildFreeFilter(false) } + +func (f *SearchFilters) AddParentIDFilter(m SearchMatchType, id *ID) { + f.addReservedFilter(m, fKeyParent, id) +} diff --git a/pkg/object/search_test.go b/pkg/object/search_test.go index 8abce4b..e126b5b 100644 --- a/pkg/object/search_test.go +++ b/pkg/object/search_test.go @@ -1,6 +1,8 @@ package object_test import ( + "crypto/rand" + "crypto/sha256" "testing" "github.com/nspcc-dev/neofs-api-go/pkg/object" @@ -106,3 +108,29 @@ func TestSearchFilters_AddNonLeafFilter(t *testing.T) { require.Equal(t, v2object.FilterPropertyLeaf, f.Header()) require.Equal(t, v2object.BooleanPropertyValueFalse, f.Value()) } + +func testOID() *object.ID { + cs := [sha256.Size]byte{} + + rand.Read(cs[:]) + + id := object.NewID() + id.SetSHA256(cs) + + return id +} + +func TestSearchFilters_AddParentIDFilter(t *testing.T) { + par := testOID() + + fs := object.SearchFilters{} + fs.AddParentIDFilter(object.MatchStringEqual, par) + + fsV2 := fs.ToV2() + + require.Len(t, fsV2, 1) + + require.Equal(t, v2object.FilterHeaderParent, fsV2[0].GetKey()) + require.Equal(t, par.String(), fsV2[0].GetValue()) + require.Equal(t, v2object.MatchStringEqual, fsV2[0].GetMatchType()) +}