testutil

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: Apache-2.0, MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertChannelEmpty added in v0.1.0

func AssertChannelEmpty(t TestingT, channel interface{}, errorMessage string)

AssertChannelEmpty verifies that a channel has no value currently

func AssertContainsBlock added in v0.1.0

func AssertContainsBlock(t TestingT, blks []blocks.Block, block blocks.Block)

AssertContainsBlock will fail a test if the block is not in the given block list

func AssertContainsPeer added in v0.1.0

func AssertContainsPeer(t TestingT, peers []peer.ID, p peer.ID)

AssertContainsPeer will fail a test if the peer is not in the given peer list

func AssertDoesReceive added in v0.1.0

func AssertDoesReceive(ctx context.Context, t TestingT, channel interface{}, errorMessage string)

AssertDoesReceive verifies that a channel returns some value before the given context closes

func AssertDoesReceiveFirst added in v0.1.0

func AssertDoesReceiveFirst(t TestingT, channel interface{}, errorMessage string, incorrectChannels ...interface{})

AssertDoesReceiveFirst asserts that the given channel receives a value before any of the other channels specified

func AssertReceive added in v0.1.0

func AssertReceive(ctx context.Context, t TestingT, channel interface{}, out interface{}, errorMessage string)

AssertReceive verifies that a channel returns a value before the given context closes, and writes into into out, which should be a pointer to the value type

func AssertReceiveFirst added in v0.1.0

func AssertReceiveFirst(t TestingT, channel interface{}, out interface{}, errorMessage string, incorrectChannels ...interface{})

AssertReceiveFirst verifies that a channel returns a value on the specified channel before the other channels, and writes the value into out, which should be a pointer to the value type

func AssertSends added in v0.1.0

func AssertSends(ctx context.Context, t TestingT, channel interface{}, in interface{}, errorMessage string)

AssertSends attempts to send the given input value to the given channel before the given context closes

func CollectErrors

func CollectErrors(ctx context.Context, t *testing.T, errChan <-chan error) []error

CollectErrors is just a utility to convert an error channel into an array.

func CollectResponses

func CollectResponses(ctx context.Context, t TestingT, responseChan <-chan graphsync.ResponseProgress) []graphsync.ResponseProgress

CollectResponses is just a utility to convert a graphsync response progress channel into an array.

func ContainsBlock

func ContainsBlock(blks []blocks.Block, block blocks.Block) bool

ContainsBlock returns true if a block is found n a list of blocks

func ContainsPeer

func ContainsPeer(peers []peer.ID, p peer.ID) bool

ContainsPeer returns true if a peer is found n a list of peers.

func GenerateBlocksOfSize

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

GenerateBlocksOfSize generates a series of blocks of the given byte size

func GenerateCids

func GenerateCids(n int) []cid.Cid

GenerateCids produces n content identifiers.

func GeneratePeers

func GeneratePeers(n int) []peer.ID

GeneratePeers creates n peer ids.

func IndexOf

func IndexOf(blks []blocks.Block, c cid.Cid) int

IndexOf returns the index of a given cid in an array of blocks

func NewFakeBlockData added in v0.1.0

func NewFakeBlockData() graphsync.BlockData

NewFakeBlockData returns a fake block that matches the block data interface

func NewInvalidSelectorSpec added in v0.1.0

func NewInvalidSelectorSpec() ipld.Node

NewInvalidSelectorSpec returns a spec that will fail when you attempt to validate it on the responder side

func NewTestLink() ipld.Link

NewTestLink returns a randomly generated IPLD Link

func NewTestStore added in v0.1.0

func NewTestStore(blocksWritten map[ipld.Link][]byte) (ipld.Loader, ipld.Storer)

NewTestStore provides a loader and storer for the given in memory link -> byte data map

func NewUnparsableSelectorSpec added in v0.1.0

func NewUnparsableSelectorSpec() ipld.Node

NewUnparsableSelectorSpec returns a spec that will fail when you attempt to validate it or decompose to a node + selector.

func RandomBytes

func RandomBytes(n int64) []byte

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

func ReadNResponses

func ReadNResponses(ctx context.Context, t TestingT, responseChan <-chan graphsync.ResponseProgress, count int) []graphsync.ResponseProgress

ReadNResponses does a partial read from a ResponseProgress channel -- up to n values

func RefuteContainsBlock added in v0.1.0

func RefuteContainsBlock(t TestingT, blks []blocks.Block, block blocks.Block)

RefuteContainsBlock will fail a test if the block is in the given block list

func RefuteContainsPeer added in v0.1.0

func RefuteContainsPeer(t TestingT, peers []peer.ID, p peer.ID)

RefuteContainsPeer will fail a test if the peer is in the given peer list

func VerifyEmptyErrors

func VerifyEmptyErrors(ctx context.Context, t TestingT, errChan <-chan error)

VerifyEmptyErrors verifies that no errors were sent over a channel before it was closed

func VerifyEmptyResponse

func VerifyEmptyResponse(ctx context.Context, t TestingT, responseChan <-chan graphsync.ResponseProgress)

VerifyEmptyResponse verifies that no response progress happened before the channel was closed.

func VerifyHasErrors added in v0.1.0

func VerifyHasErrors(ctx context.Context, t TestingT, errChan <-chan error)

VerifyHasErrors verifies that at least one error was sent over a channel

func VerifySingleTerminalError

func VerifySingleTerminalError(ctx context.Context, t TestingT, errChan <-chan error)

VerifySingleTerminalError verifies that exactly one error was sent over a channel and then the channel was closed.

Types

type DispatchedEvent added in v0.3.0

type DispatchedEvent struct {
	Topic notifications.Topic
	Event notifications.Event
}

type MockPublisher added in v0.3.0

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

func NewMockPublisher added in v0.3.0

func NewMockPublisher() *MockPublisher

func (*MockPublisher) AddNotifees added in v0.3.0

func (mp *MockPublisher) AddNotifees(notifees []notifications.Notifee)

func (*MockPublisher) PublishEvents added in v0.3.0

func (mp *MockPublisher) PublishEvents(events []notifications.Event)

func (*MockPublisher) PublishEventsOnTopicData added in v0.5.2

func (mp *MockPublisher) PublishEventsOnTopicData(data []notifications.TopicData, events []notifications.Event)

func (*MockPublisher) PublishMatchingEvents added in v0.3.0

func (mp *MockPublisher) PublishMatchingEvents(shouldPublish func(notifications.TopicData) bool, events []notifications.Event)

type NotifeeVerifier added in v0.3.0

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

func NewTestNotifee added in v0.3.0

func NewTestNotifee(data notifications.TopicData, bufferSize int) (notifications.Notifee, *NotifeeVerifier)

func (*NotifeeVerifier) ExpectClose added in v0.3.0

func (nv *NotifeeVerifier) ExpectClose(ctx context.Context, t *testing.T)

func (*NotifeeVerifier) ExpectEvents added in v0.3.0

func (nv *NotifeeVerifier) ExpectEvents(ctx context.Context, t *testing.T, events []notifications.Event)

type TestBlockChain added in v0.1.0

type TestBlockChain struct {
	GenisisNode ipld.Node
	GenisisLink ipld.Link
	MiddleNodes []ipld.Node
	MiddleLinks []ipld.Link
	TipNode     ipld.Node
	TipLink     ipld.Link
	// contains filtered or unexported fields
}

TestBlockChain is a simulated data structure similar to a blockchain which graphsync is uniquely suited for

func SetupBlockChain added in v0.1.0

func SetupBlockChain(
	ctx context.Context,
	t TestingT,
	loader ipld.Loader,
	storer ipld.Storer,
	size uint64,
	blockChainLength int) *TestBlockChain

SetupBlockChain creates a new test block chain with the given height

func (*TestBlockChain) AllBlocks added in v0.1.0

func (tbc *TestBlockChain) AllBlocks() []blocks.Block

AllBlocks returns all blocks for a blockchain

func (*TestBlockChain) Blocks added in v0.1.0

func (tbc *TestBlockChain) Blocks(from int, to int) []blocks.Block

Blocks Returns the given raw blocks for the block chain for the given range, indexed from the tip

func (*TestBlockChain) Chooser added in v0.1.0

func (tbc *TestBlockChain) Chooser(ipld.Link, ipld.LinkContext) (ipld.NodePrototype, error)

Chooser is a NodeBuilderChooser function that always returns the block chain

func (*TestBlockChain) LinkTipIndex added in v0.1.0

func (tbc *TestBlockChain) LinkTipIndex(fromTip int) ipld.Link

LinkTipIndex returns a link to the block at the given index from the tip

func (*TestBlockChain) NodeTipIndex added in v0.1.0

func (tbc *TestBlockChain) NodeTipIndex(fromTip int) ipld.Node

NodeTipIndex returns the node to the block at the given index from the tip

func (*TestBlockChain) RemainderBlocks added in v0.1.0

func (tbc *TestBlockChain) RemainderBlocks(from int) []blocks.Block

RemainderBlocks returns the remaining blocks for a blockchain, indexed from tip

func (*TestBlockChain) Selector added in v0.1.0

func (tbc *TestBlockChain) Selector() ipld.Node

Selector returns the selector to recursive traverse the block chain parent links

func (*TestBlockChain) VerifyRemainder added in v0.1.0

func (tbc *TestBlockChain) VerifyRemainder(ctx context.Context, responseChan <-chan graphsync.ResponseProgress, from int)

VerifyRemainder verifies the given response channel returns the remainder of the chain starting at the nth block from the tip

func (*TestBlockChain) VerifyRemainderSync added in v0.1.0

func (tbc *TestBlockChain) VerifyRemainderSync(responses []graphsync.ResponseProgress, from int)

VerifyRemainderSync verifies the given set of read responses are the remainder of the chain starting at the nth block from the tip

func (*TestBlockChain) VerifyRemainderWithTypes added in v0.1.0

func (tbc *TestBlockChain) VerifyRemainderWithTypes(ctx context.Context, responseChan <-chan graphsync.ResponseProgress, from int)

VerifyRemainderWithTypes verifies the given response channel returns the remainder of the chain starting at the nth block from the tip and that the types in the response are the expected types for a block chain

func (*TestBlockChain) VerifyResponseRange added in v0.1.0

func (tbc *TestBlockChain) VerifyResponseRange(ctx context.Context, responseChan <-chan graphsync.ResponseProgress, from int, to int)

VerifyResponseRange verifies the given response channel returns the given range of respnses, indexed from the tip (with possibly more data left in the channel)

func (*TestBlockChain) VerifyResponseRangeSync added in v0.1.0

func (tbc *TestBlockChain) VerifyResponseRangeSync(responses []graphsync.ResponseProgress, from int, to int)

VerifyResponseRangeSync verifies given set of read responses match responses for the given range of the blockchain, indexed from the tip (with possibly more data left in the channel)

func (*TestBlockChain) VerifyWholeChain added in v0.1.0

func (tbc *TestBlockChain) VerifyWholeChain(ctx context.Context, responseChan <-chan graphsync.ResponseProgress)

VerifyWholeChain verifies the given response channel returns the expected responses for the whole chain

func (*TestBlockChain) VerifyWholeChainSync added in v0.1.0

func (tbc *TestBlockChain) VerifyWholeChainSync(responses []graphsync.ResponseProgress)

VerifyWholeChainSync verifies the given set of read responses are the expected responses for the whole chain

func (*TestBlockChain) VerifyWholeChainWithTypes added in v0.1.0

func (tbc *TestBlockChain) VerifyWholeChainWithTypes(ctx context.Context, responseChan <-chan graphsync.ResponseProgress)

VerifyWholeChainWithTypes verifies the given response channel returns the expected responses for the whole chain and that the types in the response are the expected types for a block chain

type TestIPLDTree added in v0.1.0

type TestIPLDTree struct {
	Storage           map[ipld.Link][]byte
	LeafAlpha         ipld.Node
	LeafAlphaLnk      ipld.Link
	LeafAlphaBlock    blocks.Block
	LeafBeta          ipld.Node
	LeafBetaLnk       ipld.Link
	LeafBetaBlock     blocks.Block
	MiddleMapNode     ipld.Node
	MiddleMapNodeLnk  ipld.Link
	MiddleMapBlock    blocks.Block
	MiddleListNode    ipld.Node
	MiddleListNodeLnk ipld.Link
	MiddleListBlock   blocks.Block
	RootNode          ipld.Node
	RootNodeLnk       ipld.Link
	RootBlock         blocks.Block
}

TestIPLDTree is a set of IPLD Data that forms a tree spread across some blocks with a serialized in memory representation

func NewTestIPLDTree added in v0.1.0

func NewTestIPLDTree() TestIPLDTree

NewTestIPLDTree returns a fake tree of nodes, spread across 5 blocks

type TestSubscriber added in v0.3.0

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

func NewTestSubscriber added in v0.3.0

func NewTestSubscriber(bufferSize int) *TestSubscriber

func (*TestSubscriber) ExpectCloses added in v0.3.0

func (ts *TestSubscriber) ExpectCloses(ctx context.Context, t *testing.T, topics []notifications.Topic)

func (*TestSubscriber) ExpectClosesAnyOrder added in v0.3.0

func (ts *TestSubscriber) ExpectClosesAnyOrder(ctx context.Context, t *testing.T, topics []notifications.Topic)

func (*TestSubscriber) ExpectEvents added in v0.3.0

func (ts *TestSubscriber) ExpectEvents(ctx context.Context, t *testing.T, events []DispatchedEvent)

func (*TestSubscriber) NoEventsReceived added in v0.3.0

func (ts *TestSubscriber) NoEventsReceived(t *testing.T)

func (*TestSubscriber) OnClose added in v0.3.0

func (ts *TestSubscriber) OnClose(topic notifications.Topic)

func (*TestSubscriber) OnNext added in v0.3.0

func (ts *TestSubscriber) OnNext(topic notifications.Topic, ev notifications.Event)

type TestingT added in v0.1.2

type TestingT interface {
	Errorf(format string, args ...interface{})
	FailNow()
	Fatal(args ...interface{})
}

TestingT covers the interface methods we need from either *testing.T or *testing.B

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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