frostfs-sdk-go/object/error_test.go
Pavel Pogodaev 6ce73790ea
All checks were successful
DCO / DCO (pull_request) Successful in 38s
Tests and linters / Tests (pull_request) Successful in 1m13s
Tests and linters / Lint (pull_request) Successful in 2m36s
[#276] Merge repo with frostfs-api-go
Signed-off-by: Pavel Pogodaev <p.pogodaev@yadro.com>
2024-10-22 14:05:12 +00:00

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
}