Documentation
¶
Overview ¶
Package testutil provides a multi-node test harness for integration testing mesh operations over real I2P connections. This harness requires a running I2P router with SAM enabled on localhost:7656.
Package testutil provides testing utilities for i2plan integration tests.
Index ¶
- Constants
- type EmbeddedHarness
- func (h *EmbeddedHarness) Cleanup()
- func (h *EmbeddedHarness) ConnectViaInvite(ctx context.Context, inviterID, inviteeID string) error
- func (h *EmbeddedHarness) CreateNode(ctx context.Context, id string) (*EmbeddedTestNode, error)
- func (h *EmbeddedHarness) CreateNodes(ctx context.Context, count int) ([]*EmbeddedTestNode, error)
- func (h *EmbeddedHarness) GetNode(id string) *EmbeddedTestNode
- func (h *EmbeddedHarness) ListNodes() []*EmbeddedTestNode
- func (h *EmbeddedHarness) NodeCount() int
- func (h *EmbeddedHarness) RequireSAM() error
- type EmbeddedHarnessConfig
- type EmbeddedTestNode
- func (n *EmbeddedTestNode) AcceptInvite(ctx context.Context, inviteCode string) error
- func (n *EmbeddedTestNode) CreateInvite(ctx context.Context, maxUses int) (string, error)
- func (n *EmbeddedTestNode) Events() <-chan embedded.Event
- func (n *EmbeddedTestNode) I2PAddress() string
- func (n *EmbeddedTestNode) I2PDestination() string
- func (n *EmbeddedTestNode) IsStarted() bool
- func (n *EmbeddedTestNode) NodeID() string
- func (n *EmbeddedTestNode) Peers() []embedded.PeerInfo
- func (n *EmbeddedTestNode) Start(ctx context.Context) error
- func (n *EmbeddedTestNode) Status() embedded.Status
- func (n *EmbeddedTestNode) Stop() error
- func (n *EmbeddedTestNode) TunnelIP() netip.Addr
- type EmbeddedTestNodeConfig
- type MockMeshNetwork
- func (n *MockMeshNetwork) AddNode(nodeID, dest string) *MockTransport
- func (n *MockMeshNetwork) ConnectNodes(nodeA, nodeB string) error
- func (n *MockMeshNetwork) DisconnectNodes(nodeA, nodeB string)
- func (n *MockMeshNetwork) GetTransport(nodeID string) *MockTransport
- func (n *MockMeshNetwork) NodeCount() int
- type MockMessage
- type MockPeer
- type MockSAM
- type MockTransport
- func (t *MockTransport) AddPeer(nodeID, dest string)
- func (t *MockTransport) Broadcast(data []byte) error
- func (t *MockTransport) Dest() string
- func (t *MockTransport) GetPeers() []*MockPeer
- func (t *MockTransport) Messages() <-chan *MockMessage
- func (t *MockTransport) NodeID() string
- func (t *MockTransport) ReceiveMessage(ctx context.Context) *MockMessage
- func (t *MockTransport) RemovePeer(nodeID string)
- func (t *MockTransport) SendTo(nodeID string, data []byte) error
- func (t *MockTransport) SendToDest(i2pDest string, data []byte) error
- type MultiNodeHarness
- func (h *MultiNodeHarness) Cleanup()
- func (h *MultiNodeHarness) ConnectPeers(nodeA, nodeB string) error
- func (h *MultiNodeHarness) CreateNode(ctx context.Context, id string) (*TestNode, error)
- func (h *MultiNodeHarness) CreateNodes(ctx context.Context, count int) ([]*TestNode, error)
- func (h *MultiNodeHarness) GetNode(id string) *TestNode
- func (h *MultiNodeHarness) GetNodeAddresses() map[string]string
- func (h *MultiNodeHarness) ListNodes() []*TestNode
- func (h *MultiNodeHarness) NodeCount() int
- func (h *MultiNodeHarness) RequireSAM() error
- func (h *MultiNodeHarness) WaitForNodes(ctx context.Context) error
- type MultiNodeHarnessConfig
- type TestNode
- type TestNodeConfig
Constants ¶
const ( // DefaultSAMAddress is the default SAM bridge address for tests. DefaultSAMAddress = "127.0.0.1:7656" // DefaultDialTimeout is the timeout for SAM connectivity checks. DefaultDialTimeout = 5 * time.Second // DefaultNodeStartTimeout is how long to wait for a node to start. DefaultNodeStartTimeout = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EmbeddedHarness ¶
type EmbeddedHarness struct {
// contains filtered or unexported fields
}
EmbeddedHarness manages multiple embedded test nodes.
func NewEmbeddedHarness ¶
func NewEmbeddedHarness(cfg EmbeddedHarnessConfig) *EmbeddedHarness
NewEmbeddedHarness creates a new embedded test harness.
func (*EmbeddedHarness) Cleanup ¶
func (h *EmbeddedHarness) Cleanup()
Cleanup stops all nodes and cleans up resources.
func (*EmbeddedHarness) ConnectViaInvite ¶
func (h *EmbeddedHarness) ConnectViaInvite(ctx context.Context, inviterID, inviteeID string) error
ConnectViaInvite connects two nodes using the invite system.
func (*EmbeddedHarness) CreateNode ¶
func (h *EmbeddedHarness) CreateNode(ctx context.Context, id string) (*EmbeddedTestNode, error)
CreateNode creates and starts a new embedded test node.
func (*EmbeddedHarness) CreateNodes ¶
func (h *EmbeddedHarness) CreateNodes(ctx context.Context, count int) ([]*EmbeddedTestNode, error)
CreateNodes creates and starts multiple nodes.
func (*EmbeddedHarness) GetNode ¶
func (h *EmbeddedHarness) GetNode(id string) *EmbeddedTestNode
GetNode returns a node by ID.
func (*EmbeddedHarness) ListNodes ¶
func (h *EmbeddedHarness) ListNodes() []*EmbeddedTestNode
ListNodes returns all nodes.
func (*EmbeddedHarness) NodeCount ¶
func (h *EmbeddedHarness) NodeCount() int
NodeCount returns the number of nodes.
func (*EmbeddedHarness) RequireSAM ¶
func (h *EmbeddedHarness) RequireSAM() error
RequireSAM checks that SAM is available.
type EmbeddedHarnessConfig ¶
type EmbeddedHarnessConfig struct {
// SAMAddress is the SAM bridge address (defaults to localhost:7656).
SAMAddress string
// BaseDir is the base directory for node data (defaults to temp dir).
BaseDir string
}
EmbeddedHarnessConfig configures the embedded harness.
type EmbeddedTestNode ¶
type EmbeddedTestNode struct {
// Identity
ID string
Name string
// Embedded VPN
VPN *embedded.VPN
// contains filtered or unexported fields
}
EmbeddedTestNode represents a test node using the embedded VPN API. This provides higher-level testing capabilities compared to TestNode, including full mesh functionality (peers, invites, routes).
func NewEmbeddedTestNode ¶
func NewEmbeddedTestNode(cfg EmbeddedTestNodeConfig) *EmbeddedTestNode
NewEmbeddedTestNode creates a new embedded test node.
func (*EmbeddedTestNode) AcceptInvite ¶
func (n *EmbeddedTestNode) AcceptInvite(ctx context.Context, inviteCode string) error
AcceptInvite joins a network using an invite code.
func (*EmbeddedTestNode) CreateInvite ¶
CreateInvite generates an invite code.
func (*EmbeddedTestNode) Events ¶
func (n *EmbeddedTestNode) Events() <-chan embedded.Event
Events returns the VPN event channel.
func (*EmbeddedTestNode) I2PAddress ¶
func (n *EmbeddedTestNode) I2PAddress() string
I2PAddress returns the short I2P address (base32.b32.i2p).
func (*EmbeddedTestNode) I2PDestination ¶
func (n *EmbeddedTestNode) I2PDestination() string
I2PDestination returns the full I2P destination.
func (*EmbeddedTestNode) IsStarted ¶
func (n *EmbeddedTestNode) IsStarted() bool
IsStarted returns true if the node is running.
func (*EmbeddedTestNode) NodeID ¶
func (n *EmbeddedTestNode) NodeID() string
NodeID returns the unique node identifier.
func (*EmbeddedTestNode) Peers ¶
func (n *EmbeddedTestNode) Peers() []embedded.PeerInfo
Peers returns the list of connected peers.
func (*EmbeddedTestNode) Start ¶
func (n *EmbeddedTestNode) Start(ctx context.Context) error
Start initializes and starts the embedded VPN.
func (*EmbeddedTestNode) Status ¶
func (n *EmbeddedTestNode) Status() embedded.Status
Status returns the current VPN status.
func (*EmbeddedTestNode) Stop ¶
func (n *EmbeddedTestNode) Stop() error
Stop shuts down the embedded test node.
func (*EmbeddedTestNode) TunnelIP ¶
func (n *EmbeddedTestNode) TunnelIP() netip.Addr
TunnelIP returns the mesh tunnel IP address.
type EmbeddedTestNodeConfig ¶
type EmbeddedTestNodeConfig struct {
// ID is a unique identifier for this node (e.g., "node1", "node2").
ID string
// Name is the node name (defaults to "test-<ID>").
Name string
// SAMAddress is the SAM bridge address (defaults to localhost:7656).
SAMAddress string
// DataDir is the data directory (defaults to temp dir).
DataDir string
}
EmbeddedTestNodeConfig configures an embedded test node.
type MockMeshNetwork ¶
type MockMeshNetwork struct {
// contains filtered or unexported fields
}
MockMeshNetwork creates an interconnected set of mock transports for testing.
func NewMockMeshNetwork ¶
func NewMockMeshNetwork() *MockMeshNetwork
NewMockMeshNetwork creates a new mock mesh network.
func (*MockMeshNetwork) AddNode ¶
func (n *MockMeshNetwork) AddNode(nodeID, dest string) *MockTransport
AddNode adds a node to the mock mesh network.
func (*MockMeshNetwork) ConnectNodes ¶
func (n *MockMeshNetwork) ConnectNodes(nodeA, nodeB string) error
ConnectNodes connects two nodes in the mock network.
func (*MockMeshNetwork) DisconnectNodes ¶
func (n *MockMeshNetwork) DisconnectNodes(nodeA, nodeB string)
DisconnectNodes disconnects two nodes in the mock network.
func (*MockMeshNetwork) GetTransport ¶
func (n *MockMeshNetwork) GetTransport(nodeID string) *MockTransport
GetTransport returns the transport for a node.
func (*MockMeshNetwork) NodeCount ¶
func (n *MockMeshNetwork) NodeCount() int
NodeCount returns the number of nodes in the network.
type MockMessage ¶
MockMessage represents a message in the mock transport.
type MockSAM ¶
type MockSAM struct {
// contains filtered or unexported fields
}
MockSAM provides a mock SAM bridge for testing without a real I2P router.
func NewMockSAM ¶
NewMockSAM creates a new mock SAM bridge listening on a random port.
type MockTransport ¶
type MockTransport struct {
// contains filtered or unexported fields
}
MockTransport provides an in-memory transport for testing mesh operations.
func NewMockTransport ¶
func NewMockTransport(nodeID, dest string) *MockTransport
NewMockTransport creates a new mock transport for testing.
func (*MockTransport) AddPeer ¶
func (t *MockTransport) AddPeer(nodeID, dest string)
AddPeer adds a peer to the mock transport.
func (*MockTransport) Broadcast ¶
func (t *MockTransport) Broadcast(data []byte) error
Broadcast sends a message to all peers.
func (*MockTransport) Dest ¶
func (t *MockTransport) Dest() string
Dest returns the mock destination.
func (*MockTransport) GetPeers ¶
func (t *MockTransport) GetPeers() []*MockPeer
GetPeers returns all connected peers.
func (*MockTransport) Messages ¶
func (t *MockTransport) Messages() <-chan *MockMessage
Messages returns the message channel for direct access.
func (*MockTransport) NodeID ¶
func (t *MockTransport) NodeID() string
NodeID returns the mock node ID.
func (*MockTransport) ReceiveMessage ¶
func (t *MockTransport) ReceiveMessage(ctx context.Context) *MockMessage
ReceiveMessage receives a message from the mock transport. Returns nil if context is cancelled.
func (*MockTransport) RemovePeer ¶
func (t *MockTransport) RemovePeer(nodeID string)
RemovePeer removes a peer from the mock transport.
func (*MockTransport) SendTo ¶
func (t *MockTransport) SendTo(nodeID string, data []byte) error
SendTo sends a message to a peer.
func (*MockTransport) SendToDest ¶
func (t *MockTransport) SendToDest(i2pDest string, data []byte) error
SendToDest sends a message directly to an I2P destination. In the mock, this is a no-op that always succeeds since we don't simulate I2P destinations.
type MultiNodeHarness ¶
type MultiNodeHarness struct {
// contains filtered or unexported fields
}
MultiNodeHarness manages multiple test nodes for integration testing.
func NewMultiNodeHarness ¶
func NewMultiNodeHarness(cfg MultiNodeHarnessConfig) *MultiNodeHarness
NewMultiNodeHarness creates a new multi-node test harness.
func (*MultiNodeHarness) Cleanup ¶
func (h *MultiNodeHarness) Cleanup()
Cleanup stops all nodes and cleans up resources. Should be called with defer after creating the harness.
func (*MultiNodeHarness) ConnectPeers ¶
func (h *MultiNodeHarness) ConnectPeers(nodeA, nodeB string) error
ConnectPeers adds peer tracking between two nodes. This registers each node as a peer of the other, but doesn't establish a WireGuard tunnel (that requires the full mesh implementation).
func (*MultiNodeHarness) CreateNode ¶
CreateNode creates and starts a new test node.
func (*MultiNodeHarness) CreateNodes ¶
CreateNodes creates and starts multiple nodes.
func (*MultiNodeHarness) GetNode ¶
func (h *MultiNodeHarness) GetNode(id string) *TestNode
GetNode returns a node by ID.
func (*MultiNodeHarness) GetNodeAddresses ¶
func (h *MultiNodeHarness) GetNodeAddresses() map[string]string
GetNodeAddresses returns a map of node IDs to their I2P addresses.
func (*MultiNodeHarness) ListNodes ¶
func (h *MultiNodeHarness) ListNodes() []*TestNode
ListNodes returns all nodes.
func (*MultiNodeHarness) NodeCount ¶
func (h *MultiNodeHarness) NodeCount() int
NodeCount returns the number of nodes.
func (*MultiNodeHarness) RequireSAM ¶
func (h *MultiNodeHarness) RequireSAM() error
RequireSAM checks that SAM is available and returns an error if not.
func (*MultiNodeHarness) WaitForNodes ¶
func (h *MultiNodeHarness) WaitForNodes(ctx context.Context) error
WaitForNodes waits for all nodes to be addressable. This is useful after creating nodes to ensure they're fully initialized.
type MultiNodeHarnessConfig ¶
type MultiNodeHarnessConfig struct {
// SAMAddress is the SAM bridge address (defaults to localhost:7656).
SAMAddress string
}
MultiNodeHarnessConfig configures the multi-node harness.
type TestNode ¶
type TestNode struct {
// Identity
ID string
Name string
// Transport
Transport *transport.Transport
// contains filtered or unexported fields
}
TestNode represents a single node in the multi-node test harness. Each node has its own I2P session and can communicate with other nodes.
func NewTestNode ¶
func NewTestNode(cfg TestNodeConfig) *TestNode
NewTestNode creates a new test node with the given configuration.
func (*TestNode) I2PDestination ¶
I2PDestination returns the full I2P destination.
func (*TestNode) LocalAddress ¶
LocalAddress returns the base32 I2P address.
type TestNodeConfig ¶
type TestNodeConfig struct {
// ID is a unique identifier for this node (e.g., "node1", "node2").
ID string
// Name is the I2P tunnel name (defaults to "test-<ID>").
Name string
// SAMAddress is the SAM bridge address (defaults to localhost:7656).
SAMAddress string
// Options are SAM tunnel options.
Options []string
}
TestNodeConfig configures a test node.