From 5844096017ffadcf52eedf1475154b7b6ef0b925 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 27 May 2021 14:31:30 +0300 Subject: [PATCH] [#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 --- pkg/acl/eacl/target.go | 6 ++++++ pkg/acl/eacl/target_test.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/acl/eacl/target.go b/pkg/acl/eacl/target.go index b951082e..8574e48a 100644 --- a/pkg/acl/eacl/target.go +++ b/pkg/acl/eacl/target.go @@ -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()) diff --git a/pkg/acl/eacl/target_test.go b/pkg/acl/eacl/target_test.go index 5c33ec75..6612e3ac 100644 --- a/pkg/acl/eacl/target_test.go +++ b/pkg/acl/eacl/target_test.go @@ -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()) + }) +}