From 8abf78009a5ac6494195e35389793bae404fad09 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 27 May 2021 14:43:21 +0300 Subject: [PATCH] [#288] pkg/eacl: Convert nil eACL table to nil API v2 message Make `Table.ToV2` method to return `nil` when called on `nil`. Write corresponding unit test. Signed-off-by: Leonard Lyubich --- pkg/acl/eacl/table.go | 6 ++++++ pkg/acl/eacl/table_test.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/acl/eacl/table.go b/pkg/acl/eacl/table.go index 99b6aad..c348696 100644 --- a/pkg/acl/eacl/table.go +++ b/pkg/acl/eacl/table.go @@ -75,7 +75,13 @@ func (t *Table) SetSignature(sig *pkg.Signature) { } // ToV2 converts Table to v2 acl.EACLTable message. +// +// Nil Table converts to nil. func (t *Table) ToV2() *v2acl.Table { + if t == nil { + return nil + } + v2 := new(v2acl.Table) if t.cid != nil { diff --git a/pkg/acl/eacl/table_test.go b/pkg/acl/eacl/table_test.go index ec28efe..c9fe8d5 100644 --- a/pkg/acl/eacl/table_test.go +++ b/pkg/acl/eacl/table_test.go @@ -112,3 +112,11 @@ func TestTable_Signature(t *testing.T) { require.Equal(t, sig, table.Signature()) } + +func TestTable_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *eacl.Table + + require.Nil(t, x.ToV2()) + }) +}