[#288] pkg/eacl: Convert nil eACL target to nil API v2 message

Make `Target.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:31:30 +03:00 committed by Leonard Lyubich
parent 8f27d857fa
commit 5844096017
2 changed files with 14 additions and 0 deletions

View file

@ -108,7 +108,13 @@ func (t Target) Role() Role {
}
// ToV2 converts Target to v2 acl.EACLRecord.Target message.
//
// Nil Target converts to nil.
func (t *Target) ToV2() *v2acl.Target {
if t == nil {
return nil
}
target := new(v2acl.Target)
target.SetRole(t.role.ToV2())

View file

@ -61,3 +61,11 @@ func TestTargetEncoding(t *testing.T) {
require.Equal(t, tar, tar2)
})
}
func TestTarget_ToV2(t *testing.T) {
t.Run("nil", func(t *testing.T) {
var x *Target
require.Nil(t, x.ToV2())
})
}