frostfs-sdk-go/netmap/netmap_test.go
Anton Nikiforov 224e921447
Some checks failed
DCO / DCO (pull_request) Successful in 32s
Code generation / Generate proto (pull_request) Successful in 35s
Tests and linters / Tests (pull_request) Successful in 45s
Tests and linters / Lint (pull_request) Failing after 1m13s
[#344] netmap: Add method Clone
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2025-03-07 14:01:30 +03:00

59 lines
1.2 KiB
Go

package netmap_test
import (
"testing"
v2netmap "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/netmap"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
netmaptest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap/test"
"github.com/stretchr/testify/require"
)
func TestNetMapNodes(t *testing.T) {
var nm netmap.NetMap
require.Empty(t, nm.Nodes())
nodes := []netmap.NodeInfo{netmaptest.NodeInfo(), netmaptest.NodeInfo()}
nm.SetNodes(nodes)
require.ElementsMatch(t, nodes, nm.Nodes())
nodesV2 := make([]v2netmap.NodeInfo, len(nodes))
for i := range nodes {
nodes[i].WriteToV2(&nodesV2[i])
}
var m v2netmap.NetMap
nm.WriteToV2(&m)
require.ElementsMatch(t, nodesV2, m.Nodes())
}
func TestNetMap_SetEpoch(t *testing.T) {
var nm netmap.NetMap
require.Zero(t, nm.Epoch())
const e = 158
nm.SetEpoch(e)
require.EqualValues(t, e, nm.Epoch())
var m v2netmap.NetMap
nm.WriteToV2(&m)
require.EqualValues(t, e, m.Epoch())
}
func TestNetMap_Clone(t *testing.T) {
nm := new(netmap.NetMap)
nm.SetEpoch(1)
var ni netmap.NodeInfo
nm.SetNodes([]netmap.NodeInfo{ni})
c := nm.Clone()
require.True(t, c != nm)
require.True(t, &(c.Nodes()[0]) != &(nm.Nodes()[0]))
}