package util import ( "crypto/rand" "testing" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "github.com/stretchr/testify/require" ) func TestMergeECInfo(t *testing.T) { id := generateV2ID() target := objectSDK.NewECInfo() var chunk objectSDK.ECChunk chunk.Total = 2 chunk.Index = 0 chunk.SetID(id) target.AddChunk(chunk) t.Run("merge empty", func(t *testing.T) { to := objectSDK.NewECInfo() result := MergeECInfo(target, to) require.Equal(t, result, target) }) t.Run("merge existed", func(t *testing.T) { to := objectSDK.NewECInfo() to.AddChunk(chunk) result := MergeECInfo(target, to) require.Equal(t, result, target) }) t.Run("merge extend", func(t *testing.T) { to := objectSDK.NewECInfo() var chunk objectSDK.ECChunk chunk.Total = 2 chunk.Index = 1 chunk.SetID(generateV2ID()) to.AddChunk(chunk) result := MergeECInfo(target, to) require.Equal(t, len(result.Chunks), 2) }) } func generateV2ID() oid.ID { var buf [32]byte _, _ = rand.Read(buf[:]) var id oid.ID _ = id.Decode(buf[:]) return id }