[#190] sdk/object: Implement AddParentIDFilter method on SearchFilters
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
3fb3cfd1a5
commit
e4111ff3e7
2 changed files with 32 additions and 0 deletions
|
@ -234,3 +234,7 @@ func (f *SearchFilters) AddChildfreeFilter() {
|
||||||
func (f *SearchFilters) AddNonChildfreeFilter() {
|
func (f *SearchFilters) AddNonChildfreeFilter() {
|
||||||
f.addChildFreeFilter(false)
|
f.addChildFreeFilter(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *SearchFilters) AddParentIDFilter(m SearchMatchType, id *ID) {
|
||||||
|
f.addReservedFilter(m, fKeyParent, id)
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package object_test
|
package object_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/sha256"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
"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.FilterPropertyLeaf, f.Header())
|
||||||
require.Equal(t, v2object.BooleanPropertyValueFalse, f.Value())
|
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())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue