[#288] pkg/eacl: Document default values set in NewFilter

Document field values of instance constructed via `NewFilter`. Assert the
values in corresponding unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-27 14:29:45 +03:00 committed by Leonard Lyubich
parent 89cb2f6e71
commit 8f27d857fa
2 changed files with 25 additions and 0 deletions

View file

@ -108,6 +108,12 @@ func (k filterKey) String() string {
} }
// NewFilter creates, initializes and returns blank Filter instance. // NewFilter creates, initializes and returns blank Filter instance.
//
// Defaults:
// - header type: HeaderTypeUnknown;
// - matcher: MatchUnknown;
// - key: "";
// - value: "".
func NewFilter() *Filter { func NewFilter() *Filter {
return NewFilterFromV2(new(v2acl.HeaderFilter)) return NewFilterFromV2(new(v2acl.HeaderFilter))
} }

View file

@ -3,6 +3,7 @@ package eacl
import ( import (
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/v2/acl"
v2acl "github.com/nspcc-dev/neofs-api-go/v2/acl" v2acl "github.com/nspcc-dev/neofs-api-go/v2/acl"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -66,4 +67,22 @@ func TestFilter_ToV2(t *testing.T) {
require.Nil(t, x.ToV2()) require.Nil(t, x.ToV2())
}) })
t.Run("default values", func(t *testing.T) {
filter := NewFilter()
// check initial values
require.Empty(t, filter.Key())
require.Empty(t, filter.Value())
require.Equal(t, HeaderTypeUnknown, filter.From())
require.Equal(t, MatchUnknown, filter.Matcher())
// convert to v2 message
filterV2 := filter.ToV2()
require.Empty(t, filterV2.GetKey())
require.Empty(t, filterV2.GetValue())
require.Equal(t, acl.HeaderTypeUnknown, filterV2.GetHeaderType())
require.Equal(t, acl.MatchTypeUnknown, filterV2.GetMatchType())
})
} }