Skip to content

Commit 73c9092

Browse files
committed
Use test module for random data generation
1 parent 760d35f commit 73c9092

14 files changed

+135
-133
lines changed

cardatatransfer/cardatatransfer_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import (
2727
"github.com/ipld/go-ipld-prime/traversal/selector/builder"
2828
selectorparse "github.com/ipld/go-ipld-prime/traversal/selector/parse"
2929
"github.com/ipni/go-libipni/metadata"
30-
"github.com/ipni/go-libipni/test"
3130
"github.com/ipni/index-provider/cardatatransfer"
3231
"github.com/ipni/index-provider/supplier"
3332
"github.com/ipni/index-provider/testutil"
33+
"github.com/ipni/test/random"
3434
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
3535
"github.com/stretchr/testify/require"
3636
)
@@ -50,7 +50,7 @@ func TestCarDataTransfer(t *testing.T) {
5050
require.NoError(t, err)
5151
require.Len(t, roots2, 1)
5252

53-
missingCid := test.RandomCids(1)[0]
53+
missingCid := random.Cids(1)[0]
5454
missingContextID := []byte("notFound")
5555

5656
supplier := &fakeSupplier{blockstores: make(map[string]supplier.ClosableBlockstore)}
@@ -72,7 +72,7 @@ func TestCarDataTransfer(t *testing.T) {
7272
pieceCID2 := pieceCIDFromContextID(t, contextID2)
7373
missingPieceCID := pieceCIDFromContextID(t, missingContextID)
7474

75-
incorrectPieceCid := test.RandomCids(1)[0]
75+
incorrectPieceCid := random.Cids(1)[0]
7676

7777
testCases := map[string]struct {
7878
voucher datatransfer.TypedVoucher

delegatedrouting/listener_concurrency_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
"github.com/ipfs/go-cid"
1313
"github.com/ipfs/go-datastore"
1414
leveldb "github.com/ipfs/go-ds-leveldb"
15-
"github.com/ipni/go-libipni/test"
1615
drouting "github.com/ipni/index-provider/delegatedrouting"
1716
"github.com/ipni/index-provider/engine"
1817
mock_provider "github.com/ipni/index-provider/mock"
18+
"github.com/ipni/test/random"
1919
"github.com/libp2p/go-libp2p"
2020
"github.com/stretchr/testify/require"
2121
)
@@ -26,7 +26,7 @@ func TestHandleConcurrentRequests(t *testing.T) {
2626
snapshotSize := 1000
2727
concurrencyFactor := 10
2828

29-
pID, priv, _ := test.RandomIdentity()
29+
pID, priv, _ := random.Identity()
3030

3131
ctx := context.Background()
3232
defer ctx.Done()
@@ -79,7 +79,7 @@ func TestShouldProcessMillionCIDsInThirtySeconds(t *testing.T) {
7979

8080
h, err := libp2p.New()
8181
require.NoError(t, err)
82-
pID, priv, _ := test.RandomIdentity()
82+
pID, priv, _ := random.Identity()
8383
ctx := context.Background()
8484

8585
engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher))

delegatedrouting/listener_test.go

+31-31
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717
"github.com/ipfs/go-datastore"
1818
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
1919
"github.com/ipni/go-libipni/metadata"
20-
"github.com/ipni/go-libipni/test"
2120
drouting "github.com/ipni/index-provider/delegatedrouting"
2221
"github.com/ipni/index-provider/engine"
2322
mock_provider "github.com/ipni/index-provider/mock"
23+
"github.com/ipni/test/random"
2424
"github.com/libp2p/go-libp2p"
2525
"github.com/libp2p/go-libp2p/core/crypto"
2626
"github.com/libp2p/go-libp2p/core/peer"
@@ -54,7 +54,7 @@ func TestDelegatedRoutingMultihashLister(t *testing.T) {
5454
cids[newCid("test2")] = struct{}{}
5555
cids[newCid("test3")] = struct{}{}
5656

57-
pID, _, _ := test.RandomIdentity()
57+
pID, _, _ := random.Identity()
5858

5959
lister := &drouting.MultihashLister{
6060
CidFetcher: func(contextID []byte) (map[cid.Cid]struct{}, error) {
@@ -118,7 +118,7 @@ func TestProvideRoundtrip(t *testing.T) {
118118

119119
h, err := libp2p.New()
120120
require.NoError(t, err)
121-
pID, priv, _ := test.RandomIdentity()
121+
pID, priv, _ := random.Identity()
122122

123123
ctx := context.Background()
124124

@@ -178,7 +178,7 @@ func TestProvideRoundtripWithRemove(t *testing.T) {
178178

179179
h, err := libp2p.New()
180180
require.NoError(t, err)
181-
pID, priv, _ := test.RandomIdentity()
181+
pID, priv, _ := random.Identity()
182182
ctx := context.Background()
183183

184184
engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher))
@@ -234,7 +234,7 @@ func TestAdvertiseTwoChunksWithOneCidInEach(t *testing.T) {
234234
chunkSize := 1
235235
snapshotSize := 1000
236236

237-
pID, priv, _ := test.RandomIdentity()
237+
pID, priv, _ := random.Identity()
238238

239239
ctx := context.Background()
240240
defer ctx.Done()
@@ -265,7 +265,7 @@ func TestAdvertiseUsingAddrsFromParameters(t *testing.T) {
265265
chunkSize := 1
266266
snapshotSize := 1000
267267

268-
pID, priv, _ := test.RandomIdentity()
268+
pID, priv, _ := random.Identity()
269269

270270
ctx := context.Background()
271271
defer ctx.Done()
@@ -300,7 +300,7 @@ func TestProvideRegistersCidInDatastore(t *testing.T) {
300300
chunkSize := 2
301301
snapshotSize := 1000
302302

303-
pID, priv, _ := test.RandomIdentity()
303+
pID, priv, _ := random.Identity()
304304

305305
ctx := context.Background()
306306
defer ctx.Done()
@@ -335,7 +335,7 @@ func TestCidsAreOrderedByArrivalInExpiryQueue(t *testing.T) {
335335
chunkSize := 1000
336336
snapshotSize := 1000
337337

338-
pID, priv, _ := test.RandomIdentity()
338+
pID, priv, _ := random.Identity()
339339

340340
ctx := context.Background()
341341
defer ctx.Done()
@@ -370,7 +370,7 @@ func TestFullChunkAdvertisedAndRegisteredInDatastore(t *testing.T) {
370370
chunkSize := 2
371371
snapshotSize := 1000
372372

373-
pID, priv, _ := test.RandomIdentity()
373+
pID, priv, _ := random.Identity()
374374

375375
ctx := context.Background()
376376
defer ctx.Done()
@@ -407,7 +407,7 @@ func TestRemovedChunkIsRemovedFromIndexes(t *testing.T) {
407407
chunkSize := 2
408408
snapshotSize := 1000
409409

410-
pID, priv, _ := test.RandomIdentity()
410+
pID, priv, _ := random.Identity()
411411

412412
ctx := context.Background()
413413
defer ctx.Done()
@@ -446,7 +446,7 @@ func TestAdvertiseOneChunkWithTwoCidsInIt(t *testing.T) {
446446
chunkSize := 2
447447
snapshotSize := 1000
448448

449-
pID, priv, _ := test.RandomIdentity()
449+
pID, priv, _ := random.Identity()
450450

451451
ctx := context.Background()
452452
defer ctx.Done()
@@ -476,7 +476,7 @@ func TestDoNotReAdvertiseRepeatedCids(t *testing.T) {
476476
chunkSize := 1
477477
snapshotSize := 1000
478478

479-
pID, priv, _ := test.RandomIdentity()
479+
pID, priv, _ := random.Identity()
480480

481481
ctx := context.Background()
482482
defer ctx.Done()
@@ -509,7 +509,7 @@ func TestAdvertiseExpiredCidsIfProvidedAgain(t *testing.T) {
509509
chunkSize := 1
510510
snapshotSize := 1000
511511

512-
pID, priv, _ := test.RandomIdentity()
512+
pID, priv, _ := random.Identity()
513513

514514
ctx := context.Background()
515515
defer ctx.Done()
@@ -547,7 +547,7 @@ func TestRemoveExpiredCidAndReadvertiseChunk(t *testing.T) {
547547
chunkSize := 2
548548
snapshotSize := 1000
549549

550-
pID, priv, _ := test.RandomIdentity()
550+
pID, priv, _ := random.Identity()
551551

552552
ctx := context.Background()
553553
defer ctx.Done()
@@ -591,7 +591,7 @@ func TestExpireMultipleChunks(t *testing.T) {
591591
chunkSize := 1
592592
snapshotSize := 1000
593593

594-
pID, priv, _ := test.RandomIdentity()
594+
pID, priv, _ := random.Identity()
595595

596596
ctx := context.Background()
597597
defer ctx.Done()
@@ -629,7 +629,7 @@ func TestDoNotReadvertiseChunkIfAllCidsExpired(t *testing.T) {
629629
chunkSize := 1
630630
snapshotSize := 1000
631631

632-
pID, priv, _ := test.RandomIdentity()
632+
pID, priv, _ := random.Identity()
633633

634634
ctx := context.Background()
635635
defer ctx.Done()
@@ -667,7 +667,7 @@ func TestDoNotReadvertiseTheSameCids(t *testing.T) {
667667
chunkSize := 2
668668
snapshotSize := 1000
669669

670-
pID, priv, _ := test.RandomIdentity()
670+
pID, priv, _ := random.Identity()
671671

672672
ctx := context.Background()
673673
defer ctx.Done()
@@ -698,7 +698,7 @@ func TestDoNotLoadRemovedChunksOnInitialisation(t *testing.T) {
698698
chunkSize := 1
699699
snapshotSize := 1000
700700

701-
pID, priv, _ := test.RandomIdentity()
701+
pID, priv, _ := random.Identity()
702702

703703
ctx := context.Background()
704704
defer ctx.Done()
@@ -738,7 +738,7 @@ func TestMissingCidTimestampsBackfilledOnIntialisation(t *testing.T) {
738738
chunkSize := 1
739739
snapshotSize := 1000
740740

741-
pID, priv, _ := test.RandomIdentity()
741+
pID, priv, _ := random.Identity()
742742

743743
ctx := context.Background()
744744
defer ctx.Done()
@@ -804,7 +804,7 @@ func TestSameCidNotDuplicatedInTheCurrentChunkIfProvidedTwice(t *testing.T) {
804804
chunkSize := 2
805805
snapshotSize := 1000
806806

807-
pID, priv, _ := test.RandomIdentity()
807+
pID, priv, _ := random.Identity()
808808

809809
ctx := context.Background()
810810
defer ctx.Done()
@@ -833,7 +833,7 @@ func TestShouldStoreSnapshotInDatastore(t *testing.T) {
833833
ttl := time.Hour
834834
chunkSize := 1000
835835

836-
pID, priv, _ := test.RandomIdentity()
836+
pID, priv, _ := random.Identity()
837837

838838
ctx := context.Background()
839839
defer ctx.Done()
@@ -874,7 +874,7 @@ func TestShouldNotStoreSnapshotInDatastore(t *testing.T) {
874874
ttl := time.Hour
875875
chunkSize := 1000
876876

877-
pID, priv, _ := test.RandomIdentity()
877+
pID, priv, _ := random.Identity()
878878

879879
ctx := context.Background()
880880
defer ctx.Done()
@@ -913,7 +913,7 @@ func TestShouldCleanUpTimestampMappingsFromDatastore(t *testing.T) {
913913
ttl := time.Hour
914914
chunkSize := 1000
915915

916-
pID, priv, _ := test.RandomIdentity()
916+
pID, priv, _ := random.Identity()
917917

918918
ctx := context.Background()
919919
defer ctx.Done()
@@ -959,7 +959,7 @@ func TestShouldCorrectlyMergeSnapshotAndCidTimestamps(t *testing.T) {
959959
ttl := time.Hour
960960
chunkSize := 1000
961961

962-
pID, priv, _ := test.RandomIdentity()
962+
pID, priv, _ := random.Identity()
963963

964964
ctx := context.Background()
965965
defer ctx.Done()
@@ -1011,7 +1011,7 @@ func TestInitialiseFromDatastoreWithSnapshot(t *testing.T) {
10111011
}
10121012

10131013
func verifyInitialisationFromDatastore(t *testing.T, snapshotSize int, ttl time.Duration, chunkSize int) {
1014-
pID, priv, _ := test.RandomIdentity()
1014+
pID, priv, _ := random.Identity()
10151015
// total number of test cids to generate
10161016
// - has to be not even so that not all of the cids end up included into chunks
10171017
// - has to span multiple page sizes so that datastore is initialised in pages
@@ -1101,7 +1101,7 @@ func TestCleanUpExpiredCidsThatDontHaveChunk(t *testing.T) {
11011101
ttl := time.Second
11021102
chunkSize := 2
11031103
snapshotSize := 1000
1104-
pID, priv, _ := test.RandomIdentity()
1104+
pID, priv, _ := random.Identity()
11051105

11061106
ctx := context.Background()
11071107
defer ctx.Done()
@@ -1142,7 +1142,7 @@ func TestCidsWithoutChunkAreRegisteredInDsAndIndexes(t *testing.T) {
11421142
ttl := 1 * time.Hour
11431143
chunkSize := 2
11441144
snapshotSize := 1000
1145-
pID, priv, _ := test.RandomIdentity()
1145+
pID, priv, _ := random.Identity()
11461146

11471147
ctx := context.Background()
11481148
defer ctx.Done()
@@ -1175,7 +1175,7 @@ func TestShouldSplitSnapshotIntoMultipleChunksAndReadThemBack(t *testing.T) {
11751175

11761176
h, err := libp2p.New()
11771177
require.NoError(t, err)
1178-
pID, priv, _ := test.RandomIdentity()
1178+
pID, priv, _ := random.Identity()
11791179
ctx := context.Background()
11801180

11811181
engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher))
@@ -1240,7 +1240,7 @@ func TestShouldCleanUpOldSnapshotChunksAfterStoringNewOnes(t *testing.T) {
12401240

12411241
h, err := libp2p.New()
12421242
require.NoError(t, err)
1243-
pID, priv, _ := test.RandomIdentity()
1243+
pID, priv, _ := random.Identity()
12441244
ctx := context.Background()
12451245

12461246
engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher))
@@ -1287,7 +1287,7 @@ func TestShouldRecogniseLegacySnapshot(t *testing.T) {
12871287

12881288
h, err := libp2p.New()
12891289
require.NoError(t, err)
1290-
pID, priv, _ := test.RandomIdentity()
1290+
pID, priv, _ := random.Identity()
12911291
ctx := context.Background()
12921292

12931293
engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher))
@@ -1347,7 +1347,7 @@ func TestAdsFlush(t *testing.T) {
13471347
chunkSize := 2
13481348
snapshotSize := 1000
13491349
adFlusFreq := 100 * time.Millisecond
1350-
pID, priv, _ := test.RandomIdentity()
1350+
pID, priv, _ := random.Identity()
13511351

13521352
ctx := context.Background()
13531353
defer ctx.Done()

engine/chunker/benchmark_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77

88
"github.com/ipfs/go-datastore"
99
dssync "github.com/ipfs/go-datastore/sync"
10-
"github.com/ipni/go-libipni/test"
1110
provider "github.com/ipni/index-provider"
1211
"github.com/ipni/index-provider/engine/chunker"
12+
"github.com/ipni/test/random"
1313
"github.com/multiformats/go-multicodec"
1414
"github.com/multiformats/go-multihash"
1515
"github.com/stretchr/testify/require"
@@ -25,7 +25,7 @@ func BenchmarkCachedChunker(b *testing.B) {
2525

2626
var mhis [][]multihash.Multihash
2727
for i := 0; i < capacity; i++ {
28-
mhis = append(mhis, test.RandomMultihashes(mhCount))
28+
mhis = append(mhis, random.Multihashes(mhCount))
2929
}
3030

3131
b.Run("ChainedEntryChunk/ChunkSize_1", benchmarkCachedChunker(ctx, byteSize, capacity, mhis, chunker.NewChainChunkerFunc(1)))
@@ -76,7 +76,7 @@ func BenchmarkRestoreCache_ChainChunker(b *testing.B) {
7676
subject, err := chunker.NewCachedEntriesChunker(ctx, store, capacity, chunker.NewChainChunkerFunc(chunkSize), false)
7777
require.NoError(b, err)
7878
for i := 0; i < capacity; i++ {
79-
mhi := test.RandomMultihashes(mhCount)
79+
mhi := random.Multihashes(mhCount)
8080
chunk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(mhi))
8181
require.NoError(b, err)
8282
require.NotNil(b, chunk)

0 commit comments

Comments
 (0)