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

Make `Record.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:35:49 +03:00 committed by Leonard Lyubich
parent b81f39368e
commit 18a3c4d54f
2 changed files with 14 additions and 0 deletions

View file

@ -128,7 +128,13 @@ func (r *Record) AddObjectOwnerIDFilter(m Match, id *owner.ID) {
// TODO: add remaining filters after neofs-api#72
// ToV2 converts Record to v2 acl.EACLRecord message.
//
// Nil Record converts to nil.
func (r *Record) ToV2() *v2acl.Record {
if r == nil {
return nil
}
targets := make([]*v2acl.Target, 0, len(r.targets))
for _, target := range r.targets {
targets = append(targets, target.ToV2())

View file

@ -119,3 +119,11 @@ func TestRecordEncoding(t *testing.T) {
require.Equal(t, r, r2)
})
}
func TestRecord_ToV2(t *testing.T) {
t.Run("nil", func(t *testing.T) {
var x *Record
require.Nil(t, x.ToV2())
})
}