2021-03-12 12:57:23 +00:00
|
|
|
package netmaptest
|
|
|
|
|
|
|
|
import (
|
2023-03-07 10:38:56 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
|
|
|
|
refstest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs/test"
|
|
|
|
sessiontest "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session/test"
|
2021-03-12 12:57:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func GenerateFilter(empty bool) *netmap.Filter {
|
|
|
|
return generateFilter(empty, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateFilter(empty, withSub bool) *netmap.Filter {
|
|
|
|
m := new(netmap.Filter)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetKey("filter key")
|
|
|
|
m.SetValue("filter value")
|
|
|
|
m.SetName("filter name")
|
|
|
|
m.SetOp(1)
|
|
|
|
|
|
|
|
if withSub {
|
2022-03-01 13:41:42 +00:00
|
|
|
m.SetFilters([]netmap.Filter{
|
|
|
|
*generateFilter(empty, false),
|
|
|
|
*generateFilter(empty, false),
|
2021-03-12 12:57:23 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2022-03-01 13:41:42 +00:00
|
|
|
func GenerateFilters(empty bool) []netmap.Filter {
|
|
|
|
var res []netmap.Filter
|
2021-06-11 12:28:09 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if !empty {
|
|
|
|
res = append(res,
|
2022-03-01 13:41:42 +00:00
|
|
|
*GenerateFilter(false),
|
|
|
|
*GenerateFilter(false),
|
2021-03-12 12:57:23 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:28:09 +00:00
|
|
|
return res
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateSelector(empty bool) *netmap.Selector {
|
|
|
|
m := new(netmap.Selector)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetCount(66)
|
|
|
|
m.SetAttribute("selector attribute")
|
|
|
|
m.SetFilter("select filter")
|
|
|
|
m.SetName("select name")
|
|
|
|
m.SetClause(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2022-03-01 13:41:42 +00:00
|
|
|
func GenerateSelectors(empty bool) []netmap.Selector {
|
|
|
|
var res []netmap.Selector
|
2021-06-11 12:28:09 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if !empty {
|
|
|
|
res = append(res,
|
2022-03-01 13:41:42 +00:00
|
|
|
*GenerateSelector(false),
|
|
|
|
*GenerateSelector(false),
|
2021-03-12 12:57:23 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:28:09 +00:00
|
|
|
return res
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateReplica(empty bool) *netmap.Replica {
|
|
|
|
m := new(netmap.Replica)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetCount(42)
|
|
|
|
m.SetSelector("replica selector")
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2022-03-01 13:41:42 +00:00
|
|
|
func GenerateReplicas(empty bool) []netmap.Replica {
|
|
|
|
var res []netmap.Replica
|
2021-06-11 12:28:09 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if !empty {
|
|
|
|
res = append(res,
|
2022-03-01 13:41:42 +00:00
|
|
|
*GenerateReplica(false),
|
|
|
|
*GenerateReplica(false),
|
2021-03-12 12:57:23 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:28:09 +00:00
|
|
|
return res
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GeneratePlacementPolicy(empty bool) *netmap.PlacementPolicy {
|
|
|
|
m := new(netmap.PlacementPolicy)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetContainerBackupFactor(322)
|
2021-06-11 12:28:09 +00:00
|
|
|
m.SetFilters(GenerateFilters(false))
|
|
|
|
m.SetSelectors(GenerateSelectors(false))
|
|
|
|
m.SetReplicas(GenerateReplicas(false))
|
2023-07-19 10:00:26 +00:00
|
|
|
m.SetUnique(true)
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateAttribute(empty bool) *netmap.Attribute {
|
|
|
|
m := new(netmap.Attribute)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetKey("attribute key")
|
|
|
|
m.SetValue("attribute val")
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2022-03-02 07:40:22 +00:00
|
|
|
func GenerateAttributes(empty bool) []netmap.Attribute {
|
|
|
|
var res []netmap.Attribute
|
2021-06-11 12:28:09 +00:00
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
if !empty {
|
|
|
|
res = append(res,
|
2022-03-02 07:40:22 +00:00
|
|
|
*GenerateAttribute(false),
|
|
|
|
*GenerateAttribute(false),
|
2021-03-12 12:57:23 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:28:09 +00:00
|
|
|
return res
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateNodeInfo(empty bool) *netmap.NodeInfo {
|
|
|
|
m := new(netmap.NodeInfo)
|
|
|
|
|
|
|
|
if !empty {
|
2021-06-18 16:08:55 +00:00
|
|
|
m.SetAddresses("node address", "node address 2")
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetPublicKey([]byte{1, 2, 3})
|
|
|
|
m.SetState(33)
|
2021-06-11 12:28:09 +00:00
|
|
|
m.SetAttributes(GenerateAttributes(empty))
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2023-05-03 10:41:27 +00:00
|
|
|
func GenerateLocalNodeInfoRequestBody(_ bool) *netmap.LocalNodeInfoRequestBody {
|
2021-03-12 12:57:23 +00:00
|
|
|
m := new(netmap.LocalNodeInfoRequestBody)
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateLocalNodeInfoRequest(empty bool) *netmap.LocalNodeInfoRequest {
|
|
|
|
m := new(netmap.LocalNodeInfoRequest)
|
|
|
|
|
2021-06-11 12:28:09 +00:00
|
|
|
if !empty {
|
|
|
|
m.SetBody(GenerateLocalNodeInfoRequestBody(false))
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
|
|
|
|
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateLocalNodeInfoResponseBody(empty bool) *netmap.LocalNodeInfoResponseBody {
|
|
|
|
m := new(netmap.LocalNodeInfoResponseBody)
|
|
|
|
|
2021-06-11 12:28:09 +00:00
|
|
|
if !empty {
|
|
|
|
m.SetNodeInfo(GenerateNodeInfo(false))
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetVersion(refstest.GenerateVersion(empty))
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateLocalNodeInfoResponse(empty bool) *netmap.LocalNodeInfoResponse {
|
|
|
|
m := new(netmap.LocalNodeInfoResponse)
|
|
|
|
|
2021-06-11 12:28:09 +00:00
|
|
|
if !empty {
|
|
|
|
m.SetBody(GenerateLocalNodeInfoResponseBody(false))
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
|
|
|
|
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-09-28 08:10:20 +00:00
|
|
|
func GenerateNetworkParameter(empty bool) *netmap.NetworkParameter {
|
|
|
|
m := new(netmap.NetworkParameter)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetKey([]byte("key"))
|
|
|
|
m.SetValue([]byte("value"))
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateNetworkConfig(empty bool) *netmap.NetworkConfig {
|
|
|
|
m := new(netmap.NetworkConfig)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetParameters(
|
2022-03-01 13:41:42 +00:00
|
|
|
*GenerateNetworkParameter(empty),
|
|
|
|
*GenerateNetworkParameter(empty),
|
2021-09-28 08:10:20 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
func GenerateNetworkInfo(empty bool) *netmap.NetworkInfo {
|
|
|
|
m := new(netmap.NetworkInfo)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetMagicNumber(228)
|
|
|
|
m.SetCurrentEpoch(666)
|
2021-09-28 08:10:20 +00:00
|
|
|
m.SetMsPerBlock(5678)
|
|
|
|
m.SetNetworkConfig(GenerateNetworkConfig(empty))
|
2021-03-12 12:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2023-05-03 10:41:27 +00:00
|
|
|
func GenerateNetworkInfoRequestBody(_ bool) *netmap.NetworkInfoRequestBody {
|
2021-03-12 12:57:23 +00:00
|
|
|
m := new(netmap.NetworkInfoRequestBody)
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateNetworkInfoRequest(empty bool) *netmap.NetworkInfoRequest {
|
|
|
|
m := new(netmap.NetworkInfoRequest)
|
|
|
|
|
2021-06-11 12:28:09 +00:00
|
|
|
if !empty {
|
|
|
|
m.SetBody(GenerateNetworkInfoRequestBody(false))
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
|
|
|
|
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateNetworkInfoResponseBody(empty bool) *netmap.NetworkInfoResponseBody {
|
|
|
|
m := new(netmap.NetworkInfoResponseBody)
|
|
|
|
|
2021-06-11 12:28:09 +00:00
|
|
|
if !empty {
|
|
|
|
m.SetNetworkInfo(GenerateNetworkInfo(false))
|
|
|
|
}
|
2021-03-12 12:57:23 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateNetworkInfoResponse(empty bool) *netmap.NetworkInfoResponse {
|
|
|
|
m := new(netmap.NetworkInfoResponse)
|
|
|
|
|
2021-06-11 12:28:09 +00:00
|
|
|
if !empty {
|
|
|
|
m.SetBody(GenerateNetworkInfoResponseBody(false))
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:57:23 +00:00
|
|
|
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
|
|
|
|
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
2022-09-17 09:59:54 +00:00
|
|
|
|
|
|
|
func GenerateNetMap(empty bool) *netmap.NetMap {
|
|
|
|
m := new(netmap.NetMap)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetEpoch(987)
|
|
|
|
m.SetNodes([]netmap.NodeInfo{
|
|
|
|
*GenerateNodeInfo(false),
|
|
|
|
*GenerateNodeInfo(false),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateSnapshotRequestBody(_ bool) *netmap.SnapshotRequestBody {
|
|
|
|
return new(netmap.SnapshotRequestBody)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateSnapshotRequest(empty bool) *netmap.SnapshotRequest {
|
|
|
|
m := new(netmap.SnapshotRequest)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetBody(GenerateSnapshotRequestBody(false))
|
|
|
|
}
|
|
|
|
|
|
|
|
m.SetMetaHeader(sessiontest.GenerateRequestMetaHeader(empty))
|
|
|
|
m.SetVerificationHeader(sessiontest.GenerateRequestVerificationHeader(empty))
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateSnapshotResponseBody(empty bool) *netmap.SnapshotResponseBody {
|
|
|
|
m := new(netmap.SnapshotResponseBody)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetNetMap(GenerateNetMap(false))
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateSnapshotResponse(empty bool) *netmap.SnapshotResponse {
|
|
|
|
m := new(netmap.SnapshotResponse)
|
|
|
|
|
|
|
|
if !empty {
|
|
|
|
m.SetBody(GenerateSnapshotResponseBody(false))
|
|
|
|
}
|
|
|
|
|
|
|
|
m.SetMetaHeader(sessiontest.GenerateResponseMetaHeader(empty))
|
|
|
|
m.SetVerificationHeader(sessiontest.GenerateResponseVerificationHeader(empty))
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|