[#302] pkg/netmap: Document default values set in NewFilter

Make `filtersFromV2` return `nil` if passed
value is `nil`. Document field values of
instance constructed via `NewFilter`. Assert
the values in corresponding unit test.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 16:53:21 +03:00 committed by Alex Vanin
parent 9a7e120485
commit 44437bf81a
2 changed files with 33 additions and 0 deletions

View file

@ -148,6 +148,13 @@ func (c *Context) matchKeyValue(f *Filter, b *Node) bool {
}
// NewFilter creates and returns new Filter instance.
//
// Defaults:
// - name: "";
// - key: "";
// - value: "";
// - operation: 0;
// - filters: nil.
func NewFilter() *Filter {
return NewFilterFromV2(new(netmap.Filter))
}
@ -217,6 +224,10 @@ func (f *Filter) SetOperation(op Operation) {
}
func filtersFromV2(fs []*netmap.Filter) []*Filter {
if fs == nil {
return nil
}
res := make([]*Filter, 0, len(fs))
for i := range fs {