testutil

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: Apache-2.0, MIT Imports: 37 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 GenerateMultiaddr added in v0.10.0

func GenerateMultiaddr() multiaddr.Multiaddr

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, afterStart time.Duration, expectedList []types.RetrievalEvent, actual types.RetrievalEvent) types.EventCode

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, afterStart time.Duration, 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
	ServedRetrievals     []RemoteStats
	CompletedRetrievals  []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, afterStart time.Duration, 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, afterStart time.Duration, 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) VerifyRetrievalsCompleted added in v0.10.0

func (mc *MockClient) VerifyRetrievalsCompleted(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)

func (*MockClient) VerifyRetrievalsReceived added in v0.7.0

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

func (*MockClient) VerifyRetrievalsServed added in v0.10.0

func (mc *MockClient) VerifyRetrievalsServed(ctx context.Context, t *testing.T, afterStart time.Duration, expectedServed []RemoteStats)

type MockRoundTripRemote added in v0.10.0

type MockRoundTripRemote struct {
	Peer       peer.AddrInfo
	LinkSystem linking.LinkSystem
	Selector   ipld.Node
	RespondAt  time.Time
	Malformed  bool
}

type MockRoundTripper added in v0.10.0

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

func NewMockRoundTripper added in v0.10.0

func NewMockRoundTripper(
	t *testing.T,
	ctx context.Context,
	clock *clock.Mock,
	remoteBlockDuration time.Duration,
	expectedPath map[cid.Cid]string,
	expectedScope map[cid.Cid]types.CarScope,
	remotes map[cid.Cid][]MockRoundTripRemote,
) *MockRoundTripper

func (*MockRoundTripper) RoundTrip added in v0.10.0

func (mrt *MockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

func (*MockRoundTripper) VerifyConnectionsReceived added in v0.10.0

func (mrt *MockRoundTripper) VerifyConnectionsReceived(ctx context.Context, t *testing.T, afterStart time.Duration, expectedConnections []peer.ID)

func (*MockRoundTripper) VerifyRetrievalsCompleted added in v0.10.0

func (mrt *MockRoundTripper) VerifyRetrievalsCompleted(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)

func (*MockRoundTripper) VerifyRetrievalsReceived added in v0.10.0

func (mrt *MockRoundTripper) VerifyRetrievalsReceived(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)

func (*MockRoundTripper) VerifyRetrievalsServed added in v0.10.0

func (mrt *MockRoundTripper) VerifyRetrievalsServed(ctx context.Context, t *testing.T, afterStart time.Duration, expectedServed []RemoteStats)

type RemoteStats added in v0.10.0

type RemoteStats struct {
	Peer      peer.ID
	Root      cid.Cid
	ByteCount uint64
	Blocks    []cid.Cid
	Err       struct{}
}

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,
	client VerifierClient,
	mockCandidateFinder *MockCandidateFinder,
	runRetrievals []RunRetrieval,
) []types.RetrievalResult

type RunRetrieval added in v0.7.0

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

type VerifierClient added in v0.10.0

type VerifierClient interface {
	VerifyConnectionsReceived(ctx context.Context, t *testing.T, afterStart time.Duration, expectedConnections []peer.ID)
	VerifyRetrievalsReceived(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)
	VerifyRetrievalsServed(ctx context.Context, t *testing.T, afterStart time.Duration, expectedServed []RemoteStats)
	VerifyRetrievalsCompleted(ctx context.Context, t *testing.T, afterStart time.Duration, expectedRetrievals []peer.ID)
}

Jump to

Keyboard shortcuts

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