testutil

package
v0.0.0-...-bb5a032 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertError

func AssertError(t *testing.T, err error, message string)

AssertError is a helper that fails the test if error is nil

func AssertErrorContains

func AssertErrorContains(t *testing.T, err error, expectedText string)

AssertErrorContains validates that error message contains expected text

func AssertJSONContainsFields

func AssertJSONContainsFields(t *testing.T, data []byte, expectedFields []string)

AssertJSONContainsFields validates that JSON contains expected fields

func AssertJSONValid

func AssertJSONValid(t *testing.T, data []byte)

AssertJSONValid validates that data is valid JSON

func AssertLatencyInRange

func AssertLatencyInRange(t *testing.T, actual, expected, tolerance time.Duration)

AssertLatencyInRange validates that latency is within expected range

func AssertNoError

func AssertNoError(t *testing.T, err error, message string)

AssertNoError is a helper that fails the test if error is not nil

func AssertPortClosed

func AssertPortClosed(t *testing.T, host string, port int, isOpen bool, message string)

AssertPortClosed validates that a port is reported as closed

func AssertPortOpen

func AssertPortOpen(t *testing.T, host string, port int, isOpen bool, message string)

AssertPortOpen validates that a port is reported as open

func CreateDataStream

func CreateDataStream(size int) []byte

CreateDataStream creates a mock data stream of specified size

func CreateMockDialer

func CreateMockDialer(conn net.Conn, err error) func(network, address string) (net.Conn, error)

CreateMockDialer creates a mock dialer that returns a mock connection

func CreateMockListener

func CreateMockListener(t *testing.T, port int) net.Listener

CreateMockListener creates a mock listener for testing

func CreateTestContext

func CreateTestContext(timeout time.Duration) (context.Context, context.CancelFunc)

CreateTestContext creates a context with timeout for testing

func GetFIPSConfig

func GetFIPSConfig() *config.Config

GetFIPSConfig returns a valid FIPS-compliant configuration

func GetFreePort

func GetFreePort(t *testing.T) int

GetFreePort returns an available port on localhost

func GetInvalidFIPSConfig

func GetInvalidFIPSConfig() *config.Config

GetInvalidFIPSConfig returns a configuration that claims FIPS but uses non-compliant settings

func GetMinimalConfig

func GetMinimalConfig() *config.Config

GetMinimalConfig returns a minimal valid configuration

func GetNonFIPSConfig

func GetNonFIPSConfig() *config.Config

GetNonFIPSConfig returns a valid non-FIPS configuration

func MustMarshalJSON

func MustMarshalJSON(t *testing.T, v interface{}) []byte

MustMarshalJSON marshals data to JSON or fails the test

func MustUnmarshalJSON

func MustUnmarshalJSON(t *testing.T, data []byte, v interface{})

MustUnmarshalJSON unmarshals JSON data or fails the test

func SetupSlowTestServer

func SetupSlowTestServer(t *testing.T, delay time.Duration) (string, func())

SetupSlowTestServer creates an HTTP test server with artificial delay

func SetupTestServer

func SetupTestServer(t *testing.T, handler http.HandlerFunc) (string, func())

SetupTestServer creates an HTTP test server with the given handler

func SetupTestServerWithResponse

func SetupTestServerWithResponse(t *testing.T, statusCode int, body string) (string, func())

SetupTestServerWithResponse creates an HTTP test server that returns specific response

func SetupTestTCPServer

func SetupTestTCPServer(t *testing.T) (string, func())

SetupTestTCPServer creates a TCP test server that echoes data

func WaitForCondition

func WaitForCondition(t *testing.T, condition func() bool, timeout time.Duration, message string)

WaitForCondition waits for a condition to be true or timeout

func WaitForPort

func WaitForPort(t *testing.T, host string, port int, timeout time.Duration) bool

WaitForPort waits for a port to be available or timeout

Types

type ConfigFixture

type ConfigFixture struct {
	Name        string
	Config      *config.Config
	ShouldError bool
	Description string
}

ConfigFixture represents a test configuration scenario

func GetConfigFixtures

func GetConfigFixtures() []ConfigFixture

GetConfigFixtures returns a collection of test configuration scenarios

type MockAddr

type MockAddr struct {
	NetworkString string
	AddrString    string
}

MockAddr implements net.Addr for testing

func (*MockAddr) Network

func (m *MockAddr) Network() string

func (*MockAddr) String

func (m *MockAddr) String() string

type MockConn

type MockConn struct {
	ReadFunc             func(b []byte) (n int, err error)
	WriteFunc            func(b []byte) (n int, err error)
	CloseFunc            func() error
	LocalAddrFunc        func() net.Addr
	RemoteAddrFunc       func() net.Addr
	SetDeadlineFunc      func(t time.Time) error
	SetReadDeadlineFunc  func(t time.Time) error
	SetWriteDeadlineFunc func(t time.Time) error
}

MockConn implements net.Conn for testing without real network access

func MockConnWithData

func MockConnWithData(data []byte) *MockConn

MockConnWithData creates a mock connection that returns specific data

func MockConnWithError

func MockConnWithError(returnErr error) *MockConn

MockConnWithError creates a mock connection that returns an error

func MockConnWithLatency

func MockConnWithLatency(latency time.Duration, data []byte) *MockConn

MockConnWithLatency creates a mock connection with artificial latency

func (*MockConn) Close

func (m *MockConn) Close() error

func (*MockConn) LocalAddr

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

func (*MockConn) Read

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

func (*MockConn) RemoteAddr

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

func (*MockConn) SetDeadline

func (m *MockConn) SetDeadline(t time.Time) error

func (*MockConn) SetReadDeadline

func (m *MockConn) SetReadDeadline(t time.Time) error

func (*MockConn) SetWriteDeadline

func (m *MockConn) SetWriteDeadline(t time.Time) error

func (*MockConn) Write

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

Jump to

Keyboard shortcuts

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