forked from TrueCloudLab/frostfs-api-go
[#191] pkg/object: Use root
and phy
filters as flags
Inverted values for `root` and `phy` filters now are not supported. Therefore these filters works like flags. It either presented in search query or not. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
91eade02cd
commit
fe48e3ab5b
2 changed files with 17 additions and 46 deletions
|
@ -173,6 +173,13 @@ func (f *SearchFilters) addReservedFilter(op SearchMatchType, keyTyp filterKeyTy
|
||||||
f.addFilter(op, keyTyp, "", val)
|
f.addFilter(op, keyTyp, "", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// addFlagFilters adds filters that works like flags: they don't need to have
|
||||||
|
// specific match type or value. They processed by NeoFS nodes by the fact
|
||||||
|
// of presence in search query. E.g.: PHY, ROOT.
|
||||||
|
func (f *SearchFilters) addFlagFilter(keyTyp filterKeyType) {
|
||||||
|
f.addFilter(MatchUnknown, keyTyp, "", staticStringer(""))
|
||||||
|
}
|
||||||
|
|
||||||
func (f *SearchFilters) AddObjectVersionFilter(op SearchMatchType, v *pkg.Version) {
|
func (f *SearchFilters) AddObjectVersionFilter(op SearchMatchType, v *pkg.Version) {
|
||||||
f.addReservedFilter(op, fKeyVersion, v)
|
f.addReservedFilter(op, fKeyVersion, v)
|
||||||
}
|
}
|
||||||
|
@ -199,28 +206,20 @@ func (f SearchFilters) ToV2() []*v2object.SearchFilter {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *SearchFilters) addRootFilter(val bool) {
|
func (f *SearchFilters) addRootFilter() {
|
||||||
f.addReservedFilter(MatchStringEqual, fKeyPropRoot, boolStringer(val))
|
f.addFlagFilter(fKeyPropRoot)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *SearchFilters) AddRootFilter() {
|
func (f *SearchFilters) AddRootFilter() {
|
||||||
f.addRootFilter(true)
|
f.addRootFilter()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *SearchFilters) AddNonRootFilter() {
|
func (f *SearchFilters) addPhyFilter() {
|
||||||
f.addRootFilter(false)
|
f.addFlagFilter(fKeyPropPhy)
|
||||||
}
|
|
||||||
|
|
||||||
func (f *SearchFilters) addPhyFilter(val bool) {
|
|
||||||
f.addReservedFilter(MatchStringEqual, fKeyPropPhy, boolStringer(val))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *SearchFilters) AddPhyFilter() {
|
func (f *SearchFilters) AddPhyFilter() {
|
||||||
f.addPhyFilter(true)
|
f.addPhyFilter()
|
||||||
}
|
|
||||||
|
|
||||||
func (f *SearchFilters) AddNonPhyFilter() {
|
|
||||||
f.addPhyFilter(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *SearchFilters) addChildFreeFilter(val bool) {
|
func (f *SearchFilters) addChildFreeFilter(val bool) {
|
||||||
|
|
|
@ -62,23 +62,9 @@ func TestSearchFilters_AddRootFilter(t *testing.T) {
|
||||||
|
|
||||||
f := (*fs)[0]
|
f := (*fs)[0]
|
||||||
|
|
||||||
require.Equal(t, object.MatchStringEqual, f.Operation())
|
require.Equal(t, object.MatchUnknown, f.Operation())
|
||||||
require.Equal(t, v2object.FilterPropertyRoot, f.Header())
|
require.Equal(t, v2object.FilterPropertyRoot, f.Header())
|
||||||
require.Equal(t, v2object.BooleanPropertyValueTrue, f.Value())
|
require.Equal(t, "", 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, v2object.FilterPropertyRoot, f.Header())
|
|
||||||
require.Equal(t, v2object.BooleanPropertyValueFalse, f.Value())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSearchFilters_AddPhyFilter(t *testing.T) {
|
func TestSearchFilters_AddPhyFilter(t *testing.T) {
|
||||||
|
@ -90,23 +76,9 @@ func TestSearchFilters_AddPhyFilter(t *testing.T) {
|
||||||
|
|
||||||
f := (*fs)[0]
|
f := (*fs)[0]
|
||||||
|
|
||||||
require.Equal(t, object.MatchStringEqual, f.Operation())
|
require.Equal(t, object.MatchUnknown, f.Operation())
|
||||||
require.Equal(t, v2object.FilterPropertyPhy, f.Header())
|
require.Equal(t, v2object.FilterPropertyPhy, f.Header())
|
||||||
require.Equal(t, v2object.BooleanPropertyValueTrue, f.Value())
|
require.Equal(t, "", f.Value())
|
||||||
}
|
|
||||||
|
|
||||||
func TestSearchFilters_AddNonPhyFilter(t *testing.T) {
|
|
||||||
fs := new(object.SearchFilters)
|
|
||||||
|
|
||||||
fs.AddNonPhyFilter()
|
|
||||||
|
|
||||||
require.Len(t, *fs, 1)
|
|
||||||
|
|
||||||
f := (*fs)[0]
|
|
||||||
|
|
||||||
require.Equal(t, object.MatchStringEqual, f.Operation())
|
|
||||||
require.Equal(t, v2object.FilterPropertyPhy, f.Header())
|
|
||||||
require.Equal(t, v2object.BooleanPropertyValueFalse, f.Value())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testOID() *object.ID {
|
func testOID() *object.ID {
|
||||||
|
|
Loading…
Reference in a new issue