From fc4f7429d5c3bcbcacbd0b218dc027e4fe4fb55a Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 27 May 2021 14:48:20 +0300 Subject: [PATCH] [#288] pkg/eacl: Document default values set in NewTable Document field values of instance constructed via `NewTable`. Assert the values in corresponding unit test. Signed-off-by: Leonard Lyubich --- pkg/acl/eacl/table.go | 7 +++++++ pkg/acl/eacl/table_test.go | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/pkg/acl/eacl/table.go b/pkg/acl/eacl/table.go index c348696..d18ab0c 100644 --- a/pkg/acl/eacl/table.go +++ b/pkg/acl/eacl/table.go @@ -100,6 +100,13 @@ func (t *Table) ToV2() *v2acl.Table { } // NewTable creates, initializes and returns blank Table instance. +// +// Defaults: +// - version: pkg.SDKVersion(); +// - container ID: nil; +// - records: nil; +// - session token: nil; +// - signature: nil. func NewTable() *Table { t := new(Table) t.SetVersion(*pkg.SDKVersion()) diff --git a/pkg/acl/eacl/table_test.go b/pkg/acl/eacl/table_test.go index c9fe8d5..393527a 100644 --- a/pkg/acl/eacl/table_test.go +++ b/pkg/acl/eacl/table_test.go @@ -119,4 +119,22 @@ func TestTable_ToV2(t *testing.T) { require.Nil(t, x.ToV2()) }) + + t.Run("default values", func(t *testing.T) { + table := eacl.NewTable() + + // check initial values + require.Equal(t, *pkg.SDKVersion(), table.Version()) + require.Nil(t, table.Records()) + require.Nil(t, table.CID()) + require.Nil(t, table.SessionToken()) + require.Nil(t, table.Signature()) + + // convert to v2 message + tableV2 := table.ToV2() + + require.Equal(t, pkg.SDKVersion().ToV2(), tableV2.GetVersion()) + require.Nil(t, tableV2.GetRecords()) + require.Nil(t, tableV2.GetContainerID()) + }) }