From 3e1463cc76c594ced793f4b3762331a16353a577 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 31 May 2021 14:27:58 +0300 Subject: [PATCH] [#570] *: Use generator of test container IDs from API Go lib Signed-off-by: Leonard Lyubich --- pkg/core/object/fmt_test.go | 15 ++++----------- .../processors/audit/scheduler_test.go | 11 ++--------- .../blobovnicza/blobovnicza_test.go | 7 ++----- .../blobstor/blobovnicza_test.go | 7 ++----- .../blobstor/fstree/fstree_test.go | 14 ++------------ .../engine/engine_test.go | 10 ---------- pkg/local_object_storage/engine/head_test.go | 3 ++- .../engine/inhume_test.go | 3 ++- .../metabase/containers_test.go | 3 ++- pkg/local_object_storage/metabase/db_test.go | 15 +++------------ .../metabase/delete_test.go | 5 +++-- .../metabase/exists_test.go | 5 +++-- pkg/local_object_storage/metabase/get_test.go | 3 ++- .../metabase/select_test.go | 19 ++++++++++--------- pkg/local_object_storage/shard/delete_test.go | 3 ++- pkg/local_object_storage/shard/get_test.go | 3 ++- pkg/local_object_storage/shard/head_test.go | 3 ++- pkg/local_object_storage/shard/inhume_test.go | 3 ++- pkg/local_object_storage/shard/list_test.go | 3 ++- pkg/local_object_storage/shard/shard_test.go | 13 ++----------- pkg/morph/client/audit/wrapper/result_test.go | 6 ++---- .../load/controller/calls_test.go | 16 ++-------------- .../announcement/load/storage/storage_test.go | 16 ++-------------- pkg/services/object/acl/eacl/v2/eacl_test.go | 15 ++------------- pkg/services/object/get/get_test.go | 6 ++---- pkg/services/object/search/search_test.go | 12 +++--------- 26 files changed, 64 insertions(+), 155 deletions(-) diff --git a/pkg/core/object/fmt_test.go b/pkg/core/object/fmt_test.go index 1a5e99b69..a3fc952ad 100644 --- a/pkg/core/object/fmt_test.go +++ b/pkg/core/object/fmt_test.go @@ -8,7 +8,7 @@ import ( "strconv" "testing" - cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/session" @@ -28,13 +28,6 @@ func testSHA(t *testing.T) [sha256.Size]byte { return cs } -func testContainerID(t *testing.T) *cid.ID { - id := cid.New() - id.SetSHA256(testSHA(t)) - - return id -} - func testObjectID(t *testing.T) *object.ID { id := object.NewID() id.SetSHA256(testSHA(t)) @@ -50,7 +43,7 @@ func blankValidObject(t *testing.T, key *ecdsa.PrivateKey) *RawObject { ownerID.SetNeo3Wallet(wallet) obj := NewRaw() - obj.SetContainerID(testContainerID(t)) + obj.SetContainerID(cidtest.Generate()) obj.SetOwnerID(ownerID) return obj @@ -94,7 +87,7 @@ func TestFormatValidator_Validate(t *testing.T) { t.Run("unsigned object", func(t *testing.T) { obj := NewRaw() - obj.SetContainerID(testContainerID(t)) + obj.SetContainerID(cidtest.Generate()) obj.SetID(testObjectID(t)) require.Error(t, v.Validate(obj.Object())) @@ -105,7 +98,7 @@ func TestFormatValidator_Validate(t *testing.T) { tok.SetSessionKey(crypto.MarshalPublicKey(&ownerKey.PublicKey)) obj := NewRaw() - obj.SetContainerID(testContainerID(t)) + obj.SetContainerID(cidtest.Generate()) obj.SetSessionToken(tok) require.NoError(t, object.SetIDWithSignature(ownerKey, obj.SDK())) diff --git a/pkg/innerring/processors/audit/scheduler_test.go b/pkg/innerring/processors/audit/scheduler_test.go index 9ed6c4748..ef0cee84f 100644 --- a/pkg/innerring/processors/audit/scheduler_test.go +++ b/pkg/innerring/processors/audit/scheduler_test.go @@ -1,11 +1,10 @@ package audit_test import ( - "crypto/rand" - "crypto/sha256" "testing" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/audit" "github.com/stretchr/testify/require" ) @@ -77,16 +76,10 @@ func TestSelect(t *testing.T) { } func generateContainers(n int) []*cid.ID { - var buf [sha256.Size]byte result := make([]*cid.ID, 0, n) for i := 0; i < n; i++ { - _, _ = rand.Read(buf[:]) - - id := cid.New() - id.SetSHA256(buf) - - result = append(result, id) + result = append(result, cidtest.Generate()) } return result diff --git a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go index f5c2982cc..e4add96ae 100644 --- a/pkg/local_object_storage/blobovnicza/blobovnicza_test.go +++ b/pkg/local_object_storage/blobovnicza/blobovnicza_test.go @@ -7,7 +7,7 @@ import ( "os" "testing" - cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/util/logger/test" @@ -21,15 +21,12 @@ func testSHA256() (h [sha256.Size]byte) { } func testAddress() *objectSDK.Address { - id := cid.New() - id.SetSHA256(testSHA256()) - oid := objectSDK.NewID() oid.SetSHA256(testSHA256()) addr := objectSDK.NewAddress() addr.SetObjectID(oid) - addr.SetContainerID(id) + addr.SetContainerID(cidtest.Generate()) return addr } diff --git a/pkg/local_object_storage/blobstor/blobovnicza_test.go b/pkg/local_object_storage/blobstor/blobovnicza_test.go index 577e09f1a..23922aa0b 100644 --- a/pkg/local_object_storage/blobstor/blobovnicza_test.go +++ b/pkg/local_object_storage/blobstor/blobovnicza_test.go @@ -7,7 +7,7 @@ import ( "os" "testing" - cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/util/logger/test" @@ -21,15 +21,12 @@ func testSHA256() (h [sha256.Size]byte) { } func testAddress() *objectSDK.Address { - id := cid.New() - id.SetSHA256(testSHA256()) - oid := objectSDK.NewID() oid.SetSHA256(testSHA256()) addr := objectSDK.NewAddress() addr.SetObjectID(oid) - addr.SetContainerID(id) + addr.SetContainerID(cidtest.Generate()) return addr } diff --git a/pkg/local_object_storage/blobstor/fstree/fstree_test.go b/pkg/local_object_storage/blobstor/fstree/fstree_test.go index c15882629..a4d73f441 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree_test.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree_test.go @@ -8,21 +8,11 @@ import ( "path" "testing" - cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/stretchr/testify/require" ) -func testCID() *cid.ID { - cs := [sha256.Size]byte{} - _, _ = rand.Read(cs[:]) - - id := cid.New() - id.SetSHA256(cs) - - return id -} - func testOID() *objectSDK.ID { cs := [sha256.Size]byte{} _, _ = rand.Read(cs[:]) @@ -36,7 +26,7 @@ func testOID() *objectSDK.ID { func testAddress() *objectSDK.Address { a := objectSDK.NewAddress() a.SetObjectID(testOID()) - a.SetContainerID(testCID()) + a.SetContainerID(cidtest.Generate()) return a } diff --git a/pkg/local_object_storage/engine/engine_test.go b/pkg/local_object_storage/engine/engine_test.go index 72d64956d..a81b905c0 100644 --- a/pkg/local_object_storage/engine/engine_test.go +++ b/pkg/local_object_storage/engine/engine_test.go @@ -61,16 +61,6 @@ func testNewShard(t *testing.T, id int) *shard.Shard { return s } -func testCID() *cid.ID { - cs := [sha256.Size]byte{} - _, _ = rand.Read(cs[:]) - - id := cid.New() - id.SetSHA256(cs) - - return id -} - func testOID() *objectSDK.ID { cs := [sha256.Size]byte{} _, _ = rand.Read(cs[:]) diff --git a/pkg/local_object_storage/engine/head_test.go b/pkg/local_object_storage/engine/head_test.go index f90f96be5..b08fa9cbe 100644 --- a/pkg/local_object_storage/engine/head_test.go +++ b/pkg/local_object_storage/engine/head_test.go @@ -4,6 +4,7 @@ import ( "os" "testing" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/stretchr/testify/require" @@ -12,7 +13,7 @@ import ( func TestHeadRaw(t *testing.T) { defer os.RemoveAll(t.Name()) - cid := testCID() + cid := cidtest.Generate() splitID := objectSDK.NewSplitID() parent := generateRawObjectWithCID(t, cid) diff --git a/pkg/local_object_storage/engine/inhume_test.go b/pkg/local_object_storage/engine/inhume_test.go index 2c3a46e88..15ea9b971 100644 --- a/pkg/local_object_storage/engine/inhume_test.go +++ b/pkg/local_object_storage/engine/inhume_test.go @@ -4,6 +4,7 @@ import ( "os" "testing" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/stretchr/testify/require" @@ -12,7 +13,7 @@ import ( func TestStorageEngine_Inhume(t *testing.T) { defer os.RemoveAll(t.Name()) - cid := testCID() + cid := cidtest.Generate() splitID := objectSDK.NewSplitID() fs := objectSDK.SearchFilters{} diff --git a/pkg/local_object_storage/metabase/containers_test.go b/pkg/local_object_storage/metabase/containers_test.go index 621905bbf..5c8eecad1 100644 --- a/pkg/local_object_storage/metabase/containers_test.go +++ b/pkg/local_object_storage/metabase/containers_test.go @@ -5,6 +5,7 @@ import ( "testing" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-node/pkg/core/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/stretchr/testify/require" @@ -84,7 +85,7 @@ func TestDB_ContainerSize(t *testing.T) { objs := make(map[*cid.ID][]*object.RawObject, C*N) for i := 0; i < C; i++ { - cid := testCID() + cid := cidtest.Generate() cids[cid] = 0 for j := 0; j < N; j++ { diff --git a/pkg/local_object_storage/metabase/db_test.go b/pkg/local_object_storage/metabase/db_test.go index 801ce6277..9a5b48a50 100644 --- a/pkg/local_object_storage/metabase/db_test.go +++ b/pkg/local_object_storage/metabase/db_test.go @@ -8,6 +8,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-node/pkg/core/object" @@ -32,16 +33,6 @@ func testSelect(t *testing.T, db *meta.DB, cid *cid.ID, fs objectSDK.SearchFilte } } -func testCID() *cid.ID { - cs := [sha256.Size]byte{} - _, _ = rand.Read(cs[:]) - - id := cid.New() - id.SetSHA256(cs) - - return id -} - func testOID() *objectSDK.ID { cs := [sha256.Size]byte{} _, _ = rand.Read(cs[:]) @@ -68,7 +59,7 @@ func releaseDB(db *meta.DB) { } func generateRawObject(t *testing.T) *object.RawObject { - return generateRawObjectWithCID(t, testCID()) + return generateRawObjectWithCID(t, cidtest.Generate()) } func generateRawObjectWithCID(t *testing.T, cid *cid.ID) *object.RawObject { @@ -102,7 +93,7 @@ func generateRawObjectWithCID(t *testing.T, cid *cid.ID) *object.RawObject { func generateAddress() *objectSDK.Address { addr := objectSDK.NewAddress() - addr.SetContainerID(testCID()) + addr.SetContainerID(cidtest.Generate()) addr.SetObjectID(testOID()) return addr diff --git a/pkg/local_object_storage/metabase/delete_test.go b/pkg/local_object_storage/metabase/delete_test.go index ccac6780c..ef7923a0a 100644 --- a/pkg/local_object_storage/metabase/delete_test.go +++ b/pkg/local_object_storage/metabase/delete_test.go @@ -4,6 +4,7 @@ import ( "errors" "testing" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/stretchr/testify/require" @@ -13,7 +14,7 @@ func TestDB_Delete(t *testing.T) { db := newDB(t) defer releaseDB(db) - cid := testCID() + cid := cidtest.Generate() parent := generateRawObjectWithCID(t, cid) addAttribute(parent, "foo", "bar") @@ -70,7 +71,7 @@ func TestDeleteAllChildren(t *testing.T) { db := newDB(t) defer releaseDB(db) - cid := testCID() + cid := cidtest.Generate() // generate parent object parent := generateRawObjectWithCID(t, cid) diff --git a/pkg/local_object_storage/metabase/exists_test.go b/pkg/local_object_storage/metabase/exists_test.go index 6b1a6c985..851f34b3d 100644 --- a/pkg/local_object_storage/metabase/exists_test.go +++ b/pkg/local_object_storage/metabase/exists_test.go @@ -4,6 +4,7 @@ import ( "errors" "testing" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/stretchr/testify/require" @@ -55,7 +56,7 @@ func TestDB_Exists(t *testing.T) { }) t.Run("virtual object", func(t *testing.T) { - cid := testCID() + cid := cidtest.Generate() parent := generateRawObjectWithCID(t, cid) child := generateRawObjectWithCID(t, cid) @@ -72,7 +73,7 @@ func TestDB_Exists(t *testing.T) { }) t.Run("merge split info", func(t *testing.T) { - cid := testCID() + cid := cidtest.Generate() splitID := objectSDK.NewSplitID() parent := generateRawObjectWithCID(t, cid) diff --git a/pkg/local_object_storage/metabase/get_test.go b/pkg/local_object_storage/metabase/get_test.go index 83947b81d..6db4b973c 100644 --- a/pkg/local_object_storage/metabase/get_test.go +++ b/pkg/local_object_storage/metabase/get_test.go @@ -4,6 +4,7 @@ import ( "bytes" "testing" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" @@ -59,7 +60,7 @@ func TestDB_Get(t *testing.T) { }) t.Run("put virtual object", func(t *testing.T) { - cid := testCID() + cid := cidtest.Generate() splitID := objectSDK.NewSplitID() parent := generateRawObjectWithCID(t, cid) diff --git a/pkg/local_object_storage/metabase/select_test.go b/pkg/local_object_storage/metabase/select_test.go index 6d955a017..1d8bc9a33 100644 --- a/pkg/local_object_storage/metabase/select_test.go +++ b/pkg/local_object_storage/metabase/select_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/nspcc-dev/neofs-api-go/pkg" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" v2object "github.com/nspcc-dev/neofs-api-go/v2/object" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" @@ -15,7 +16,7 @@ func TestDB_SelectUserAttributes(t *testing.T) { db := newDB(t) defer releaseDB(db) - cid := testCID() + cid := cidtest.Generate() raw1 := generateRawObjectWithCID(t, cid) addAttribute(raw1, "foo", "bar") @@ -88,7 +89,7 @@ func TestDB_SelectRootPhyParent(t *testing.T) { db := newDB(t) defer releaseDB(db) - cid := testCID() + cid := cidtest.Generate() // prepare @@ -256,7 +257,7 @@ func TestDB_SelectInhume(t *testing.T) { db := newDB(t) defer releaseDB(db) - cid := testCID() + cid := cidtest.Generate() raw1 := generateRawObjectWithCID(t, cid) err := putBig(db, raw1.Object()) @@ -289,7 +290,7 @@ func TestDB_SelectPayloadHash(t *testing.T) { db := newDB(t) defer releaseDB(db) - cid := testCID() + cid := cidtest.Generate() raw1 := generateRawObjectWithCID(t, cid) err := putBig(db, raw1.Object()) @@ -325,7 +326,7 @@ func TestDB_SelectWithSlowFilters(t *testing.T) { db := newDB(t) defer releaseDB(db) - cid := testCID() + cid := cidtest.Generate() v20 := new(pkg.Version) v20.SetMajor(2) @@ -424,7 +425,7 @@ func TestDB_SelectObjectID(t *testing.T) { db := newDB(t) defer releaseDB(db) - cid := testCID() + cid := cidtest.Generate() // prepare @@ -533,7 +534,7 @@ func TestDB_SelectSplitID(t *testing.T) { db := newDB(t) defer releaseDB(db) - cid := testCID() + cid := cidtest.Generate() child1 := generateRawObjectWithCID(t, cid) child2 := generateRawObjectWithCID(t, cid) @@ -588,7 +589,7 @@ func TestDB_SelectContainerID(t *testing.T) { db := newDB(t) defer releaseDB(db) - cid := testCID() + cid := cidtest.Generate() obj1 := generateRawObjectWithCID(t, cid) err := putBig(db, obj1.Object()) @@ -622,7 +623,7 @@ func TestDB_SelectContainerID(t *testing.T) { }) t.Run("not same cid", func(t *testing.T) { - newCID := testCID() + newCID := cidtest.Generate() fs := objectSDK.SearchFilters{} fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, newCID) diff --git a/pkg/local_object_storage/shard/delete_test.go b/pkg/local_object_storage/shard/delete_test.go index facacb42d..053db63db 100644 --- a/pkg/local_object_storage/shard/delete_test.go +++ b/pkg/local_object_storage/shard/delete_test.go @@ -3,6 +3,7 @@ package shard_test import ( "testing" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/stretchr/testify/require" @@ -22,7 +23,7 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { sh := newShard(t, hasWriteCache) defer releaseShard(sh, t) - cid := generateCID() + cid := cidtest.Generate() obj := generateRawObjectWithCID(t, cid) addAttribute(obj, "foo", "bar") diff --git a/pkg/local_object_storage/shard/get_test.go b/pkg/local_object_storage/shard/get_test.go index 4d661054a..5778256a9 100644 --- a/pkg/local_object_storage/shard/get_test.go +++ b/pkg/local_object_storage/shard/get_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" @@ -67,7 +68,7 @@ func testShardGet(t *testing.T, hasWriteCache bool) { t.Run("parent object", func(t *testing.T) { obj := generateRawObject(t) addAttribute(obj, "foo", "bar") - cid := generateCID() + cid := cidtest.Generate() splitID := objectSDK.NewSplitID() parent := generateRawObjectWithCID(t, cid) diff --git a/pkg/local_object_storage/shard/head_test.go b/pkg/local_object_storage/shard/head_test.go index 8d0e6c39b..0d7516633 100644 --- a/pkg/local_object_storage/shard/head_test.go +++ b/pkg/local_object_storage/shard/head_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" @@ -45,7 +46,7 @@ func testShardHead(t *testing.T, hasWriteCache bool) { }) t.Run("virtual object", func(t *testing.T) { - cid := generateCID() + cid := cidtest.Generate() splitID := objectSDK.NewSplitID() parent := generateRawObjectWithCID(t, cid) diff --git a/pkg/local_object_storage/shard/inhume_test.go b/pkg/local_object_storage/shard/inhume_test.go index ad1e17003..c99e20355 100644 --- a/pkg/local_object_storage/shard/inhume_test.go +++ b/pkg/local_object_storage/shard/inhume_test.go @@ -3,6 +3,7 @@ package shard_test import ( "testing" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-node/pkg/core/object" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/stretchr/testify/require" @@ -22,7 +23,7 @@ func testShardInhume(t *testing.T, hasWriteCache bool) { sh := newShard(t, hasWriteCache) defer releaseShard(sh, t) - cid := generateCID() + cid := cidtest.Generate() obj := generateRawObjectWithCID(t, cid) addAttribute(obj, "foo", "bar") diff --git a/pkg/local_object_storage/shard/list_test.go b/pkg/local_object_storage/shard/list_test.go index 873e8788c..68998a4fb 100644 --- a/pkg/local_object_storage/shard/list_test.go +++ b/pkg/local_object_storage/shard/list_test.go @@ -3,6 +3,7 @@ package shard_test import ( "testing" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard" "github.com/stretchr/testify/require" ) @@ -33,7 +34,7 @@ func testShardList(t *testing.T, sh *shard.Shard) { putPrm := new(shard.PutPrm) for i := 0; i < C; i++ { - cid := generateCID() + cid := cidtest.Generate() for j := 0; j < N; j++ { obj := generateRawObjectWithCID(t, cid) diff --git a/pkg/local_object_storage/shard/shard_test.go b/pkg/local_object_storage/shard/shard_test.go index 303e27952..4cbf5877b 100644 --- a/pkg/local_object_storage/shard/shard_test.go +++ b/pkg/local_object_storage/shard/shard_test.go @@ -9,6 +9,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-node/pkg/core/object" @@ -61,7 +62,7 @@ func releaseShard(s *shard.Shard, t testing.TB) { } func generateRawObject(t *testing.T) *object.RawObject { - return generateRawObjectWithCID(t, generateCID()) + return generateRawObjectWithCID(t, cidtest.Generate()) } func generateRawObjectWithCID(t *testing.T, cid *cid.ID) *object.RawObject { @@ -110,16 +111,6 @@ func addPayload(obj *object.RawObject, size int) { obj.SetPayloadSize(uint64(size)) } -func generateCID() *cid.ID { - cs := [sha256.Size]byte{} - _, _ = rand.Read(cs[:]) - - id := cid.New() - id.SetSHA256(cs) - - return id -} - func generateOID() *objectSDK.ID { cs := [sha256.Size]byte{} _, _ = rand.Read(cs[:]) diff --git a/pkg/morph/client/audit/wrapper/result_test.go b/pkg/morph/client/audit/wrapper/result_test.go index cbdf9d2eb..343752863 100644 --- a/pkg/morph/client/audit/wrapper/result_test.go +++ b/pkg/morph/client/audit/wrapper/result_test.go @@ -1,13 +1,12 @@ package audit_test import ( - "crypto/sha256" "testing" "time" "github.com/nspcc-dev/neo-go/pkg/util" auditAPI "github.com/nspcc-dev/neofs-api-go/pkg/audit" - cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-node/pkg/morph/client" auditWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/audit/wrapper" @@ -36,8 +35,7 @@ func TestAuditResults(t *testing.T) { auditClientWrapper, err := auditWrapper.NewFromMorph(morphClient, auditHash, 0) require.NoError(t, err) - id := cid.New() - id.SetSHA256([sha256.Size]byte{1, 2, 3}) + id := cidtest.Generate() auditRes := auditAPI.NewResult() auditRes.SetAuditEpoch(epoch) diff --git a/pkg/services/container/announcement/load/controller/calls_test.go b/pkg/services/container/announcement/load/controller/calls_test.go index d8d817e5a..07e7bae79 100644 --- a/pkg/services/container/announcement/load/controller/calls_test.go +++ b/pkg/services/container/announcement/load/controller/calls_test.go @@ -2,13 +2,12 @@ package loadcontroller_test import ( "context" - "crypto/sha256" "math/rand" "sync" "testing" "github.com/nspcc-dev/neofs-api-go/pkg/container" - cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" loadcontroller "github.com/nspcc-dev/neofs-node/pkg/services/container/announcement/load/controller" "github.com/stretchr/testify/require" ) @@ -74,20 +73,9 @@ func (s *testAnnouncementStorage) Close() error { return nil } -func randCID() *cid.ID { - h := [sha256.Size]byte{} - - rand.Read(h[:]) - - id := cid.New() - id.SetSHA256(h) - - return id -} - func randAnnouncement() container.UsedSpaceAnnouncement { a := container.NewAnnouncement() - a.SetContainerID(randCID()) + a.SetContainerID(cidtest.Generate()) a.SetUsedSpace(rand.Uint64()) return *a diff --git a/pkg/services/container/announcement/load/storage/storage_test.go b/pkg/services/container/announcement/load/storage/storage_test.go index fbfc6f0fb..441c1af86 100644 --- a/pkg/services/container/announcement/load/storage/storage_test.go +++ b/pkg/services/container/announcement/load/storage/storage_test.go @@ -1,31 +1,19 @@ package loadstorage import ( - "crypto/sha256" "math/rand" "testing" "github.com/nspcc-dev/neofs-api-go/pkg/container" - cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/stretchr/testify/require" ) -func randCID() *cid.ID { - h := [sha256.Size]byte{} - - rand.Read(h[:]) - - id := cid.New() - id.SetSHA256(h) - - return id -} - func TestStorage(t *testing.T) { const epoch uint64 = 13 a := container.NewAnnouncement() - a.SetContainerID(randCID()) + a.SetContainerID(cidtest.Generate()) a.SetEpoch(epoch) const opinionsNum = 100 diff --git a/pkg/services/object/acl/eacl/v2/eacl_test.go b/pkg/services/object/acl/eacl/v2/eacl_test.go index 1ed738243..75827a5fa 100644 --- a/pkg/services/object/acl/eacl/v2/eacl_test.go +++ b/pkg/services/object/acl/eacl/v2/eacl_test.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-api-go/v2/session" @@ -57,22 +58,10 @@ func testID(t *testing.T) *objectSDK.ID { return id } -func testCID(t *testing.T) *cid.ID { - cs := [sha256.Size]byte{} - - _, err := rand.Read(cs[:]) - require.NoError(t, err) - - id := cid.New() - id.SetSHA256(cs) - - return id -} - func testAddress(t *testing.T) *objectSDK.Address { addr := objectSDK.NewAddress() addr.SetObjectID(testID(t)) - addr.SetContainerID(testCID(t)) + addr.SetContainerID(cidtest.Generate()) return addr } diff --git a/pkg/services/object/get/get_test.go b/pkg/services/object/get/get_test.go index d8f7a99cb..b0232d686 100644 --- a/pkg/services/object/get/get_test.go +++ b/pkg/services/object/get/get_test.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/container" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/core/object" @@ -192,10 +193,7 @@ func generateAddress() *objectSDK.Address { addr := objectSDK.NewAddress() addr.SetObjectID(generateID()) - id := cid.New() - id.SetSHA256(testSHA256()) - - addr.SetContainerID(id) + addr.SetContainerID(cidtest.Generate()) return addr } diff --git a/pkg/services/object/search/search_test.go b/pkg/services/object/search/search_test.go index 5937b8a8d..394b6ef8f 100644 --- a/pkg/services/object/search/search_test.go +++ b/pkg/services/object/search/search_test.go @@ -11,6 +11,7 @@ import ( "github.com/nspcc-dev/neofs-api-go/pkg/container" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id" + cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test" "github.com/nspcc-dev/neofs-api-go/pkg/netmap" objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-node/pkg/network" @@ -127,13 +128,6 @@ func testSHA256() (cs [sha256.Size]byte) { return cs } -func generateCID() *cid.ID { - id := cid.New() - id.SetSHA256(testSHA256()) - - return id -} - func generateIDs(num int) []*objectSDK.ID { res := make([]*objectSDK.ID, num) @@ -169,7 +163,7 @@ func TestGetLocalOnly(t *testing.T) { storage := newTestStorage() svc := newSvc(storage) - cid := generateCID() + cid := cidtest.Generate() ids := generateIDs(10) storage.addResult(cid, ids, nil) @@ -185,7 +179,7 @@ func TestGetLocalOnly(t *testing.T) { storage := newTestStorage() svc := newSvc(storage) - cid := generateCID() + cid := cidtest.Generate() testErr := errors.New("any error") storage.addResult(cid, nil, testErr)