forked from TrueCloudLab/frostfs-api-go
[#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 <leonard@nspcc.ru>
This commit is contained in:
parent
b81f39368e
commit
18a3c4d54f
2 changed files with 14 additions and 0 deletions
|
@ -128,7 +128,13 @@ func (r *Record) AddObjectOwnerIDFilter(m Match, id *owner.ID) {
|
||||||
// TODO: add remaining filters after neofs-api#72
|
// TODO: add remaining filters after neofs-api#72
|
||||||
|
|
||||||
// ToV2 converts Record to v2 acl.EACLRecord message.
|
// ToV2 converts Record to v2 acl.EACLRecord message.
|
||||||
|
//
|
||||||
|
// Nil Record converts to nil.
|
||||||
func (r *Record) ToV2() *v2acl.Record {
|
func (r *Record) ToV2() *v2acl.Record {
|
||||||
|
if r == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
targets := make([]*v2acl.Target, 0, len(r.targets))
|
targets := make([]*v2acl.Target, 0, len(r.targets))
|
||||||
for _, target := range r.targets {
|
for _, target := range r.targets {
|
||||||
targets = append(targets, target.ToV2())
|
targets = append(targets, target.ToV2())
|
||||||
|
|
|
@ -119,3 +119,11 @@ func TestRecordEncoding(t *testing.T) {
|
||||||
require.Equal(t, r, r2)
|
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())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue