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

Document field values of instance constructed via `NewTarget`. 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:34:22 +03:00 committed by Leonard Lyubich
parent 5844096017
commit b81f39368e
2 changed files with 19 additions and 0 deletions

View file

@ -124,6 +124,10 @@ func (t *Target) ToV2() *v2acl.Target {
}
// NewTarget creates, initializes and returns blank Target instance.
//
// Defaults:
// - role: RoleUnknown;
// - keys: nil.
func NewTarget() *Target {
return NewTargetFromV2(new(v2acl.Target))
}

View file

@ -4,6 +4,7 @@ import (
"crypto/ecdsa"
"testing"
"github.com/nspcc-dev/neofs-api-go/v2/acl"
v2acl "github.com/nspcc-dev/neofs-api-go/v2/acl"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-crypto/test"
@ -68,4 +69,18 @@ func TestTarget_ToV2(t *testing.T) {
require.Nil(t, x.ToV2())
})
t.Run("default values", func(t *testing.T) {
target := NewTarget()
// check initial values
require.Equal(t, RoleUnknown, target.Role())
require.Nil(t, target.BinaryKeys())
// convert to v2 message
targetV2 := target.ToV2()
require.Equal(t, acl.RoleUnknown, targetV2.GetRole())
require.Nil(t, targetV2.GetKeys())
})
}