From b81f39368eda311fbb401bbbe7ceaee7bdc7f601 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 27 May 2021 14:34:22 +0300 Subject: [PATCH] [#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 --- pkg/acl/eacl/target.go | 4 ++++ pkg/acl/eacl/target_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/pkg/acl/eacl/target.go b/pkg/acl/eacl/target.go index 8574e48..22a2af6 100644 --- a/pkg/acl/eacl/target.go +++ b/pkg/acl/eacl/target.go @@ -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)) } diff --git a/pkg/acl/eacl/target_test.go b/pkg/acl/eacl/target_test.go index 6612e3a..5fd0e70 100644 --- a/pkg/acl/eacl/target_test.go +++ b/pkg/acl/eacl/target_test.go @@ -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()) + }) }