[#307] v2/acl/test: Do not allocate memory if !empty
Move all memory allocation and field settings in `Generate...(empty bool)` functions behind `if !empty` check. Do not create empty slices if `empty == true`. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
51f20a76c5
commit
e15dd105fe
1 changed files with 19 additions and 12 deletions
|
@ -8,7 +8,10 @@ import (
|
||||||
func GenerateBearerToken(empty bool) *acl.BearerToken {
|
func GenerateBearerToken(empty bool) *acl.BearerToken {
|
||||||
m := new(acl.BearerToken)
|
m := new(acl.BearerToken)
|
||||||
|
|
||||||
m.SetBody(GenerateBearerTokenBody(empty))
|
if !empty {
|
||||||
|
m.SetBody(GenerateBearerTokenBody(false))
|
||||||
|
}
|
||||||
|
|
||||||
m.SetSignature(accountingtest.GenerateSignature(empty))
|
m.SetSignature(accountingtest.GenerateSignature(empty))
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
@ -17,9 +20,11 @@ func GenerateBearerToken(empty bool) *acl.BearerToken {
|
||||||
func GenerateBearerTokenBody(empty bool) *acl.BearerTokenBody {
|
func GenerateBearerTokenBody(empty bool) *acl.BearerTokenBody {
|
||||||
m := new(acl.BearerTokenBody)
|
m := new(acl.BearerTokenBody)
|
||||||
|
|
||||||
m.SetOwnerID(accountingtest.GenerateOwnerID(empty))
|
if !empty {
|
||||||
m.SetEACL(GenerateTable(empty))
|
m.SetOwnerID(accountingtest.GenerateOwnerID(false))
|
||||||
m.SetLifetime(GenerateTokenLifetime(empty))
|
m.SetEACL(GenerateTable(false))
|
||||||
|
m.SetLifetime(GenerateTokenLifetime(false))
|
||||||
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -27,15 +32,18 @@ func GenerateBearerTokenBody(empty bool) *acl.BearerTokenBody {
|
||||||
func GenerateTable(empty bool) *acl.Table {
|
func GenerateTable(empty bool) *acl.Table {
|
||||||
m := new(acl.Table)
|
m := new(acl.Table)
|
||||||
|
|
||||||
m.SetRecords(GenerateRecords(empty))
|
if !empty {
|
||||||
m.SetContainerID(accountingtest.GenerateContainerID(empty))
|
m.SetRecords(GenerateRecords(false))
|
||||||
|
m.SetContainerID(accountingtest.GenerateContainerID(false))
|
||||||
|
}
|
||||||
|
|
||||||
m.SetVersion(accountingtest.GenerateVersion(empty))
|
m.SetVersion(accountingtest.GenerateVersion(empty))
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateRecords(empty bool) []*acl.Record {
|
func GenerateRecords(empty bool) []*acl.Record {
|
||||||
rs := make([]*acl.Record, 0)
|
var rs []*acl.Record
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
rs = append(rs,
|
rs = append(rs,
|
||||||
|
@ -53,16 +61,15 @@ func GenerateRecord(empty bool) *acl.Record {
|
||||||
if !empty {
|
if !empty {
|
||||||
m.SetAction(acl.ActionAllow)
|
m.SetAction(acl.ActionAllow)
|
||||||
m.SetOperation(acl.OperationGet)
|
m.SetOperation(acl.OperationGet)
|
||||||
|
m.SetFilters(GenerateFilters(false))
|
||||||
|
m.SetTargets(GenerateTargets(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
m.SetFilters(GenerateFilters(empty))
|
|
||||||
m.SetTargets(GenerateTargets(empty))
|
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateFilters(empty bool) []*acl.HeaderFilter {
|
func GenerateFilters(empty bool) []*acl.HeaderFilter {
|
||||||
fs := make([]*acl.HeaderFilter, 0)
|
var fs []*acl.HeaderFilter
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
fs = append(fs,
|
fs = append(fs,
|
||||||
|
@ -88,7 +95,7 @@ func GenerateFilter(empty bool) *acl.HeaderFilter {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateTargets(empty bool) []*acl.Target {
|
func GenerateTargets(empty bool) []*acl.Target {
|
||||||
ts := make([]*acl.Target, 0)
|
var ts []*acl.Target
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
ts = append(ts,
|
ts = append(ts,
|
||||||
|
|
Loading…
Reference in a new issue