From dd0a883637d2c02fe55ced06ba2cb234359aa484 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 8 Jun 2021 11:38:29 +0300 Subject: [PATCH] [#293] pkg/object: Implement and use generator of ID Signed-off-by: Leonard Lyubich --- pkg/audit/result_test.go | 23 +++++------------------ pkg/storagegroup/storagegroup_test.go | 12 +++--------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/pkg/audit/result_test.go b/pkg/audit/result_test.go index 56e683c..4edd5fd 100644 --- a/pkg/audit/result_test.go +++ b/pkg/audit/result_test.go @@ -1,29 +1,16 @@ package audit_test import ( - "crypto/rand" - "crypto/sha256" "testing" "github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg/audit" cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-api-go/pkg/object" + objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test" "github.com/stretchr/testify/require" ) -func testSHA256() (cs [sha256.Size]byte) { - _, _ = rand.Read(cs[:]) - return -} - -func testOID() *object.ID { - id := object.NewID() - id.SetSHA256(testSHA256()) - - return id -} - func TestResult(t *testing.T) { r := audit.NewResult() require.Equal(t, pkg.SDKVersion(), r.Version()) @@ -51,11 +38,11 @@ func TestResult(t *testing.T) { r.SetRetries(retries) require.Equal(t, retries, r.Retries()) - passSG := []*object.ID{testOID(), testOID()} + passSG := []*object.ID{objecttest.GenerateID(), objecttest.GenerateID()} r.SetPassSG(passSG) require.Equal(t, passSG, r.PassSG()) - failSG := []*object.ID{testOID(), testOID()} + failSG := []*object.ID{objecttest.GenerateID(), objecttest.GenerateID()} r.SetFailSG(failSG) require.Equal(t, failSG, r.FailSG()) @@ -85,8 +72,8 @@ func TestStorageGroupEncoding(t *testing.T) { r.SetAuditEpoch(13) r.SetContainerID(cidtest.Generate()) r.SetPublicKey([]byte{1, 2, 3}) - r.SetPassSG([]*object.ID{testOID(), testOID()}) - r.SetFailSG([]*object.ID{testOID(), testOID()}) + r.SetPassSG([]*object.ID{objecttest.GenerateID(), objecttest.GenerateID()}) + r.SetFailSG([]*object.ID{objecttest.GenerateID(), objecttest.GenerateID()}) r.SetRequests(3) r.SetRetries(2) r.SetHit(1) diff --git a/pkg/storagegroup/storagegroup_test.go b/pkg/storagegroup/storagegroup_test.go index 027c0f6..8da5785 100644 --- a/pkg/storagegroup/storagegroup_test.go +++ b/pkg/storagegroup/storagegroup_test.go @@ -7,6 +7,7 @@ import ( "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" "github.com/stretchr/testify/require" ) @@ -23,13 +24,6 @@ func testChecksum() *pkg.Checksum { return h } -func testOID() *object.ID { - id := object.NewID() - id.SetSHA256(testSHA256()) - - return id -} - func TestStorageGroup(t *testing.T) { sg := storagegroup.New() @@ -45,7 +39,7 @@ func TestStorageGroup(t *testing.T) { sg.SetExpirationEpoch(exp) require.Equal(t, exp, sg.ExpirationEpoch()) - members := []*object.ID{testOID(), testOID()} + members := []*object.ID{objecttest.GenerateID(), objecttest.GenerateID()} sg.SetMembers(members) require.Equal(t, members, sg.Members()) } @@ -55,7 +49,7 @@ func TestStorageGroupEncoding(t *testing.T) { sg.SetValidationDataSize(13) sg.SetValidationDataHash(testChecksum()) sg.SetExpirationEpoch(33) - sg.SetMembers([]*object.ID{testOID(), testOID()}) + sg.SetMembers([]*object.ID{objecttest.GenerateID(), objecttest.GenerateID()}) t.Run("binary", func(t *testing.T) { data, err := sg.Marshal()