2021-11-08 10:04:45 +00:00
|
|
|
package object_test
|
|
|
|
|
|
|
|
import (
|
2024-04-22 06:51:20 +00:00
|
|
|
"crypto/rand"
|
2021-11-08 10:04:45 +00:00
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
2024-10-07 14:20:25 +00:00
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
2023-03-07 11:20:03 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2021-11-08 10:04:45 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewSplitInfoError(t *testing.T) {
|
|
|
|
var (
|
|
|
|
si = generateSplitInfo()
|
|
|
|
|
|
|
|
err error = object.NewSplitInfoError(si)
|
|
|
|
expectedErr *object.SplitInfoError
|
|
|
|
)
|
|
|
|
|
|
|
|
require.True(t, errors.As(err, &expectedErr))
|
|
|
|
|
|
|
|
siErr, ok := err.(*object.SplitInfoError)
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, si, siErr.SplitInfo())
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateSplitInfo() *object.SplitInfo {
|
|
|
|
si := object.NewSplitInfo()
|
|
|
|
si.SetSplitID(object.NewSplitID())
|
|
|
|
si.SetLastPart(generateID())
|
|
|
|
si.SetLink(generateID())
|
|
|
|
|
|
|
|
return si
|
|
|
|
}
|
2024-04-22 06:51:20 +00:00
|
|
|
|
|
|
|
func TestNewECInfoError(t *testing.T) {
|
|
|
|
var (
|
|
|
|
ei = generateECInfo()
|
|
|
|
|
|
|
|
err error = object.NewECInfoError(ei)
|
|
|
|
expectedErr *object.ECInfoError
|
|
|
|
)
|
|
|
|
|
|
|
|
require.True(t, errors.As(err, &expectedErr))
|
|
|
|
|
|
|
|
eiErr, ok := err.(*object.ECInfoError)
|
|
|
|
require.True(t, ok)
|
|
|
|
require.Equal(t, ei, eiErr.ECInfo())
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateECInfo() *object.ECInfo {
|
|
|
|
ei := object.NewECInfo()
|
|
|
|
ei.Chunks = append(ei.Chunks, objectV2.ECChunk{
|
|
|
|
ID: generateV2ID(),
|
|
|
|
Index: 0,
|
|
|
|
Total: 2,
|
|
|
|
})
|
|
|
|
ei.Chunks = append(ei.Chunks, objectV2.ECChunk{
|
|
|
|
ID: generateV2ID(),
|
|
|
|
Index: 1,
|
|
|
|
Total: 2,
|
|
|
|
})
|
|
|
|
return ei
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateV2ID() refs.ObjectID {
|
|
|
|
var buf [32]byte
|
|
|
|
_, _ = rand.Read(buf[:])
|
|
|
|
|
|
|
|
var id refs.ObjectID
|
|
|
|
id.SetValue(buf[:])
|
|
|
|
|
|
|
|
return id
|
|
|
|
}
|