forked from TrueCloudLab/frostfs-api-go
[#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:
parent
25de451a2f
commit
89cb2f6e71
2 changed files with 14 additions and 0 deletions
|
@ -66,7 +66,13 @@ func (f Filter) From() FilterHeaderType {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToV2 converts Filter to v2 acl.EACLRecord.Filter message.
|
// ToV2 converts Filter to v2 acl.EACLRecord.Filter message.
|
||||||
|
//
|
||||||
|
// Nil Filter converts to nil.
|
||||||
func (f *Filter) ToV2() *v2acl.HeaderFilter {
|
func (f *Filter) ToV2() *v2acl.HeaderFilter {
|
||||||
|
if f == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
filter := new(v2acl.HeaderFilter)
|
filter := new(v2acl.HeaderFilter)
|
||||||
filter.SetValue(f.value.String())
|
filter.SetValue(f.value.String())
|
||||||
filter.SetKey(f.key.String())
|
filter.SetKey(f.key.String())
|
||||||
|
|
|
@ -59,3 +59,11 @@ func TestFilterEncoding(t *testing.T) {
|
||||||
require.Equal(t, f, d2)
|
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())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue