testutil

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2023 License: Apache-2.0, MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateBlocksOfSize

func GenerateBlocksOfSize(n int, size int64) []blocks.Block

GenerateBlocksOfSize generates a series of blocks of the given byte size

func GenerateCid

func GenerateCid() cid.Cid

GenerateCid produces a content identifier.

func GenerateCids

func GenerateCids(n int) []cid.Cid

GenerateCids produces n content identifiers.

func GeneratePeers

func GeneratePeers(t *testing.T, n int) []peer.ID

GeneratePeers creates n peer ids.

func GenerateRetrievalCandidates

func GenerateRetrievalCandidates(t *testing.T, n int, protocols ...metadata.Protocol) []types.RetrievalCandidate

GenerateRetrievalCandidates produces n retrieval candidates

func GenerateRetrievalCandidatesForCID added in v0.8.1

func GenerateRetrievalCandidatesForCID(t *testing.T, n int, c cid.Cid, protocols ...metadata.Protocol) []types.RetrievalCandidate

GenerateRetrievalCandidates produces n retrieval candidates

func GenerateRetrievalIDs

func GenerateRetrievalIDs(t *testing.T, n int) []types.RetrievalID

func GenerateRetrievalRequests added in v0.6.0

func GenerateRetrievalRequests(t *testing.T, n int) []types.RetrievalRequest

GenerateRetrievalRequests produces retrieval requests

func RandomBytes

func RandomBytes(n int64) []byte

RandomBytes returns a byte array of the given size with random values.

func VerifyCollectedEvent

func VerifyCollectedEvent(t *testing.T, actual types.RetrievalEvent, expected types.RetrievalEvent)

func VerifyCollectedEventTimings

func VerifyCollectedEventTimings(t *testing.T, events []types.RetrievalEvent)

func VerifyContainsCollectedEvent

func VerifyContainsCollectedEvent(t *testing.T, expectedList []types.RetrievalEvent, actual types.RetrievalEvent)

Types

type AsyncCollectingEventsListener added in v0.7.0

type AsyncCollectingEventsListener struct {
	// contains filtered or unexported fields
}

func NewAsyncCollectingEventsListener added in v0.7.0

func NewAsyncCollectingEventsListener(ctx context.Context) *AsyncCollectingEventsListener

func (*AsyncCollectingEventsListener) Collect added in v0.7.0

func (*AsyncCollectingEventsListener) VerifyNextEvents added in v0.7.0

func (ev *AsyncCollectingEventsListener) VerifyNextEvents(t *testing.T, expectedEvents []types.RetrievalEvent)

type ClientRetrievalRequest added in v0.7.0

type ClientRetrievalRequest struct {
	Peer     peer.ID
	Proposal *retrievaltypes.DealProposal
	Selector ipld.Node
}

type CollectingEventsListener

type CollectingEventsListener struct {
	CollectedEvents []types.RetrievalEvent
	// contains filtered or unexported fields
}

func NewCollectingEventsListener

func NewCollectingEventsListener() *CollectingEventsListener

func (*CollectingEventsListener) Collect

func (el *CollectingEventsListener) Collect(event types.RetrievalEvent)

type DelayedClientReturn added in v0.7.0

type DelayedClientReturn struct {
	ResultStats *types.RetrievalStats
	ResultErr   error
	Delay       time.Duration
}

type DelayedConnectReturn added in v0.7.0

type DelayedConnectReturn struct {
	Err   error
	Delay time.Duration
}

type DiscoveredCandidate added in v0.7.0

type DiscoveredCandidate struct {
	Cid       cid.Cid
	Candidate types.RetrievalCandidate
}

type ExpectedActionsAtTime added in v0.7.0

type ExpectedActionsAtTime struct {
	AfterStart           time.Duration
	ReceivedConnections  []peer.ID
	ReceivedRetrievals   []peer.ID
	CandidatesDiscovered []DiscoveredCandidate
	ExpectedEvents       []types.RetrievalEvent
}

type MockCandidateFinder

type MockCandidateFinder struct {
	// contains filtered or unexported fields
}

func NewMockCandidateFinder added in v0.7.0

func NewMockCandidateFinder(err error, candidates map[cid.Cid][]types.RetrievalCandidate) *MockCandidateFinder

func (*MockCandidateFinder) FindCandidates

func (me *MockCandidateFinder) FindCandidates(ctx context.Context, cid cid.Cid) ([]types.RetrievalCandidate, error)

func (*MockCandidateFinder) FindCandidatesAsync

func (me *MockCandidateFinder) FindCandidatesAsync(ctx context.Context, c cid.Cid, cb func(types.RetrievalCandidate)) error

func (*MockCandidateFinder) VerifyCandidatesDiscovered added in v0.7.0

func (me *MockCandidateFinder) VerifyCandidatesDiscovered(ctx context.Context, t *testing.T, expectedCandidatesDiscovered []DiscoveredCandidate)

type MockClient

type MockClient struct {
	// contains filtered or unexported fields
}

func NewMockClient

func NewMockClient(connectReturns map[string]DelayedConnectReturn, retrievalReturns map[string]DelayedClientReturn, clock clock.Clock) *MockClient

func (*MockClient) Connect added in v0.7.0

func (mc *MockClient) Connect(
	ctx context.Context,
	minerPeer peer.AddrInfo,
) error

func (*MockClient) GetConnectReturns added in v0.7.0

func (mc *MockClient) GetConnectReturns() map[string]DelayedConnectReturn

func (*MockClient) GetReceivedLinkSystems

func (mc *MockClient) GetReceivedLinkSystems() []ipld.LinkSystem

func (*MockClient) GetRetrievalReturns

func (mc *MockClient) GetRetrievalReturns() map[string]DelayedClientReturn

func (*MockClient) RetrieveFromPeer

func (mc *MockClient) RetrieveFromPeer(
	ctx context.Context,
	linkSystem ipld.LinkSystem,
	peerID peer.ID,
	proposal *retrievaltypes.DealProposal,
	selector ipld.Node,
	maxBlocks uint64,
	eventsCallback datatransfer.Subscriber,
	gracefulShutdownRequested <-chan struct{},
) (*types.RetrievalStats, error)

func (*MockClient) SetConnectReturns added in v0.7.0

func (mc *MockClient) SetConnectReturns(connectReturns map[string]DelayedConnectReturn)

func (*MockClient) SetRetrievalReturns

func (mc *MockClient) SetRetrievalReturns(retrievalReturns map[string]DelayedClientReturn)

func (*MockClient) VerifyConnectionsReceived added in v0.7.0

func (mc *MockClient) VerifyConnectionsReceived(ctx context.Context, t *testing.T, expectedConnections []peer.ID)

func (*MockClient) VerifyReceivedRetrievalFrom added in v0.7.0

func (mc *MockClient) VerifyReceivedRetrievalFrom(ctx context.Context, t *testing.T, p peer.ID) ClientRetrievalRequest

func (*MockClient) VerifyRetrievalsReceived added in v0.7.0

func (mc *MockClient) VerifyRetrievalsReceived(ctx context.Context, t *testing.T, expectedRetrievals []peer.ID)

type RetrievalVerifier added in v0.7.0

type RetrievalVerifier struct {
	ExpectedSequence []ExpectedActionsAtTime
}

func (RetrievalVerifier) RunWithVerification added in v0.7.0

func (rv RetrievalVerifier) RunWithVerification(ctx context.Context, t *testing.T, clock *clock.Mock, mockClient *MockClient, mockCandidateFinder *MockCandidateFinder, runRetrievals []RunRetrieval) []types.RetrievalResult

type RunRetrieval added in v0.7.0

type RunRetrieval func(cb func(types.RetrievalEvent)) (*types.RetrievalStats, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL