frostfs-api-go/acl/test/generate.go
Evgenii Stratonikov ec484f2fd2 [#376] acl: Replace slices of pointers with raw structs
```
name                                     old time/op    new time/op    delta
Table_ToGRPCMessage/to_grpc_message-8      2.82µs ± 5%    2.86µs ± 5%     ~     (p=0.395 n=10+8)
Table_ToGRPCMessage/from_grpc_message-8    2.47µs ± 5%    1.08µs ± 6%  -56.16%  (p=0.000 n=9+9)

name                                     old alloc/op   new alloc/op   delta
Table_ToGRPCMessage/to_grpc_message-8      3.31kB ± 0%    3.31kB ± 0%     ~     (all equal)
Table_ToGRPCMessage/from_grpc_message-8    1.82kB ± 0%    1.38kB ± 0%  -24.56%  (p=0.000 n=10+10)

name                                     old allocs/op  new allocs/op  delta
Table_ToGRPCMessage/to_grpc_message-8        46.0 ± 0%      46.0 ± 0%     ~     (all equal)
Table_ToGRPCMessage/from_grpc_message-8      45.0 ± 0%       9.0 ± 0%  -80.00%  (p=0.000 n=10+10)
```

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
2022-03-15 12:19:49 +03:00

131 lines
2.2 KiB
Go

package acltest
import (
"github.com/nspcc-dev/neofs-api-go/v2/acl"
accountingtest "github.com/nspcc-dev/neofs-api-go/v2/refs/test"
)
func GenerateBearerToken(empty bool) *acl.BearerToken {
m := new(acl.BearerToken)
if !empty {
m.SetBody(GenerateBearerTokenBody(false))
}
m.SetSignature(accountingtest.GenerateSignature(empty))
return m
}
func GenerateBearerTokenBody(empty bool) *acl.BearerTokenBody {
m := new(acl.BearerTokenBody)
if !empty {
m.SetOwnerID(accountingtest.GenerateOwnerID(false))
m.SetEACL(GenerateTable(false))
m.SetLifetime(GenerateTokenLifetime(false))
}
return m
}
func GenerateTable(empty bool) *acl.Table {
m := new(acl.Table)
if !empty {
m.SetRecords(GenerateRecords(false))
m.SetContainerID(accountingtest.GenerateContainerID(false))
}
m.SetVersion(accountingtest.GenerateVersion(empty))
return m
}
func GenerateRecords(empty bool) []acl.Record {
var rs []acl.Record
if !empty {
rs = append(rs,
*GenerateRecord(false),
*GenerateRecord(false),
)
}
return rs
}
func GenerateRecord(empty bool) *acl.Record {
m := new(acl.Record)
if !empty {
m.SetAction(acl.ActionAllow)
m.SetOperation(acl.OperationGet)
m.SetFilters(GenerateFilters(false))
m.SetTargets(GenerateTargets(false))
}
return m
}
func GenerateFilters(empty bool) []acl.HeaderFilter {
var fs []acl.HeaderFilter
if !empty {
fs = append(fs,
*GenerateFilter(false),
*GenerateFilter(false),
)
}
return fs
}
func GenerateFilter(empty bool) *acl.HeaderFilter {
m := new(acl.HeaderFilter)
if !empty {
m.SetKey("key")
m.SetValue("val")
m.SetHeaderType(acl.HeaderTypeRequest)
m.SetMatchType(acl.MatchTypeStringEqual)
}
return m
}
func GenerateTargets(empty bool) []acl.Target {
var ts []acl.Target
if !empty {
ts = append(ts,
*GenerateTarget(false),
*GenerateTarget(false),
)
}
return ts
}
func GenerateTarget(empty bool) *acl.Target {
m := new(acl.Target)
if !empty {
m.SetRole(acl.RoleSystem)
m.SetKeys([][]byte{{1}, {2}})
}
return m
}
func GenerateTokenLifetime(empty bool) *acl.TokenLifetime {
m := new(acl.TokenLifetime)
if !empty {
m.SetExp(1)
m.SetIat(2)
m.SetExp(3)
}
return m
}