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
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/pkg"
|
||||
"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"
|
||||
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"
|
||||
)
|
||||
|
||||
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) {
|
||||
sg := storagegroup.New()
|
||||
|
||||
|
@ -31,7 +18,7 @@ func TestStorageGroup(t *testing.T) {
|
|||
sg.SetValidationDataSize(sz)
|
||||
require.Equal(t, sz, sg.ValidationDataSize())
|
||||
|
||||
cs := testChecksum()
|
||||
cs := refstest.Checksum()
|
||||
sg.SetValidationDataHash(cs)
|
||||
require.Equal(t, cs, sg.ValidationDataHash())
|
||||
|
||||
|
@ -39,17 +26,13 @@ func TestStorageGroup(t *testing.T) {
|
|||
sg.SetExpirationEpoch(exp)
|
||||
require.Equal(t, exp, sg.ExpirationEpoch())
|
||||
|
||||
members := []*object.ID{objecttest.GenerateID(), objecttest.GenerateID()}
|
||||
members := []*object.ID{objecttest.ID(), objecttest.ID()}
|
||||
sg.SetMembers(members)
|
||||
require.Equal(t, members, sg.Members())
|
||||
}
|
||||
|
||||
func TestStorageGroupEncoding(t *testing.T) {
|
||||
sg := storagegroup.New()
|
||||
sg.SetValidationDataSize(13)
|
||||
sg.SetValidationDataHash(testChecksum())
|
||||
sg.SetExpirationEpoch(33)
|
||||
sg.SetMembers([]*object.ID{objecttest.GenerateID(), objecttest.GenerateID()})
|
||||
sg := storagegrouptest.Generate()
|
||||
|
||||
t.Run("binary", func(t *testing.T) {
|
||||
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