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

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

View file

@ -98,3 +98,15 @@ func (f SearchFilters) ToV2() []*v2object.SearchFilter {
return result
}
func (f *SearchFilters) addRootFilter(val string) {
f.AddFilter(KeyRoot, val, MatchStringEqual)
}
func (f *SearchFilters) AddRootFilter() {
f.addRootFilter(ValRoot)
}
func (f *SearchFilters) AddNonRootFilter() {
f.addRootFilter(ValNonRoot)
}

View file

@ -51,3 +51,31 @@ func TestFilter(t *testing.T) {
newFilters := object.NewSearchFiltersFromV2(v2)
require.Equal(t, filters, newFilters)
}
func TestSearchFilters_AddRootFilter(t *testing.T) {
fs := new(object.SearchFilters)
fs.AddRootFilter()
require.Len(t, *fs, 1)
f := (*fs)[0]
require.Equal(t, object.MatchStringEqual, f.Operation())
require.Equal(t, object.KeyRoot, f.Header())
require.Equal(t, object.ValRoot, f.Value())
}
func TestSearchFilters_AddNonRootFilter(t *testing.T) {
fs := new(object.SearchFilters)
fs.AddNonRootFilter()
require.Len(t, *fs, 1)
f := (*fs)[0]
require.Equal(t, object.MatchStringEqual, f.Operation())
require.Equal(t, object.KeyRoot, f.Header())
require.Equal(t, object.ValNonRoot, f.Value())
}

View file

@ -0,0 +1,20 @@
package object
const (
valFalse = "false"
valTrue = "true"
)
// ReservedFilterPrefix is a reserved prefix for system search filter keys.
const ReservedFilterPrefix = "$Object:"
const (
// KeyRoot is a reserved search filter key to source objects.
KeyRoot = ReservedFilterPrefix + "ROOT"
// ValRoot is a value of root object filter.
ValRoot = valTrue
// ValNonRoot is a value of non-root object filter.
ValNonRoot = valFalse
)