From 89cb2f6e71749aef35a59ac5d9e8f1b04d5748f5 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 27 May 2021 14:25:41 +0300 Subject: [PATCH] [#288] pkg/eacl: Convert nil eACL filter to nil message Make `Filter.ToV2` method to return `nil` when called on `nil`. Write corresponding unit test. Signed-off-by: Leonard Lyubich --- pkg/acl/eacl/filter.go | 6 ++++++ pkg/acl/eacl/filter_test.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/acl/eacl/filter.go b/pkg/acl/eacl/filter.go index d66978b2..3be0bb52 100644 --- a/pkg/acl/eacl/filter.go +++ b/pkg/acl/eacl/filter.go @@ -66,7 +66,13 @@ func (f Filter) From() FilterHeaderType { } // ToV2 converts Filter to v2 acl.EACLRecord.Filter message. +// +// Nil Filter converts to nil. func (f *Filter) ToV2() *v2acl.HeaderFilter { + if f == nil { + return nil + } + filter := new(v2acl.HeaderFilter) filter.SetValue(f.value.String()) filter.SetKey(f.key.String()) diff --git a/pkg/acl/eacl/filter_test.go b/pkg/acl/eacl/filter_test.go index 64636ccd..7918042a 100644 --- a/pkg/acl/eacl/filter_test.go +++ b/pkg/acl/eacl/filter_test.go @@ -59,3 +59,11 @@ func TestFilterEncoding(t *testing.T) { require.Equal(t, f, d2) }) } + +func TestFilter_ToV2(t *testing.T) { + t.Run("nil", func(t *testing.T) { + var x *Filter + + require.Nil(t, x.ToV2()) + }) +}