[#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:
parent
374c37983d
commit
8c70b4714e
1 changed files with 18 additions and 12 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue