forked from TrueCloudLab/frostfs-api-go
[#293] pkg/storagegroup: Implement and use generator of StorageGroup
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
cd32722d25
commit
318755e9de
2 changed files with 25 additions and 22 deletions
|
@ -1,29 +1,16 @@
|
||||||
package storagegroup_test
|
package storagegroup_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"crypto/sha256"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||||
objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test"
|
objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/storagegroup"
|
"github.com/nspcc-dev/neofs-api-go/pkg/storagegroup"
|
||||||
|
storagegrouptest "github.com/nspcc-dev/neofs-api-go/pkg/storagegroup/test"
|
||||||
|
refstest "github.com/nspcc-dev/neofs-api-go/pkg/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testSHA256() (cs [sha256.Size]byte) {
|
|
||||||
_, _ = rand.Read(cs[:])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func testChecksum() *pkg.Checksum {
|
|
||||||
h := pkg.NewChecksum()
|
|
||||||
h.SetSHA256(testSHA256())
|
|
||||||
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStorageGroup(t *testing.T) {
|
func TestStorageGroup(t *testing.T) {
|
||||||
sg := storagegroup.New()
|
sg := storagegroup.New()
|
||||||
|
|
||||||
|
@ -31,7 +18,7 @@ func TestStorageGroup(t *testing.T) {
|
||||||
sg.SetValidationDataSize(sz)
|
sg.SetValidationDataSize(sz)
|
||||||
require.Equal(t, sz, sg.ValidationDataSize())
|
require.Equal(t, sz, sg.ValidationDataSize())
|
||||||
|
|
||||||
cs := testChecksum()
|
cs := refstest.Checksum()
|
||||||
sg.SetValidationDataHash(cs)
|
sg.SetValidationDataHash(cs)
|
||||||
require.Equal(t, cs, sg.ValidationDataHash())
|
require.Equal(t, cs, sg.ValidationDataHash())
|
||||||
|
|
||||||
|
@ -39,17 +26,13 @@ func TestStorageGroup(t *testing.T) {
|
||||||
sg.SetExpirationEpoch(exp)
|
sg.SetExpirationEpoch(exp)
|
||||||
require.Equal(t, exp, sg.ExpirationEpoch())
|
require.Equal(t, exp, sg.ExpirationEpoch())
|
||||||
|
|
||||||
members := []*object.ID{objecttest.GenerateID(), objecttest.GenerateID()}
|
members := []*object.ID{objecttest.ID(), objecttest.ID()}
|
||||||
sg.SetMembers(members)
|
sg.SetMembers(members)
|
||||||
require.Equal(t, members, sg.Members())
|
require.Equal(t, members, sg.Members())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStorageGroupEncoding(t *testing.T) {
|
func TestStorageGroupEncoding(t *testing.T) {
|
||||||
sg := storagegroup.New()
|
sg := storagegrouptest.Generate()
|
||||||
sg.SetValidationDataSize(13)
|
|
||||||
sg.SetValidationDataHash(testChecksum())
|
|
||||||
sg.SetExpirationEpoch(33)
|
|
||||||
sg.SetMembers([]*object.ID{objecttest.GenerateID(), objecttest.GenerateID()})
|
|
||||||
|
|
||||||
t.Run("binary", func(t *testing.T) {
|
t.Run("binary", func(t *testing.T) {
|
||||||
data, err := sg.Marshal()
|
data, err := sg.Marshal()
|
||||||
|
|
20
pkg/storagegroup/test/generate.go
Normal file
20
pkg/storagegroup/test/generate.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package storagegrouptest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/object"
|
||||||
|
objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test"
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/storagegroup"
|
||||||
|
refstest "github.com/nspcc-dev/neofs-api-go/pkg/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate returns random storagegroup.StorageGroup.
|
||||||
|
func Generate() *storagegroup.StorageGroup {
|
||||||
|
x := storagegroup.New()
|
||||||
|
|
||||||
|
x.SetExpirationEpoch(66)
|
||||||
|
x.SetValidationDataSize(322)
|
||||||
|
x.SetValidationDataHash(refstest.Checksum())
|
||||||
|
x.SetMembers([]*object.ID{objecttest.ID(), objecttest.ID()})
|
||||||
|
|
||||||
|
return x
|
||||||
|
}
|
Loading…
Reference in a new issue