diff --git a/pkg/storagegroup/storagegroup_test.go b/pkg/storagegroup/storagegroup_test.go index 8da57850..51184312 100644 --- a/pkg/storagegroup/storagegroup_test.go +++ b/pkg/storagegroup/storagegroup_test.go @@ -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() diff --git a/pkg/storagegroup/test/generate.go b/pkg/storagegroup/test/generate.go new file mode 100644 index 00000000..4efe1b2f --- /dev/null +++ b/pkg/storagegroup/test/generate.go @@ -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 +}