[#164] sdk/object: Define filters to search root objects
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
9799e5d48c
commit
09e6093e64
3 changed files with 60 additions and 0 deletions
|
@ -98,3 +98,15 @@ func (f SearchFilters) ToV2() []*v2object.SearchFilter {
|
||||||
|
|
||||||
return result
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -51,3 +51,31 @@ func TestFilter(t *testing.T) {
|
||||||
newFilters := object.NewSearchFiltersFromV2(v2)
|
newFilters := object.NewSearchFiltersFromV2(v2)
|
||||||
require.Equal(t, filters, newFilters)
|
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())
|
||||||
|
}
|
||||||
|
|
20
pkg/object/wellknown_filters.go
Normal file
20
pkg/object/wellknown_filters.go
Normal 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
|
||||||
|
)
|
Loading…
Reference in a new issue