[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-27 14:43:21 +03:00 committed by Leonard Lyubich
parent 8c70b4714e
commit 8abf78009a
2 changed files with 14 additions and 0 deletions

View file

@ -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 {

View file

@ -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())
})
}