[#164] sdk/object: Define filters to search virtual objects

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-30 18:57:39 +03:00 committed by Leonard Lyubich
parent 09e6093e64
commit f3bddc2ba5
3 changed files with 51 additions and 0 deletions

View file

@ -110,3 +110,15 @@ func (f *SearchFilters) AddRootFilter() {
func (f *SearchFilters) AddNonRootFilter() {
f.addRootFilter(ValNonRoot)
}
func (f *SearchFilters) addLeafFilter(val string) {
f.AddFilter(KeyLeaf, val, MatchStringEqual)
}
func (f *SearchFilters) AddLeafFilter() {
f.addLeafFilter(ValLeaf)
}
func (f *SearchFilters) AddNonLeafFilter() {
f.addLeafFilter(ValNonLeaf)
}

View file

@ -79,3 +79,31 @@ func TestSearchFilters_AddNonRootFilter(t *testing.T) {
require.Equal(t, object.KeyRoot, f.Header())
require.Equal(t, object.ValNonRoot, f.Value())
}
func TestSearchFilters_AddLeafFilter(t *testing.T) {
fs := new(object.SearchFilters)
fs.AddLeafFilter()
require.Len(t, *fs, 1)
f := (*fs)[0]
require.Equal(t, object.MatchStringEqual, f.Operation())
require.Equal(t, object.KeyLeaf, f.Header())
require.Equal(t, object.ValLeaf, f.Value())
}
func TestSearchFilters_AddNonLeafFilter(t *testing.T) {
fs := new(object.SearchFilters)
fs.AddNonLeafFilter()
require.Len(t, *fs, 1)
f := (*fs)[0]
require.Equal(t, object.MatchStringEqual, f.Operation())
require.Equal(t, object.KeyLeaf, f.Header())
require.Equal(t, object.ValNonLeaf, f.Value())
}

View file

@ -18,3 +18,14 @@ const (
// ValNonRoot is a value of non-root object filter.
ValNonRoot = valFalse
)
const (
// KeyLeaf is a reserved search filter key to physically stored objects.
KeyLeaf = ReservedFilterPrefix + "LEAF"
// ValLeaf is a value of physically stored object filter.
ValLeaf = valTrue
// ValNonLeaf is a value of virtual object filter.
ValNonLeaf = valFalse
)