[#344] netmap: Add method Clone

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2025-03-07 13:59:38 +03:00
parent f70c0c9081
commit 749b4e9ab5
6 changed files with 141 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package netmap_test
import (
"bytes"
"testing"
v2netmap "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/netmap"
@ -45,3 +46,28 @@ func TestNetMap_SetEpoch(t *testing.T) {
require.EqualValues(t, e, m.Epoch())
}
func TestNetMap_Clone(t *testing.T) {
nm := new(netmap.NetMap)
nm.SetEpoch(1)
var ni netmap.NodeInfo
ni.SetPublicKey([]byte{1, 2, 3})
nm.SetNodes([]netmap.NodeInfo{ni})
clone := nm.Clone()
require.True(t, clone != nm)
require.True(t, &(clone.Nodes()[0]) != &(nm.Nodes()[0]))
var clonev2 v2netmap.NetMap
clone.WriteToV2(&clonev2)
var bufClone []byte
bufClone = clonev2.StableMarshal(bufClone)
var nmv2 v2netmap.NetMap
nm.WriteToV2(&nmv2)
var bufNM []byte
bufNM = nmv2.StableMarshal(bufNM)
require.True(t, bytes.Equal(bufClone, bufNM))
}