2020-12-17 14:37:58 +00:00
|
|
|
package storagegroup_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
2021-06-08 08:38:29 +00:00
|
|
|
objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test"
|
2020-12-17 14:37:58 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/storagegroup"
|
2021-06-08 11:40:12 +00:00
|
|
|
storagegrouptest "github.com/nspcc-dev/neofs-api-go/pkg/storagegroup/test"
|
|
|
|
refstest "github.com/nspcc-dev/neofs-api-go/pkg/test"
|
2020-12-17 14:37:58 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStorageGroup(t *testing.T) {
|
|
|
|
sg := storagegroup.New()
|
|
|
|
|
|
|
|
sz := uint64(13)
|
|
|
|
sg.SetValidationDataSize(sz)
|
|
|
|
require.Equal(t, sz, sg.ValidationDataSize())
|
|
|
|
|
2021-06-08 11:40:12 +00:00
|
|
|
cs := refstest.Checksum()
|
2020-12-17 14:37:58 +00:00
|
|
|
sg.SetValidationDataHash(cs)
|
|
|
|
require.Equal(t, cs, sg.ValidationDataHash())
|
|
|
|
|
|
|
|
exp := uint64(33)
|
|
|
|
sg.SetExpirationEpoch(exp)
|
|
|
|
require.Equal(t, exp, sg.ExpirationEpoch())
|
|
|
|
|
2021-06-08 11:40:12 +00:00
|
|
|
members := []*object.ID{objecttest.ID(), objecttest.ID()}
|
2020-12-17 14:37:58 +00:00
|
|
|
sg.SetMembers(members)
|
|
|
|
require.Equal(t, members, sg.Members())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStorageGroupEncoding(t *testing.T) {
|
2021-06-08 11:40:12 +00:00
|
|
|
sg := storagegrouptest.Generate()
|
2020-12-17 14:37:58 +00:00
|
|
|
|
|
|
|
t.Run("binary", func(t *testing.T) {
|
|
|
|
data, err := sg.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
sg2 := storagegroup.New()
|
|
|
|
require.NoError(t, sg2.Unmarshal(data))
|
|
|
|
|
|
|
|
require.Equal(t, sg, sg2)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
|
|
data, err := sg.MarshalJSON()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
sg2 := storagegroup.New()
|
|
|
|
require.NoError(t, sg2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, sg, sg2)
|
|
|
|
})
|
|
|
|
}
|