frostfs-sdk-go/object/error_test.go
Anton Nikiforov 20ab57bf7e
All checks were successful
DCO / DCO (pull_request) Successful in 1m3s
Tests and linters / Tests (1.21) (pull_request) Successful in 1m15s
Tests and linters / Tests (1.20) (pull_request) Successful in 1m27s
Tests and linters / Lint (pull_request) Successful in 2m13s
[#214] object: Implement Get\Head requests for EC object
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2024-04-24 11:07:26 +03:00

76 lines
1.5 KiB
Go

package object_test
import (
"crypto/rand"
"errors"
"testing"
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/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
}