forked from TrueCloudLab/frostfs-sdk-go
76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package object_test
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"errors"
|
|
"testing"
|
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
"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
|
|
}
|
|
|
|
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
|
|
}
|