diff --git a/.github/workflows/goreleaser-check.yml b/.github/workflows/goreleaser-check.yml index 44911232..a2650f03 100644 --- a/.github/workflows/goreleaser-check.yml +++ b/.github/workflows/goreleaser-check.yml @@ -15,7 +15,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.19.x" + go-version: "1.22.x" - name: Check GoReleaser config uses: goreleaser/goreleaser-action@v6 with: diff --git a/cardatatransfer/cardatatransfer_test.go b/cardatatransfer/cardatatransfer_test.go index 46a9d6ee..a47dee61 100644 --- a/cardatatransfer/cardatatransfer_test.go +++ b/cardatatransfer/cardatatransfer_test.go @@ -16,6 +16,7 @@ import ( "github.com/ipfs/go-datastore" dssync "github.com/ipfs/go-datastore/sync" "github.com/ipfs/go-graphsync/storeutil" + "github.com/ipfs/go-test/random" dagpb "github.com/ipld/go-codec-dagpb" "github.com/ipld/go-ipld-prime" "github.com/ipld/go-ipld-prime/datamodel" @@ -27,7 +28,6 @@ import ( "github.com/ipld/go-ipld-prime/traversal/selector/builder" selectorparse "github.com/ipld/go-ipld-prime/traversal/selector/parse" "github.com/ipni/go-libipni/metadata" - "github.com/ipni/go-libipni/test" "github.com/ipni/index-provider/cardatatransfer" "github.com/ipni/index-provider/supplier" "github.com/ipni/index-provider/testutil" @@ -50,7 +50,7 @@ func TestCarDataTransfer(t *testing.T) { require.NoError(t, err) require.Len(t, roots2, 1) - missingCid := test.RandomCids(1)[0] + missingCid := random.Cids(1)[0] missingContextID := []byte("notFound") supplier := &fakeSupplier{blockstores: make(map[string]supplier.ClosableBlockstore)} @@ -72,7 +72,7 @@ func TestCarDataTransfer(t *testing.T) { pieceCID2 := pieceCIDFromContextID(t, contextID2) missingPieceCID := pieceCIDFromContextID(t, missingContextID) - incorrectPieceCid := test.RandomCids(1)[0] + incorrectPieceCid := random.Cids(1)[0] testCases := map[string]struct { voucher datatransfer.TypedVoucher diff --git a/delegatedrouting/listener_concurrency_test.go b/delegatedrouting/listener_concurrency_test.go index 16d0658a..cc6fffbc 100644 --- a/delegatedrouting/listener_concurrency_test.go +++ b/delegatedrouting/listener_concurrency_test.go @@ -12,7 +12,7 @@ import ( "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" leveldb "github.com/ipfs/go-ds-leveldb" - "github.com/ipni/go-libipni/test" + "github.com/ipfs/go-test/random" drouting "github.com/ipni/index-provider/delegatedrouting" "github.com/ipni/index-provider/engine" mock_provider "github.com/ipni/index-provider/mock" @@ -26,7 +26,7 @@ func TestHandleConcurrentRequests(t *testing.T) { snapshotSize := 1000 concurrencyFactor := 10 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -79,7 +79,7 @@ func TestShouldProcessMillionCIDsInThirtySeconds(t *testing.T) { h, err := libp2p.New() require.NoError(t, err) - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher)) diff --git a/delegatedrouting/listener_test.go b/delegatedrouting/listener_test.go index 84f55766..a1215e11 100644 --- a/delegatedrouting/listener_test.go +++ b/delegatedrouting/listener_test.go @@ -15,9 +15,9 @@ import ( "github.com/ipfs/boxo/routing/http/server" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" + "github.com/ipfs/go-test/random" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/ipni/go-libipni/metadata" - "github.com/ipni/go-libipni/test" drouting "github.com/ipni/index-provider/delegatedrouting" "github.com/ipni/index-provider/engine" mock_provider "github.com/ipni/index-provider/mock" @@ -54,7 +54,7 @@ func TestDelegatedRoutingMultihashLister(t *testing.T) { cids[newCid("test2")] = struct{}{} cids[newCid("test3")] = struct{}{} - pID, _, _ := test.RandomIdentity() + pID, _, _ := random.Identity() lister := &drouting.MultihashLister{ CidFetcher: func(contextID []byte) (map[cid.Cid]struct{}, error) { @@ -118,7 +118,7 @@ func TestProvideRoundtrip(t *testing.T) { h, err := libp2p.New() require.NoError(t, err) - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() @@ -178,7 +178,7 @@ func TestProvideRoundtripWithRemove(t *testing.T) { h, err := libp2p.New() require.NoError(t, err) - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher)) @@ -234,7 +234,7 @@ func TestAdvertiseTwoChunksWithOneCidInEach(t *testing.T) { chunkSize := 1 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -265,7 +265,7 @@ func TestAdvertiseUsingAddrsFromParameters(t *testing.T) { chunkSize := 1 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -300,7 +300,7 @@ func TestProvideRegistersCidInDatastore(t *testing.T) { chunkSize := 2 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -335,7 +335,7 @@ func TestCidsAreOrderedByArrivalInExpiryQueue(t *testing.T) { chunkSize := 1000 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -370,7 +370,7 @@ func TestFullChunkAdvertisedAndRegisteredInDatastore(t *testing.T) { chunkSize := 2 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -407,7 +407,7 @@ func TestRemovedChunkIsRemovedFromIndexes(t *testing.T) { chunkSize := 2 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -446,7 +446,7 @@ func TestAdvertiseOneChunkWithTwoCidsInIt(t *testing.T) { chunkSize := 2 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -476,7 +476,7 @@ func TestDoNotReAdvertiseRepeatedCids(t *testing.T) { chunkSize := 1 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -509,7 +509,7 @@ func TestAdvertiseExpiredCidsIfProvidedAgain(t *testing.T) { chunkSize := 1 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -547,7 +547,7 @@ func TestRemoveExpiredCidAndReadvertiseChunk(t *testing.T) { chunkSize := 2 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -591,7 +591,7 @@ func TestExpireMultipleChunks(t *testing.T) { chunkSize := 1 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -629,7 +629,7 @@ func TestDoNotReadvertiseChunkIfAllCidsExpired(t *testing.T) { chunkSize := 1 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -667,7 +667,7 @@ func TestDoNotReadvertiseTheSameCids(t *testing.T) { chunkSize := 2 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -698,7 +698,7 @@ func TestDoNotLoadRemovedChunksOnInitialisation(t *testing.T) { chunkSize := 1 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -738,7 +738,7 @@ func TestMissingCidTimestampsBackfilledOnIntialisation(t *testing.T) { chunkSize := 1 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -804,7 +804,7 @@ func TestSameCidNotDuplicatedInTheCurrentChunkIfProvidedTwice(t *testing.T) { chunkSize := 2 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -833,7 +833,7 @@ func TestShouldStoreSnapshotInDatastore(t *testing.T) { ttl := time.Hour chunkSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -874,7 +874,7 @@ func TestShouldNotStoreSnapshotInDatastore(t *testing.T) { ttl := time.Hour chunkSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -913,7 +913,7 @@ func TestShouldCleanUpTimestampMappingsFromDatastore(t *testing.T) { ttl := time.Hour chunkSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -959,7 +959,7 @@ func TestShouldCorrectlyMergeSnapshotAndCidTimestamps(t *testing.T) { ttl := time.Hour chunkSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -1011,7 +1011,7 @@ func TestInitialiseFromDatastoreWithSnapshot(t *testing.T) { } func verifyInitialisationFromDatastore(t *testing.T, snapshotSize int, ttl time.Duration, chunkSize int) { - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() // total number of test cids to generate // - has to be not even so that not all of the cids end up included into chunks // - has to span multiple page sizes so that datastore is initialised in pages @@ -1101,7 +1101,7 @@ func TestCleanUpExpiredCidsThatDontHaveChunk(t *testing.T) { ttl := time.Second chunkSize := 2 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -1142,7 +1142,7 @@ func TestCidsWithoutChunkAreRegisteredInDsAndIndexes(t *testing.T) { ttl := 1 * time.Hour chunkSize := 2 snapshotSize := 1000 - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() @@ -1175,7 +1175,7 @@ func TestShouldSplitSnapshotIntoMultipleChunksAndReadThemBack(t *testing.T) { h, err := libp2p.New() require.NoError(t, err) - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher)) @@ -1240,7 +1240,7 @@ func TestShouldCleanUpOldSnapshotChunksAfterStoringNewOnes(t *testing.T) { h, err := libp2p.New() require.NoError(t, err) - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher)) @@ -1287,7 +1287,7 @@ func TestShouldRecogniseLegacySnapshot(t *testing.T) { h, err := libp2p.New() require.NoError(t, err) - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() engine, err := engine.New(engine.WithHost(h), engine.WithPublisherKind(engine.Libp2pPublisher)) @@ -1347,7 +1347,7 @@ func TestAdsFlush(t *testing.T) { chunkSize := 2 snapshotSize := 1000 adFlusFreq := 100 * time.Millisecond - pID, priv, _ := test.RandomIdentity() + pID, priv, _ := random.Identity() ctx := context.Background() defer ctx.Done() diff --git a/engine/chunker/benchmark_test.go b/engine/chunker/benchmark_test.go index b1fcf595..3a94b6a0 100644 --- a/engine/chunker/benchmark_test.go +++ b/engine/chunker/benchmark_test.go @@ -7,7 +7,7 @@ import ( "github.com/ipfs/go-datastore" dssync "github.com/ipfs/go-datastore/sync" - "github.com/ipni/go-libipni/test" + "github.com/ipfs/go-test/random" provider "github.com/ipni/index-provider" "github.com/ipni/index-provider/engine/chunker" "github.com/multiformats/go-multicodec" @@ -25,7 +25,7 @@ func BenchmarkCachedChunker(b *testing.B) { var mhis [][]multihash.Multihash for i := 0; i < capacity; i++ { - mhis = append(mhis, test.RandomMultihashes(mhCount)) + mhis = append(mhis, random.Multihashes(mhCount)) } b.Run("ChainedEntryChunk/ChunkSize_1", benchmarkCachedChunker(ctx, byteSize, capacity, mhis, chunker.NewChainChunkerFunc(1))) @@ -76,7 +76,7 @@ func BenchmarkRestoreCache_ChainChunker(b *testing.B) { subject, err := chunker.NewCachedEntriesChunker(ctx, store, capacity, chunker.NewChainChunkerFunc(chunkSize), false) require.NoError(b, err) for i := 0; i < capacity; i++ { - mhi := test.RandomMultihashes(mhCount) + mhi := random.Multihashes(mhCount) chunk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(mhi)) require.NoError(b, err) require.NotNil(b, chunk) diff --git a/engine/chunker/cached_chunker_test.go b/engine/chunker/cached_chunker_test.go index 9b5a3fa4..576caf28 100644 --- a/engine/chunker/cached_chunker_test.go +++ b/engine/chunker/cached_chunker_test.go @@ -11,13 +11,13 @@ import ( "github.com/ipfs/go-datastore" dssync "github.com/ipfs/go-datastore/sync" + "github.com/ipfs/go-test/random" hamt "github.com/ipld/go-ipld-adl-hamt" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" ipldcodec "github.com/ipld/go-ipld-prime/multicodec" "github.com/ipld/go-ipld-prime/node/bindnode" "github.com/ipni/go-libipni/ingest/schema" - "github.com/ipni/go-libipni/test" provider "github.com/ipni/index-provider" "github.com/ipni/index-provider/engine/chunker" "github.com/multiformats/go-multicodec" @@ -35,7 +35,7 @@ func TestCachedEntriesChunker_Chain_OverlappingLinkCounter(t *testing.T) { defer subject.Close() // Cache a link with 2 full chunks - c1Mhs := test.RandomMultihashes(20) + c1Mhs := random.Multihashes(20) c1Lnk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(c1Mhs)) require.NoError(t, err) c1Chain := listEntriesChain(t, subject, c1Lnk) @@ -44,7 +44,7 @@ func TestCachedEntriesChunker_Chain_OverlappingLinkCounter(t *testing.T) { for i := 1; i < capacity*2; i++ { // Generate a chunk worth of CIDs - newMhs := test.RandomMultihashes(i * 2) + newMhs := random.Multihashes(i * 2) // Append to the previously generated CIDs newMhs = append(c1Mhs, newMhs...) wantChainLen := math.Ceil(float64(len(newMhs)) / float64(chunkSize)) @@ -116,7 +116,7 @@ func testCachedEntriesChunker_CapAndLen(t *testing.T, capacity int, c chunker.Ne var chunks []ipld.Link for i := 1; i < capacity*2; i++ { - mhs := test.RandomMultihashes(5 * i) + mhs := random.Multihashes(5 * i) chunk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(mhs)) require.NoError(t, err) requireChunkIsCached(t, subject, chunk) @@ -144,7 +144,7 @@ func testNewCachedEntriesChunker_FailsWhenContextIsCancelled(t *testing.T, capac // Prepare subject by caching something so that restore has data to recover subject, err := chunker.NewCachedEntriesChunker(ctx, ds, capacity, c, false) require.NoError(t, err) - mhs := test.RandomMultihashes(45) + mhs := random.Multihashes(45) _, err = subject.Chunk(ctx, provider.SliceMultihashIterator(mhs)) require.NoError(t, err) require.NoError(t, subject.Close()) @@ -165,7 +165,7 @@ func testCachedEntriesChunker_NonOverlappingDagIsEvicted(t *testing.T, c chunker defer subject.Close() // Cache a chain of length 5 and assert it is cached. - c1Mhs := test.RandomMultihashes(45) + c1Mhs := random.Multihashes(45) c1Lnk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(c1Mhs)) require.NoError(t, err) require.Equal(t, 1, subject.Len()) @@ -173,7 +173,7 @@ func testCachedEntriesChunker_NonOverlappingDagIsEvicted(t *testing.T, c chunker requireChunkEntriesMatch(t, gotC1Mhs, c1Mhs) // Cache a new, non-overlapping chain of length 2 and assert it is cached - c2Mhs := test.RandomMultihashes(15) + c2Mhs := random.Multihashes(15) c2Lnk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(c2Mhs)) require.NoError(t, err) gotC2Mhs := requireDecodeAllMultihashes(t, c2Lnk, subject.LinkSystem()) @@ -194,7 +194,7 @@ func testCachedEntriesChunker_PreviouslyCachedChunksAreRestored(t *testing.T, ca defer subject.Close() // Chunk and cache a multihash iterator. - c1Mhs := test.RandomMultihashes(50) + c1Mhs := random.Multihashes(50) c1Lnk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(c1Mhs)) require.NoError(t, err) @@ -203,7 +203,7 @@ func testCachedEntriesChunker_PreviouslyCachedChunksAreRestored(t *testing.T, ca requireChunkEntriesMatch(t, gotC1Mhs, c1Mhs) // Chunk another iterator. - c2Mhs := test.RandomMultihashes(12) + c2Mhs := random.Multihashes(12) c2Lnk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(c2Mhs)) require.NoError(t, err) @@ -212,7 +212,7 @@ func testCachedEntriesChunker_PreviouslyCachedChunksAreRestored(t *testing.T, ca requireChunkEntriesMatch(t, gotC2Mhs, c2Mhs) // Chunk and cache another multihash iterators with overlapping section. - c3Mhs := test.RandomMultihashes(13) + c3Mhs := random.Multihashes(13) require.NoError(t, err) c3Mhs = append(c2Mhs, c3Mhs...) c3Lnk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(c3Mhs)) @@ -256,7 +256,7 @@ func TestCachedEntriesChunker_OverlappingDagIsNotEvicted(t *testing.T) { // 2. Its entries match the original CIDs // 3. The length of chain is 1, i.e. the chunk has no next since chunkSize = 10 // 4. The cache length is 1. - c1Mhs := test.RandomMultihashes(10) + c1Mhs := random.Multihashes(10) require.NoError(t, err) c1Lnk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(c1Mhs)) require.NoError(t, err) @@ -274,7 +274,7 @@ func TestCachedEntriesChunker_OverlappingDagIsNotEvicted(t *testing.T) { // 3. The first entry in chain has all the newly generated CIDs // 4. The second entry in chain is identical to c1. // 5. The length of cache is still 1. - extraMhs := test.RandomMultihashes(10) + extraMhs := random.Multihashes(10) require.NoError(t, err) c2Mhs := append(c1Mhs, extraMhs...) c2Lnk, err := subject.Chunk(ctx, provider.SliceMultihashIterator(c2Mhs)) @@ -306,7 +306,7 @@ func testCachedEntriesChunker_RecoversFromCorruptCacheGracefully(t *testing.T, c defer subject.Close() // Chunk some data first which we won't corrupt to test partial corruption. - wantMhs1 := test.RandomMultihashes(10) + wantMhs1 := random.Multihashes(10) require.NoError(t, err) chunkLink1, err := subject.Chunk(ctx, provider.SliceMultihashIterator(wantMhs1)) require.NoError(t, err) @@ -317,7 +317,7 @@ func testCachedEntriesChunker_RecoversFromCorruptCacheGracefully(t *testing.T, c require.Equal(t, 1, subject.Len()) // Chunk some more data which we will corrupt. - wantMhs2 := test.RandomMultihashes(10) + wantMhs2 := random.Multihashes(10) require.NoError(t, err) chunkLink2, err := subject.Chunk(ctx, provider.SliceMultihashIterator(wantMhs2)) require.NoError(t, err) @@ -371,7 +371,7 @@ func testCachedEntriesChunker_PurgesCacheSuccessfullyEvenIfCorrupted(t *testing. defer subject.Close() // Chunk some data - wantMhs1 := test.RandomMultihashes(10) + wantMhs1 := random.Multihashes(10) require.NoError(t, err) chunkLink1, err := subject.Chunk(ctx, provider.SliceMultihashIterator(wantMhs1)) require.NoError(t, err) @@ -408,7 +408,7 @@ func testCachedEntriesChunker_PurgesCacheSuccessfully(t *testing.T, capacity int defer subject.Close() // Chunk some data - wantMhs1 := test.RandomMultihashes(10) + wantMhs1 := random.Multihashes(10) require.NoError(t, err) chunkLink1, err := subject.Chunk(ctx, provider.SliceMultihashIterator(wantMhs1)) require.NoError(t, err) @@ -440,7 +440,7 @@ func testCachedEntriesChunker_OldFormatIsHandledGracefully(t *testing.T, capacit defer subject.Close() // Chunk and cache a multihash iterator. - root, err := subject.Chunk(ctx, provider.SliceMultihashIterator(test.RandomMultihashes(50))) + root, err := subject.Chunk(ctx, provider.SliceMultihashIterator(random.Multihashes(50))) require.NoError(t, err) // Close off the test subject diff --git a/engine/chunker/chain_chunker_test.go b/engine/chunker/chain_chunker_test.go index 2f5ad73e..fde20ad9 100644 --- a/engine/chunker/chain_chunker_test.go +++ b/engine/chunker/chain_chunker_test.go @@ -4,11 +4,11 @@ import ( "context" "testing" + "github.com/ipfs/go-test/random" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/ipld/go-ipld-prime/storage/memstore" "github.com/ipni/go-libipni/ingest/schema" - "github.com/ipni/go-libipni/test" provider "github.com/ipni/index-provider" "github.com/ipni/index-provider/engine/chunker" "github.com/stretchr/testify/require" @@ -18,7 +18,7 @@ func TestChainChunker_Chunk(t *testing.T) { ctx := context.TODO() ls := cidlink.DefaultLinkSystem() chunkHasExpectedMhs := func(t *testing.T, subject chunker.EntriesChunker) { - mhs := test.RandomMultihashes(100) + mhs := random.Multihashes(100) l, err := subject.Chunk(ctx, provider.SliceMultihashIterator(mhs)) require.NoError(t, err) diff --git a/engine/chunker/hamt_chunker_test.go b/engine/chunker/hamt_chunker_test.go index 539c5962..4c7afc99 100644 --- a/engine/chunker/hamt_chunker_test.go +++ b/engine/chunker/hamt_chunker_test.go @@ -4,12 +4,12 @@ import ( "context" "testing" + "github.com/ipfs/go-test/random" hamt "github.com/ipld/go-ipld-adl-hamt" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/ipld/go-ipld-prime/node/bindnode" "github.com/ipld/go-ipld-prime/storage/memstore" - "github.com/ipni/go-libipni/test" provider "github.com/ipni/index-provider" "github.com/ipni/index-provider/engine/chunker" "github.com/multiformats/go-multicodec" @@ -85,7 +85,7 @@ func TestHamtChunker_Chunk(t *testing.T) { ctx := context.TODO() ls := cidlink.DefaultLinkSystem() chunkHasExpectedMhs := func(t *testing.T, subject chunker.EntriesChunker) { - mhs := test.RandomMultihashes(100) + mhs := random.Multihashes(100) l, err := subject.Chunk(ctx, provider.SliceMultihashIterator(mhs)) require.NoError(t, err) diff --git a/engine/engine_test.go b/engine/engine_test.go index b0b1d1e7..56386796 100644 --- a/engine/engine_test.go +++ b/engine/engine_test.go @@ -13,6 +13,7 @@ import ( "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" leveldb "github.com/ipfs/go-ds-leveldb" + "github.com/ipfs/go-test/random" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/ipld/go-ipld-prime/node/basicnode" @@ -23,7 +24,6 @@ import ( "github.com/ipni/go-libipni/dagsync/ipnisync" "github.com/ipni/go-libipni/ingest/schema" "github.com/ipni/go-libipni/metadata" - "github.com/ipni/go-libipni/test" provider "github.com/ipni/index-provider" "github.com/ipni/index-provider/engine" "github.com/ipni/index-provider/testutil" @@ -46,7 +46,7 @@ func TestEngine_NotifyRemoveWithUnknownContextIDIsError(t *testing.T) { func Test_NewEngineWithNoPublisherAndRoot(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) - mhs := test.RandomMultihashes(1) + mhs := random.Multihashes(1) contextID := []byte("fish") subject, err := engine.New(engine.WithPublisherKind(engine.NoPublisher)) @@ -72,7 +72,7 @@ func TestEngine_PublishLocal(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) - mhs := test.RandomMultihashes(42) + mhs := random.Multihashes(42) subject, err := engine.New() require.NoError(t, err) @@ -112,7 +112,7 @@ func TestEngine_PublishWithLibp2pHttpPublisher(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) - mhs := test.RandomMultihashes(42) + mhs := random.Multihashes(42) wantExtraGossipData := []byte("🐠") // Use test name as gossip topic name for uniqueness per test. @@ -342,7 +342,7 @@ func TestEngine_NotifyPutThenNotifyRemove(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) - mhs := test.RandomMultihashes(42) + mhs := random.Multihashes(42) subject, err := engine.New() require.NoError(t, err) @@ -380,7 +380,7 @@ func TestEngine_NotifyRemoveWithDefaultProvider(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) - mhs := test.RandomMultihashes(42) + mhs := random.Multihashes(42) subject, err := engine.New() require.NoError(t, err) @@ -412,7 +412,7 @@ func TestEngine_NotifyRemoveWithCustomProvider(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) - mhs := test.RandomMultihashes(42) + mhs := random.Multihashes(42) subject, err := engine.New() require.NoError(t, err) @@ -428,7 +428,7 @@ func TestEngine_NotifyRemoveWithCustomProvider(t *testing.T) { return nil, errors.New("not found") }) - providerId, _, _ := test.RandomIdentity() + providerId, _, _ := random.Identity() providerAddrs, _ := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/1234/http") _, err = subject.NotifyPut(ctx, &peer.AddrInfo{ID: providerId, Addrs: []multiaddr.Multiaddr{providerAddrs}}, wantContextID, metadata.Default.New(metadata.Bitswap{})) @@ -446,13 +446,13 @@ func TestEngine_ProducesSingleChainForMultipleProviders(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) - randMhs := test.RandomMultihashes(84) + randMhs := random.Multihashes(84) mhs1 := randMhs[:42] mhs2 := randMhs[42:] - provider1id, _, _ := test.RandomIdentity() + provider1id, _, _ := random.Identity() provider1Addrs, _ := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/1234/http") - provider2id, _, _ := test.RandomIdentity() + provider2id, _, _ := random.Identity() provider2Addrs, _ := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/4321/http") subject, err := engine.New() @@ -499,7 +499,7 @@ func TestEngine_NotifyPutUseDefaultProviderAndAddressesWhenNoneGiven(t *testing. ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) - mhs := test.RandomMultihashes(42) + mhs := random.Multihashes(42) subject, err := engine.New() require.NoError(t, err) @@ -531,7 +531,7 @@ func TestEngine_VerifyErrAlreadyAdvertised(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) - mhs := test.RandomMultihashes(42) + mhs := random.Multihashes(42) subject, err := engine.New() require.NoError(t, err) @@ -554,7 +554,7 @@ func TestEngine_VerifyErrAlreadyAdvertised(t *testing.T) { _, err = subject.NotifyPut(ctx, nil, wantContextID, metadata.Default.New(metadata.Bitswap{})) require.Error(t, err, provider.ErrAlreadyAdvertised) - p, _, _ := test.RandomIdentity() + p, _, _ := random.Identity() _, err = subject.NotifyPut(ctx, &peer.AddrInfo{ID: p}, wantContextID, metadata.Default.New(metadata.Bitswap{})) require.NoError(t, err, provider.ErrAlreadyAdvertised) } @@ -563,11 +563,11 @@ func TestEngine_ShouldHaveSameChunksInChunkerForSameCIDs(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), testTimeout) t.Cleanup(cancel) - mhs := test.RandomMultihashes(42) + mhs := random.Multihashes(42) - provider1id, _, _ := test.RandomIdentity() + provider1id, _, _ := random.Identity() provider1Addrs, _ := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/1234/http") - provider2id, _, _ := test.RandomIdentity() + provider2id, _, _ := random.Identity() provider2Addrs, _ := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/4321/http") subject, err := engine.New() @@ -664,7 +664,7 @@ func TestEngine_DatastoreBackwardsCompatibilityTest(t *testing.T) { mmap := make(map[string][]multihash.Multihash) subject.RegisterMultihashLister(func(ctx context.Context, p peer.ID, contextID []byte) (provider.MultihashIterator, error) { if _, ok := mmap[string(contextID)]; !ok { - mmap[string(contextID)] = test.RandomMultihashes(42) + mmap[string(contextID)] = random.Multihashes(42) } return provider.SliceMultihashIterator(mmap[string(contextID)]), nil }) @@ -680,7 +680,7 @@ func TestEngine_DatastoreBackwardsCompatibilityTest(t *testing.T) { require.NoError(t, err) // try publishing for new provider - newPID, _, _ := test.RandomIdentity() + newPID, _, _ := random.Identity() _, err = subject.NotifyPut(ctx, &peer.AddrInfo{ID: newPID}, []byte("has"), metadata.Default.New(metadata.Bitswap{})) require.NoError(t, err) diff --git a/engine/linksystem_test.go b/engine/linksystem_test.go index fad64657..ac532eb0 100644 --- a/engine/linksystem_test.go +++ b/engine/linksystem_test.go @@ -8,13 +8,13 @@ import ( "time" "github.com/ipfs/go-cid" + "github.com/ipfs/go-test/random" "github.com/ipld/go-car/v2/index" "github.com/ipld/go-ipld-prime" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/ipld/go-ipld-prime/multicodec" "github.com/ipni/go-libipni/ingest/schema" "github.com/ipni/go-libipni/metadata" - "github.com/ipni/go-libipni/test" provider "github.com/ipni/index-provider" "github.com/ipni/index-provider/engine" "github.com/ipni/index-provider/engine/chunker" @@ -51,7 +51,7 @@ func Test_RemovalAdvertisementWithNoEntriesIsRetrievable(t *testing.T) { defer subject.Shutdown() ctxID := []byte("added then removed content") - mhs := test.RandomCids(12) + mhs := random.Cids(12) require.NoError(t, err) // Register lister with removal handle @@ -112,18 +112,18 @@ func Test_EvictedCachedEntriesChainIsRegeneratedGracefully(t *testing.T) { require.NoError(t, err) defer subject.Shutdown() - otherProviderId, _, _ := test.RandomIdentity() + otherProviderId, _, _ := random.Identity() ad1CtxID := []byte("first") ad1MhCount := 12 wantAd1EntriesChainLen := ad1MhCount / chunkSize - ad1Mhs := test.RandomCids(ad1MhCount) + ad1Mhs := random.Cids(ad1MhCount) require.NoError(t, err) ad2CtxID := []byte("second") ad2MhCount := 10 wantAd2ChunkLen := ad2MhCount / chunkSize - ad2Mhs := test.RandomCids(ad2MhCount) + ad2Mhs := random.Cids(ad2MhCount) require.NoError(t, err) subject.RegisterMultihashLister(func(ctx context.Context, p peer.ID, contextID []byte) (provider.MultihashIterator, error) { diff --git a/engine/xproviders/xproviders_test.go b/engine/xproviders/xproviders_test.go index 4096980d..f688c872 100644 --- a/engine/xproviders/xproviders_test.go +++ b/engine/xproviders/xproviders_test.go @@ -6,9 +6,9 @@ import ( "time" "github.com/ipfs/go-cid" + "github.com/ipfs/go-test/random" cidlink "github.com/ipld/go-ipld-prime/linking/cid" "github.com/ipni/go-libipni/ingest/schema" - "github.com/ipni/go-libipni/test" "github.com/ipni/index-provider/engine" ep "github.com/ipni/index-provider/engine/xproviders" "github.com/libp2p/go-libp2p/core/peer" @@ -23,7 +23,7 @@ func TestPublish(t *testing.T) { defer cancel() contextID := []byte("test-context") - addrs := test.RandomMultiaddrs(2) + addrs := random.Multiaddrs(2) addrsStr := []string{addrs[0].String(), addrs[1].String()} metadata := []byte("thisismeta") eps := make([]ep.Info, 2) @@ -35,7 +35,7 @@ func TestPublish(t *testing.T) { require.NoError(t, err) defer eng.Shutdown() - providerID, priv, _ := test.RandomIdentity() + providerID, priv, _ := random.Identity() for i := 0; i < len(eps); i++ { epID, ep := randomExtendedProvider() @@ -93,7 +93,7 @@ func TestMainProviderShouldNotBeAddedAsExtendedIfItsAlreadyOnTheList(t *testing. defer cancel() contextID := []byte("test-context") - addrs := test.RandomMultiaddrs(2) + addrs := random.Multiaddrs(2) addrsStr := []string{addrs[0].String(), addrs[1].String()} metadata := []byte("thisismeta") @@ -103,7 +103,7 @@ func TestMainProviderShouldNotBeAddedAsExtendedIfItsAlreadyOnTheList(t *testing. require.NoError(t, err) defer eng.Shutdown() - providerID, priv, _ := test.RandomIdentity() + providerID, priv, _ := random.Identity() override := true adv, err := ep.NewAdBuilder(providerID, priv, addrs). @@ -138,10 +138,10 @@ func TestMainProviderShouldNotBeAddedAsExtendedIfItsAlreadyOnTheList(t *testing. } func TestExtendedProvidersShouldNotAllowEmptyAddresses(t *testing.T) { - addrs := test.RandomMultiaddrs(2) + addrs := random.Multiaddrs(2) metadata := []byte("thisismeta") - providerID, priv, _ := test.RandomIdentity() + providerID, priv, _ := random.Identity() _, err := ep.NewAdBuilder(providerID, priv, addrs). WithExtendedProviders(ep.NewInfo(providerID, priv, metadata, []multiaddr.Multiaddr{})). @@ -153,10 +153,10 @@ func TestExtendedProvidersShouldNotAllowEmptyAddresses(t *testing.T) { } func TestExtendedProvidersShouldAllowEmptyMetadata(t *testing.T) { - addrs := test.RandomMultiaddrs(2) + addrs := random.Multiaddrs(2) metadata := []byte("thisismeta") - providerID, priv, _ := test.RandomIdentity() + providerID, priv, _ := random.Identity() _, err := ep.NewAdBuilder(providerID, priv, addrs). WithExtendedProviders(ep.NewInfo(providerID, priv, []byte{}, addrs)). @@ -168,10 +168,10 @@ func TestExtendedProvidersShouldAllowEmptyMetadata(t *testing.T) { } func TestExtendedProvidersShouldNotAllowInvalidPeerIDs(t *testing.T) { - addrs := test.RandomMultiaddrs(2) + addrs := random.Multiaddrs(2) metadata := []byte("thisismeta") - providerID, priv, _ := test.RandomIdentity() + providerID, priv, _ := random.Identity() _, err := ep.NewAdBuilder(providerID, priv, addrs). WithExtendedProviders(ep.NewInfo("invalid", priv, []byte{}, addrs)). @@ -183,9 +183,9 @@ func TestExtendedProvidersShouldNotAllowInvalidPeerIDs(t *testing.T) { } func TestExtendedProvidersShouldAllowEntries(t *testing.T) { - addrs := test.RandomMultiaddrs(1) - providerID, priv, _ := test.RandomIdentity() - entries := test.RandomCids(1)[0] + addrs := random.Multiaddrs(1) + providerID, priv, _ := random.Identity() + entries := random.Cids(1)[0] ad, err := ep.NewAdBuilder(providerID, priv, addrs). WithEntries(entries). @@ -199,10 +199,10 @@ func TestExtendedProvidersShouldAllowEntries(t *testing.T) { } func TestZeroExtendedProvidersShouldStillCreateExtendedProvidersField(t *testing.T) { - addrs := test.RandomMultiaddrs(2) + addrs := random.Multiaddrs(2) metadata := []byte("thisismeta") - providerID, priv, _ := test.RandomIdentity() + providerID, priv, _ := random.Identity() ad, err := ep.NewAdBuilder(providerID, priv, addrs). WithOverride(true). @@ -218,7 +218,7 @@ func TestMainProviderShouldNotBeAddedAsExtendedIfThereAreNoOthers(t *testing.T) ctx, cancel := context.WithTimeout(context.Background(), testTimeout) defer cancel() contextID := []byte("test-context") - addrs := test.RandomMultiaddrs(2) + addrs := random.Multiaddrs(2) addrsStr := []string{addrs[0].String(), addrs[1].String()} metadata := []byte("thisismeta") @@ -228,7 +228,7 @@ func TestMainProviderShouldNotBeAddedAsExtendedIfThereAreNoOthers(t *testing.T) require.NoError(t, err) defer eng.Shutdown() - providerID, priv, _ := test.RandomIdentity() + providerID, priv, _ := random.Identity() override := true adv, err := ep.NewAdBuilder(providerID, priv, addrs). @@ -257,7 +257,7 @@ func TestMainProviderShouldNotBeAddedAsExtendedIfThereAreNoOthers(t *testing.T) } func TestPublishFailsIfOverrideIsTrueWithNoContextId(t *testing.T) { - addrs := test.RandomMultiaddrs(2) + addrs := random.Multiaddrs(2) metadata := []byte("thisismeta") eps := make([]ep.Info, 2) epIds := make([]peer.ID, len(eps)) @@ -266,7 +266,7 @@ func TestPublishFailsIfOverrideIsTrueWithNoContextId(t *testing.T) { eps[i] = ep epIds[i] = epID } - providerID, priv, _ := test.RandomIdentity() + providerID, priv, _ := random.Identity() _, err := ep.NewAdBuilder(providerID, priv, addrs). WithExtendedProviders(eps...). @@ -278,8 +278,8 @@ func TestPublishFailsIfOverrideIsTrueWithNoContextId(t *testing.T) { } func randomExtendedProvider() (peer.ID, ep.Info) { - providerID, priv, _ := test.RandomIdentity() + providerID, priv, _ := random.Identity() metadata := []byte("thisismeta") - addrs := test.RandomMultiaddrs(2) + addrs := random.Multiaddrs(2) return providerID, ep.NewInfo(providerID, priv, metadata, addrs) } diff --git a/go.mod b/go.mod index 7eaabccc..37bc5d88 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/ipfs/go-ds-leveldb v0.5.0 github.com/ipfs/go-graphsync v0.17.0 github.com/ipfs/go-log/v2 v2.5.1 + github.com/ipfs/go-test v0.0.2 github.com/ipld/go-car/v2 v2.13.1 github.com/ipld/go-codec-dagpb v1.6.0 github.com/ipld/go-ipld-adl-hamt v0.0.0-20240322071803-376decb85801 diff --git a/go.sum b/go.sum index edd7ed97..4aa551bb 100644 --- a/go.sum +++ b/go.sum @@ -349,6 +349,8 @@ github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fG github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= github.com/ipfs/go-peertaskqueue v0.8.1 h1:YhxAs1+wxb5jk7RvS0LHdyiILpNmRIRnZVztekOF0pg= github.com/ipfs/go-peertaskqueue v0.8.1/go.mod h1:Oxxd3eaK279FxeydSPPVGHzbwVeHjatZ2GA8XD+KbPU= +github.com/ipfs/go-test v0.0.2 h1:Wdxl4bKEdjEM8SLiulXMHlAQwHYOhX3CSBoUoEvncmM= +github.com/ipfs/go-test v0.0.2/go.mod h1:qhIM1EluEfElKKM6fnWxGn822/z9knUGM1+I/OAQNKI= github.com/ipfs/go-unixfs v0.4.5 h1:wj8JhxvV1G6CD7swACwSKYa+NgtdWC1RUit+gFnymDU= github.com/ipfs/go-unixfs v0.4.5/go.mod h1:BIznJNvt/gEx/ooRMI4Us9K8+qeGO7vx1ohnbk8gjFg= github.com/ipfs/go-unixfsnode v1.9.0 h1:ubEhQhr22sPAKO2DNsyVBW7YB/zA8Zkif25aBvz8rc8= diff --git a/mirror/mirror_test.go b/mirror/mirror_test.go index 0216b173..ce33cb39 100644 --- a/mirror/mirror_test.go +++ b/mirror/mirror_test.go @@ -6,11 +6,11 @@ import ( "time" "github.com/ipfs/go-cid" + "github.com/ipfs/go-test/random" cidlink "github.com/ipld/go-ipld-prime/linking/cid" selectorparse "github.com/ipld/go-ipld-prime/traversal/selector/parse" "github.com/ipni/go-libipni/ingest/schema" "github.com/ipni/go-libipni/metadata" - "github.com/ipni/go-libipni/test" "github.com/ipni/index-provider/engine" "github.com/ipni/index-provider/mirror" "github.com/multiformats/go-multihash" @@ -21,7 +21,6 @@ const ( testContextTimeout = 10 * time.Second testEventualTimeout = testContextTimeout / 2 testCheckInterval = testEventualTimeout / 10 - testRandomSeed = 1413 ) func newTestContext(t *testing.T) context.Context { @@ -32,10 +31,10 @@ func newTestContext(t *testing.T) context.Context { func TestMirror_PutAdIsMirrored(t *testing.T) { ctx := newTestContext(t) - wantMhs := test.RandomMultihashes(42) + wantMhs := random.Multihashes(42) wantCtxID := []byte("fish") wantMetadata := metadata.Default.New(metadata.Bitswap{}, &metadata.GraphsyncFilecoinV1{ - PieceCID: test.RandomCids(1)[0], + PieceCID: random.Cids(1)[0], VerifiedDeal: true, }) @@ -70,9 +69,9 @@ func TestMirror_IsAlsoCdnForOriginalAds(t *testing.T) { te.startSource(t, ctx, engine.WithPublisherKind(engine.Libp2pPublisher)) // Publish a bunch of ads on the original provider - ad1 := te.putAdOnSource(t, ctx, []byte("ad1"), test.RandomMultihashes(3), md) - ad2 := te.putAdOnSource(t, ctx, []byte("ad2"), test.RandomMultihashes(4), md) - ad3 := te.putAdOnSource(t, ctx, []byte("ad3"), test.RandomMultihashes(5), md) + ad1 := te.putAdOnSource(t, ctx, []byte("ad1"), random.Multihashes(3), md) + ad2 := te.putAdOnSource(t, ctx, []byte("ad2"), random.Multihashes(4), md) + ad3 := te.putAdOnSource(t, ctx, []byte("ad3"), random.Multihashes(5), md) ad4 := te.removeAdOnSource(t, ctx, []byte("ad1")) // Start a mirror for the original provider with reduced tick time for faster test turnaround. @@ -106,9 +105,9 @@ func TestMirror_FormsExpectedAdChain(t *testing.T) { te.startSource(t, ctx, engine.WithPublisherKind(engine.Libp2pPublisher)) // Publish a bunch of ads on the original provider - _ = te.putAdOnSource(t, ctx, []byte("ad1"), test.RandomMultihashes(3), md) - _ = te.putAdOnSource(t, ctx, []byte("ad2"), test.RandomMultihashes(4), md) - _ = te.putAdOnSource(t, ctx, []byte("ad3"), test.RandomMultihashes(5), md) + _ = te.putAdOnSource(t, ctx, []byte("ad1"), random.Multihashes(3), md) + _ = te.putAdOnSource(t, ctx, []byte("ad2"), random.Multihashes(4), md) + _ = te.putAdOnSource(t, ctx, []byte("ad3"), random.Multihashes(5), md) originalHeadAdCid := te.removeAdOnSource(t, ctx, []byte("ad1")) // Start a mirror for the original provider with reduced tick time for faster test turnaround. @@ -190,13 +189,13 @@ func TestMirror_FormsExpectedAdChainRemap(t *testing.T) { te.startSource(t, ctx, engine.WithPublisherKind(engine.Libp2pPublisher)) // Publish a bunch of ads on the original provider - _ = te.putAdOnSource(t, ctx, []byte("ad1"), test.RandomMultihashes(1), md) - _ = te.putAdOnSource(t, ctx, []byte("ad2"), test.RandomMultihashes(400), md) + _ = te.putAdOnSource(t, ctx, []byte("ad1"), random.Multihashes(1), md) + _ = te.putAdOnSource(t, ctx, []byte("ad2"), random.Multihashes(400), md) _ = te.removeAdOnSource(t, ctx, []byte("ad1")) - _ = te.putAdOnSource(t, ctx, []byte("ad3"), test.RandomMultihashes(1), md) - _ = te.putAdOnSource(t, ctx, []byte("ad4"), test.RandomMultihashes(2), md) + _ = te.putAdOnSource(t, ctx, []byte("ad3"), random.Multihashes(1), md) + _ = te.putAdOnSource(t, ctx, []byte("ad4"), random.Multihashes(2), md) _ = te.removeAdOnSource(t, ctx, []byte("ad2")) - originalHeadAdCid := te.putAdOnSource(t, ctx, []byte("ad5"), test.RandomMultihashes(7), md) + originalHeadAdCid := te.putAdOnSource(t, ctx, []byte("ad5"), random.Multihashes(7), md) testCase.mirrorOptions = append(testCase.mirrorOptions, mirror.WithSyncInterval(time.Second)) te.startMirror(t, ctx, testCase.mirrorOptions...) @@ -230,9 +229,9 @@ func TestMirror_PreviousIDIsPreservedOnStartFromPartialAdChain(t *testing.T) { te := &testEnv{} // Start source and publish 3 ads. te.startSource(t, ctx, engine.WithPublisherKind(engine.Libp2pPublisher)) - originalACid := te.putAdOnSource(t, ctx, []byte("ad1"), test.RandomMultihashes(1), md) - originalBCid := te.putAdOnSource(t, ctx, []byte("ad2"), test.RandomMultihashes(2), md) - orignalHeadCid := te.putAdOnSource(t, ctx, []byte("ad3"), test.RandomMultihashes(3), md) + originalACid := te.putAdOnSource(t, ctx, []byte("ad1"), random.Multihashes(1), md) + originalBCid := te.putAdOnSource(t, ctx, []byte("ad2"), random.Multihashes(2), md) + orignalHeadCid := te.putAdOnSource(t, ctx, []byte("ad3"), random.Multihashes(3), md) // Start mirror with maximum initial depth of 2. te.startMirror(t, ctx, mirror.WithSyncInterval(time.Second), mirror.WithInitialAdRecursionLimit(2)) @@ -285,10 +284,10 @@ func TestMirror_MirrorsAdsIdenticallyWhenConfiguredTo(t *testing.T) { te := &testEnv{} // Start source and publish 3 ads. te.startSource(t, ctx, engine.WithPublisherKind(engine.Libp2pPublisher)) - _ = te.putAdOnSource(t, ctx, []byte("ad1"), test.RandomMultihashes(1), md) - _ = te.putAdOnSource(t, ctx, []byte("ad2"), test.RandomMultihashes(2), md) + _ = te.putAdOnSource(t, ctx, []byte("ad1"), random.Multihashes(1), md) + _ = te.putAdOnSource(t, ctx, []byte("ad2"), random.Multihashes(2), md) _ = te.removeAdOnSource(t, ctx, []byte("ad1")) - originalHeadCid := te.putAdOnSource(t, ctx, []byte("ad3"), test.RandomMultihashes(3), md) + originalHeadCid := te.putAdOnSource(t, ctx, []byte("ad3"), random.Multihashes(3), md) te.startMirror(t, ctx, mirror.WithSyncInterval(time.Second), mirror.WithAlwaysReSignAds(false)) diff --git a/server/admin/http/car_handler_test.go b/server/admin/http/car_handler_test.go index b4eae0d1..1aa7ddb8 100644 --- a/server/admin/http/car_handler_test.go +++ b/server/admin/http/car_handler_test.go @@ -14,8 +14,8 @@ import ( "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" dssync "github.com/ipfs/go-datastore/sync" + "github.com/ipfs/go-test/random" "github.com/ipni/go-libipni/metadata" - "github.com/ipni/go-libipni/test" provider "github.com/ipni/index-provider" "github.com/ipni/index-provider/cardatatransfer" mock_provider "github.com/ipni/index-provider/mock" @@ -58,7 +58,7 @@ func Test_importCarHandler(t *testing.T) { rr := httptest.NewRecorder() handler := http.HandlerFunc(subject.handleImport) - randCids := test.RandomCids(1) + randCids := random.Cids(1) require.NoError(t, err) wantCid := randCids[0] @@ -183,7 +183,7 @@ func Test_removeCarHandler(t *testing.T) { rr := httptest.NewRecorder() handler := http.HandlerFunc(subject.handleRemove) - wantCid := test.RandomCids(1)[0] + wantCid := random.Cids(1)[0] requireMockPut(t, mockEng, nil, wantKey, cs) mockEng. @@ -306,7 +306,7 @@ func requireRemoveCarHttpRequest(t *testing.T, body io.Reader) *http.Request { func requireMockPut(t *testing.T, mockEng *mock_provider.MockInterface, provider *peer.AddrInfo, key []byte, cs *supplier.CarSupplier) { wantTp, err := cardatatransfer.TransportFromContextID(key) require.NoError(t, err) - wantCid := test.RandomCids(1)[0] + wantCid := random.Cids(1)[0] wantMetadata := metadata.Default.New(wantTp) mockEng. @@ -351,7 +351,7 @@ func Test_ListCarHandler(t *testing.T) { require.NoError(t, err) require.Len(t, respBeforePut.Paths, 0) - randCids := test.RandomCids(1) + randCids := random.Cids(1) require.NoError(t, err) wantCid := randCids[0]