testutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package testutil provides testing utilities for Wormhole.

This package contains mock implementations, test helpers, and fixtures used across the test suite.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eventually

func Eventually(t *testing.T, timeout time.Duration, interval time.Duration, condition func() bool)

Eventually asserts that the condition becomes true within the timeout.

func GetFreePort

func GetFreePort(t *testing.T) int

GetFreePort returns an available TCP port.

func NewMockConnPair

func NewMockConnPair() (*MockConn, *MockConn)

NewMockConnPair creates a pair of connected MockConn instances. Data written to one connection can be read from the other.

func RequireEqual

func RequireEqual[T comparable](t *testing.T, expected, actual T)

RequireEqual fails the test if expected != actual.

func RequireError

func RequireError(t *testing.T, err error)

RequireError fails the test if err is nil.

func RequireNoError

func RequireNoError(t *testing.T, err error)

RequireNoError fails the test if err is not nil.

func RequireTrue

func RequireTrue(t *testing.T, condition bool, msg string)

RequireTrue fails the test if condition is false.

func RunInGoroutine

func RunInGoroutine(t *testing.T, timeout time.Duration, fn func())

RunInGoroutine runs the function in a goroutine and waits for completion. It fails the test if the function doesn't complete within the timeout.

func WaitFor

func WaitFor(t *testing.T, timeout time.Duration, condition func() bool)

WaitFor waits for a condition to become true within the timeout.

func WithTimeout

func WithTimeout(t *testing.T, d time.Duration) context.Context

WithTimeout returns a context that times out after the specified duration.

Types

type MockAddr

type MockAddr struct {
	NetworkStr string
	AddrStr    string
}

MockAddr implements net.Addr for testing.

func (MockAddr) Network

func (a MockAddr) Network() string

func (MockAddr) String

func (a MockAddr) String() string

type MockConn

type MockConn struct {
	// contains filtered or unexported fields
}

MockConn implements net.Conn for testing purposes. It uses two connected pipes for bidirectional communication.

func (*MockConn) Close

func (c *MockConn) Close() error

Close closes the connection.

func (*MockConn) IsClosed

func (c *MockConn) IsClosed() bool

IsClosed returns whether the connection is closed.

func (*MockConn) LocalAddr

func (c *MockConn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*MockConn) Read

func (c *MockConn) Read(b []byte) (n int, err error)

Read reads data from the connection.

func (*MockConn) RemoteAddr

func (c *MockConn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*MockConn) SetDeadline

func (c *MockConn) SetDeadline(_ time.Time) error

SetDeadline sets the read and write deadlines.

func (*MockConn) SetReadDeadline

func (c *MockConn) SetReadDeadline(_ time.Time) error

SetReadDeadline sets the deadline for future Read calls.

func (*MockConn) SetWriteDeadline

func (c *MockConn) SetWriteDeadline(_ time.Time) error

SetWriteDeadline sets the deadline for future Write calls.

func (*MockConn) Write

func (c *MockConn) Write(b []byte) (n int, err error)

Write writes data to the connection.

Jump to

Keyboard shortcuts

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