diff --git a/pkg/netmap/filter.go b/pkg/netmap/filter.go index de6c9399..4beb1f55 100644 --- a/pkg/netmap/filter.go +++ b/pkg/netmap/filter.go @@ -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 { diff --git a/pkg/netmap/filter_test.go b/pkg/netmap/filter_test.go index a9eadaa8..c9103e12 100644 --- a/pkg/netmap/filter_test.go +++ b/pkg/netmap/filter_test.go @@ -307,3 +307,25 @@ func TestFilterEncoding(t *testing.T) { require.Equal(t, f, f2) }) } + +func TestNewFilter(t *testing.T) { + t.Run("default values", func(t *testing.T) { + filter := NewFilter() + + // check initial values + require.Empty(t, filter.Name()) + require.Empty(t, filter.Key()) + require.Empty(t, filter.Value()) + require.Zero(t, filter.Operation()) + require.Nil(t, filter.InnerFilters()) + + // convert to v2 message + filterV2 := filter.ToV2() + + require.Empty(t, filterV2.GetName()) + require.Empty(t, filterV2.GetKey()) + require.Empty(t, filterV2.GetValue()) + require.Equal(t, netmap.UnspecifiedOperation, filterV2.GetOp()) + require.Nil(t, filterV2.GetFilters()) + }) +}