[#288] pkg/eacl: Fix conversion of slices in Record.ToV2 method

Nil slices of targets and filters of the `Record` should be converted to nil
slices in corresponding fields of API v2 message structure.

Add nil-check in `Record.ToV2` implementation. The changes fix corresponding
unit test.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-27 14:42:12 +03:00 committed by Leonard Lyubich
parent 374c37983d
commit 8c70b4714e

View file

@ -135,22 +135,28 @@ func (r *Record) ToV2() *v2acl.Record {
return nil return nil
} }
targets := make([]*v2acl.Target, 0, len(r.targets))
for _, target := range r.targets {
targets = append(targets, target.ToV2())
}
filters := make([]*v2acl.HeaderFilter, 0, len(r.filters))
for _, filter := range r.filters {
filters = append(filters, filter.ToV2())
}
v2 := new(v2acl.Record) v2 := new(v2acl.Record)
if r.targets != nil {
targets := make([]*v2acl.Target, 0, len(r.targets))
for _, target := range r.targets {
targets = append(targets, target.ToV2())
}
v2.SetTargets(targets)
}
if r.filters != nil {
filters := make([]*v2acl.HeaderFilter, 0, len(r.filters))
for _, filter := range r.filters {
filters = append(filters, filter.ToV2())
}
v2.SetFilters(filters)
}
v2.SetAction(r.action.ToV2()) v2.SetAction(r.action.ToV2())
v2.SetOperation(r.operation.ToV2()) v2.SetOperation(r.operation.ToV2())
v2.SetTargets(targets)
v2.SetFilters(filters)
return v2 return v2
} }