[#190] sdk/object: Implement AddParentIDFilter method on SearchFilters

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-05 19:31:23 +03:00 committed by Alex Vanin
parent 3fb3cfd1a5
commit e4111ff3e7
2 changed files with 32 additions and 0 deletions

View file

@ -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)
}

View file

@ -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())
}