From 318755e9de9587c0124f1b798fe4a3964f212bee Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 8 Jun 2021 14:40:12 +0300 Subject: [PATCH] [#293] pkg/storagegroup: Implement and use generator of StorageGroup Signed-off-by: Leonard Lyubich --- pkg/storagegroup/storagegroup_test.go | 27 +++++---------------------- pkg/storagegroup/test/generate.go | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 pkg/storagegroup/test/generate.go diff --git a/pkg/storagegroup/storagegroup_test.go b/pkg/storagegroup/storagegroup_test.go index 8da5785..5118431 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 0000000..4efe1b2 --- /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 +}