Documentation
¶
Overview ¶
Package test provides helper methods, sample configurations and simulations for testing.
Index ¶
- func Clock(now time.Time) func() time.Time
- func GenerateBootstrapPeer(t *testing.T) (peer.AddrInfo, string)
- func GenerateIdentityKey(t *testing.T) (*crypto.PrivateKey, string)
- func GenerateKeys(t *testing.T, count int) []*crypto.PrivateKey
- func MustParseIPNet(cidr string) *net.IPNet
- type CertBundle
- type MockResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clock ¶
Clock returns an implementation of model.Clock that always returns the provided time value when called.
func GenerateBootstrapPeer ¶
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 ¶
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 ¶
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 ¶
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.