[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-27 14:25:41 +03:00 committed by Leonard Lyubich
parent 25de451a2f
commit 89cb2f6e71
2 changed files with 14 additions and 0 deletions

View file

@ -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())

View file

@ -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())
})
}