2020-12-02 10:10:43 +00:00
|
|
|
package object_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2021-06-08 16:27:53 +00:00
|
|
|
objv2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
2020-12-02 10:10:43 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSplitInfo(t *testing.T) {
|
|
|
|
s := object.NewSplitInfo()
|
|
|
|
splitID := object.NewSplitID()
|
|
|
|
lastPart := generateID()
|
|
|
|
link := generateID()
|
|
|
|
|
|
|
|
s.SetSplitID(splitID)
|
|
|
|
require.Equal(t, splitID, s.SplitID())
|
|
|
|
|
|
|
|
s.SetLastPart(lastPart)
|
|
|
|
require.Equal(t, lastPart, s.LastPart())
|
|
|
|
|
|
|
|
s.SetLink(link)
|
|
|
|
require.Equal(t, link, s.Link())
|
|
|
|
|
|
|
|
t.Run("to and from v2", func(t *testing.T) {
|
|
|
|
v2 := s.ToV2()
|
|
|
|
newS := object.NewSplitInfoFromV2(v2)
|
|
|
|
|
|
|
|
require.Equal(t, s, newS)
|
|
|
|
})
|
2020-12-02 13:57:06 +00:00
|
|
|
|
|
|
|
t.Run("marshal and unmarshal", func(t *testing.T) {
|
|
|
|
data, err := s.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
newS := object.NewSplitInfo()
|
|
|
|
|
|
|
|
err = newS.Unmarshal(data)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, s, newS)
|
|
|
|
})
|
2020-12-02 10:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func generateID() *object.ID {
|
|
|
|
var buf [32]byte
|
|
|
|
_, _ = rand.Read(buf[:])
|
|
|
|
|
|
|
|
id := object.NewID()
|
|
|
|
id.SetSHA256(buf)
|
|
|
|
|
|
|
|
return id
|
|
|
|
}
|
2021-06-08 16:27:53 +00:00
|
|
|
|
|
|
|
func TestNewSplitInfoFromV2(t *testing.T) {
|
|
|
|
t.Run("from nil", func(t *testing.T) {
|
|
|
|
var x *objv2.SplitInfo
|
|
|
|
|
|
|
|
require.Nil(t, object.NewSplitInfoFromV2(x))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSplitInfo_ToV2(t *testing.T) {
|
|
|
|
t.Run("nil", func(t *testing.T) {
|
|
|
|
var x *object.SplitInfo
|
|
|
|
|
|
|
|
require.Nil(t, x.ToV2())
|
|
|
|
})
|
|
|
|
}
|