test

package
v0.1.1-0...-12c552a Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package test provides helper methods, sample configurations and simulations for testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clock

func Clock(now time.Time) func() time.Time

Clock returns an implementation of model.Clock that always returns the provided time value when called.

func GenerateBootstrapPeer

func GenerateBootstrapPeer(t *testing.T) (peer.AddrInfo, string)

GenerateBootstrapPeer generates a random peer identity and returns a peer.AddrInfo and its multiaddr string representation, suitable for use as a bootstrap peer in tests.

func GenerateIdentityKey

func GenerateIdentityKey(t *testing.T) (*crypto.PrivateKey, string)

GenerateIdentityKey generates an Ed25519 identity key for testing and returns both the key and the path to a PEM-encoded key file.

func GenerateKeys

func GenerateKeys(t *testing.T, count int) []*crypto.PrivateKey

GenerateKeys generates a specified number of ED25519 private keys for testing purposes and returns them as a slice.

func MustParseIPNet

func MustParseIPNet(cidr string) *net.IPNet

MustParseIPNet parses a CIDR string into a *net.IPNet or panics. Unlike net.ParseCIDR, this preserves the actual IP address (e.g., "192.168.1.1/24" returns an IPNet with IP=192.168.1.1, not the network address 192.168.1.0).

Types

type CertBundle

type CertBundle struct {
	Cert      *crypto.Certificate
	CAKeys    []*crypto.PublicKey
	CertPath  string
	CAPubPath string
}

CertBundle holds the parsed objects and file paths for a certificate and CA public key.

type MockResolver

type MockResolver struct {
	Interfaces map[string][]*net.IPNet
}

MockResolver is a test implementation of dmnet.InterfaceResolver that returns predefined addresses for interface names.

func (MockResolver) InterfaceAddresses

func (m MockResolver) InterfaceAddresses(name string) ([]*net.IPNet, error)

InterfaceAddresses returns the predefined addresses for the named interface.

func (MockResolver) IsReachable

func (m MockResolver) IsReachable(addr multiaddr.Multiaddr, interfaces []string) (bool, error)

IsReachable returns true if the multiaddr's IP is within the subnet of any specified interface.

func (MockResolver) ListenMultiaddrs

func (m MockResolver) ListenMultiaddrs(interfaces []string, port uint16) ([]multiaddr.Multiaddr, error)

ListenMultiaddrs returns multiaddrs for listening based on the mock's interface addresses.

Jump to

Keyboard shortcuts

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