testing

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DivulgeAddresses

func DivulgeAddresses(a, b network.Network)

DivulgeAddresses adds swarm a's addresses to swarm b's peerstore.

func GenSwarm

func GenSwarm(t *testing.T, ctx context.Context, opts ...Option) *swarm.Swarm

GenSwarm generates a new test swarm.

func GenUpgrader

func GenUpgrader(n *swarm.Swarm) *tptu.Upgrader

GenUpgrader creates a new connection upgrader for use with this swarm.

Types

type MockConnectionGater

type MockConnectionGater struct {
	Dial     func(p peer.ID, addr ma.Multiaddr) bool
	PeerDial func(p peer.ID) bool
	Accept   func(c network.ConnMultiaddrs) bool
	Secured  func(network.Direction, peer.ID, network.ConnMultiaddrs) bool
	Upgraded func(c network.Conn) (bool, control.DisconnectReason)
}

MockConnectionGater is a mock connection gater to be used by the tests.

func DefaultMockConnectionGater

func DefaultMockConnectionGater() *MockConnectionGater

func (*MockConnectionGater) InterceptAccept

func (m *MockConnectionGater) InterceptAccept(c network.ConnMultiaddrs) (allow bool)

func (*MockConnectionGater) InterceptAddrDial

func (m *MockConnectionGater) InterceptAddrDial(p peer.ID, addr ma.Multiaddr) (allow bool)

func (*MockConnectionGater) InterceptPeerDial

func (m *MockConnectionGater) InterceptPeerDial(p peer.ID) (allow bool)

func (*MockConnectionGater) InterceptSecured

func (m *MockConnectionGater) InterceptSecured(d network.Direction, p peer.ID, c network.ConnMultiaddrs) (allow bool)

func (*MockConnectionGater) InterceptUpgraded

func (m *MockConnectionGater) InterceptUpgraded(tc network.Conn) (allow bool, reason control.DisconnectReason)

type Option

type Option func(*testing.T, *config)

Option is an option that can be passed when constructing a test swarm.

var OptDialOnly Option = func(_ *testing.T, c *config) {
	c.dialOnly = true
}

OptDialOnly prevents the test swarm from listening.

var OptDisableReuseport Option = func(_ *testing.T, c *config) {
	c.disableReuseport = true
}

OptDisableReuseport disables reuseport in this test swarm.

func OptConnGater

func OptConnGater(cg connmgr.ConnectionGater) Option

OptConnGater configures the given connection gater on the test

func OptPeerPrivateKey

func OptPeerPrivateKey(sk crypto.PrivKey) Option

OptPeerPrivateKey configures the peer private key which is then used to derive the public key and peer ID.

Jump to

Keyboard shortcuts

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