testing

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 25 Imported by: 10

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.TB, opts ...Option) *swarm.Swarm

GenSwarm generates a new test swarm.

func GenUpgrader

func GenUpgrader(t testing.TB, n *swarm.Swarm, connGater connmgr.ConnectionGater, opts ...tptu.Option) transport.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.TB, *config)

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

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

OptDialOnly prevents the test swarm from listening.

var OptDisableQUIC Option = func(_ testing.TB, c *config) {
	c.disableQUIC = true
}

OptDisableQUIC disables QUIC.

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

OptDisableReuseport disables reuseport in this test swarm.

var OptDisableTCP Option = func(_ testing.TB, c *config) {
	c.disableTCP = true
}

OptDisableTCP disables TCP.

func EventBus added in v0.26.1

func EventBus(b event.Bus) Option

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.

func WithClock added in v0.21.0

func WithClock(clock clock) Option

WithClock sets the clock to use for this swarm

func WithSwarmOpts added in v0.23.0

func WithSwarmOpts(swarmOpts ...swarm.Option) Option

Jump to

Keyboard shortcuts

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