diff --git a/pkg/object/search.go b/pkg/object/search.go index ac832208..23eeb2ca 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 8abce4b5..e126b5b0 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()) +}