Anton Nikiforov
112a7c690f
All checks were successful
DCO action / DCO (pull_request) Successful in 1m44s
Vulncheck / Vulncheck (pull_request) Successful in 3m3s
Build / Build Components (1.21) (pull_request) Successful in 4m0s
Build / Build Components (1.22) (pull_request) Successful in 3m57s
Tests and linters / Staticcheck (pull_request) Successful in 4m46s
Tests and linters / gopls check (pull_request) Successful in 4m48s
Tests and linters / Lint (pull_request) Successful in 5m45s
Tests and linters / Tests (1.21) (pull_request) Successful in 8m57s
Tests and linters / Tests with -race (pull_request) Successful in 9m10s
Tests and linters / Tests (1.22) (pull_request) Successful in 9m20s
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
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
|
|
}
|