From 18a3c4d54f0a8300ef4804a9e4f16722f74f800f Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 27 May 2021 14:35:49 +0300 Subject: [PATCH] [#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 --- pkg/acl/eacl/record.go | 6 ++++++ pkg/acl/eacl/record_test.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/acl/eacl/record.go b/pkg/acl/eacl/record.go index 9b9e718..2e0d255 100644 --- a/pkg/acl/eacl/record.go +++ b/pkg/acl/eacl/record.go @@ -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()) diff --git a/pkg/acl/eacl/record_test.go b/pkg/acl/eacl/record_test.go index a22f223..25608be 100644 --- a/pkg/acl/eacl/record_test.go +++ b/pkg/acl/eacl/record_test.go @@ -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()) + }) +}