Documentation
¶
Index ¶
- func AssertDomainErrorCode(t testing.TB, err error, code coreerrors.ErrorCode)
- func AssertFrameValid(t *testing.T, frame []byte)
- func AssertLengthPrefix(t *testing.T, data []byte) uint32
- func AssertPayloadStructure(t *testing.T, payload []byte, minSize int)
- func AssertRouteValid(t *testing.T, route string)
- func BrokerConnectable(addr string) bool
- func BytesToString(b []byte) string
- func CloseQuietly[T interface{ ... }](value T)
- func ContextWithCancel() (context.Context, context.CancelFunc)
- func ExtractKeyValueFromPayload(payload []byte, startOffset int) (key []byte, value []byte, err error)
- func ExtractRouteFromPayload(payload []byte) (string, error)
- func FastContext() (context.Context, context.CancelFunc)
- func GenerateFrame(msgType uint16, payloadSize int) []byte
- func GenerateKey(size int) []byte
- func GenerateRoute(domain string) string
- func GenerateString(length int) string
- func GenerateValue(size int) []byte
- func PrecomputeFrames(count int, avgSize int) [][]byte
- func ReleaseQuietly[T interface{ ... }](ctx context.Context, value T)
- func RollbackQuietly[T interface{ ... }](ctx context.Context, value T)
- func StringToBytes(s string) []byte
- func TCPFrameWrapper(frame []byte) []byte
- func TimeoutContext(timeout time.Duration) (context.Context, context.CancelFunc)
- func UniqueArea() string
- func UniqueOperationID() string
- func UniqueRealm() string
- func UniqueResource() string
- func UniqueRoute(domain string) string
- type MockTCPConn
- func (m *MockTCPConn) Close() error
- func (m *MockTCPConn) LocalAddr() net.Addr
- func (m *MockTCPConn) Read(b []byte) (int, error)
- func (m *MockTCPConn) RemoteAddr() net.Addr
- func (m *MockTCPConn) SetDeadline(t time.Time) error
- func (m *MockTCPConn) SetReadDeadline(t time.Time) error
- func (m *MockTCPConn) SetWriteDeadline(t time.Time) error
- func (m *MockTCPConn) Write(b []byte) (int, error)
- type MockTransport
- func (m *MockTransport) Close() error
- func (m *MockTransport) GetWrittenFrames() [][]byte
- func (m *MockTransport) Read(ctx context.Context) ([]byte, error)
- func (m *MockTransport) RemoteAddr() string
- func (m *MockTransport) SetReadError(err error)
- func (m *MockTransport) SetReadFrames(frames [][]byte)
- func (m *MockTransport) SetWriteError(err error)
- func (m *MockTransport) Write(ctx context.Context, frame []byte) error
- type MockWSConn
- func (m *MockWSConn) Close() error
- func (m *MockWSConn) LocalAddr() net.Addr
- func (m *MockWSConn) Read(b []byte) (int, error)
- func (m *MockWSConn) RemoteAddr() net.Addr
- func (m *MockWSConn) SetDeadline(t time.Time) error
- func (m *MockWSConn) SetReadDeadline(t time.Time) error
- func (m *MockWSConn) SetWriteDeadline(t time.Time) error
- func (m *MockWSConn) Write(b []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertDomainErrorCode ¶
func AssertDomainErrorCode(t testing.TB, err error, code coreerrors.ErrorCode)
AssertDomainErrorCode asserts that err is a domain error with the given code. If err is nil or not a *coreerrors.DomainError, the test fails. Use this when the client surfaces server error codes so tests are stable against message text changes.
func AssertFrameValid ¶
AssertFrameValid performs basic validation on a frame.
func AssertLengthPrefix ¶
AssertLengthPrefix verifies and extracts TCP length prefix.
func AssertPayloadStructure ¶
AssertPayloadStructure verifies payload format without decoding details. Used to check that payload has minimum expected structure.
func AssertRouteValid ¶
AssertRouteValid checks if a route string is valid.
func BrokerConnectable ¶
BrokerConnectable checks if a broker is reachable.
func BytesToString ¶
BytesToString is a helper to convert bytes to string.
func CloseQuietly ¶
func CloseQuietly[T interface{ Close() error }](value T)
CloseQuietly closes a resource and discards the close error.
func ContextWithCancel ¶
func ContextWithCancel() (context.Context, context.CancelFunc)
ContextWithCancel creates a cancellable context for testing.
func ExtractKeyValueFromPayload ¶
func ExtractKeyValueFromPayload(payload []byte, startOffset int) (key []byte, value []byte, err error)
ExtractKeyValueFromPayload extracts key and value from a KV payload. Assumes format: [...][key_len (4)][key][value_len (4)][value][...] startOffset is the byte position where key_len begins.
func ExtractRouteFromPayload ¶
ExtractRouteFromPayload extracts a route string from a payload. Assumes format: [route_len (4)][route][...]
func FastContext ¶
func FastContext() (context.Context, context.CancelFunc)
FastContext creates a very short timeout context for testing timeouts.
func GenerateFrame ¶
GenerateFrame creates a complete TLV frame with specified message type and payload size.
func GenerateKey ¶
GenerateKey creates a key of specified size for testing.
func GenerateRoute ¶
GenerateRoute creates a route string for testing.
func GenerateString ¶
GenerateString creates a string of the specified length.
func GenerateValue ¶
GenerateValue creates a value of specified size for testing.
func PrecomputeFrames ¶
PrecomputeFrames creates precomputed test frames for benchmarking.
func ReleaseQuietly ¶
ReleaseQuietly releases a resource and discards the release error.
func RollbackQuietly ¶
RollbackQuietly rolls back a resource and discards the rollback error.
func StringToBytes ¶
StringToBytes is a helper to convert string to bytes.
func TCPFrameWrapper ¶
TCPFrameWrapper wraps a frame with TCP length prefix.
func TimeoutContext ¶
TimeoutContext creates a context with a specific timeout for testing.
func UniqueOperationID ¶
func UniqueOperationID() string
UniqueOperationID generates a unique operation ID for test isolation.
func UniqueRoute ¶
UniqueRoute generates a unique route for test isolation.
Types ¶
type MockTCPConn ¶
type MockTCPConn struct {
ToRead []byte
Written []byte
ReadPos int
Blocked bool
Closed bool
ReadDelay time.Duration
WriteDelay time.Duration
MaxWriteSize int
RemoteAddrString string
// contains filtered or unexported fields
}
MockTCPConn is a mock TCP connection for testing transport layer.
func (*MockTCPConn) Close ¶
func (m *MockTCPConn) Close() error
func (*MockTCPConn) LocalAddr ¶
func (m *MockTCPConn) LocalAddr() net.Addr
func (*MockTCPConn) RemoteAddr ¶
func (m *MockTCPConn) RemoteAddr() net.Addr
func (*MockTCPConn) SetDeadline ¶
func (m *MockTCPConn) SetDeadline(t time.Time) error
func (*MockTCPConn) SetReadDeadline ¶
func (m *MockTCPConn) SetReadDeadline(t time.Time) error
func (*MockTCPConn) SetWriteDeadline ¶
func (m *MockTCPConn) SetWriteDeadline(t time.Time) error
type MockTransport ¶
type MockTransport struct {
// contains filtered or unexported fields
}
MockTransport is a controllable transport for unit tests. It allows tests to specify read responses and track written frames.
func NewMockTransport ¶
func NewMockTransport() *MockTransport
NewMockTransport creates a new mock transport.
func (*MockTransport) Close ¶
func (m *MockTransport) Close() error
Close marks the transport as closed.
func (*MockTransport) GetWrittenFrames ¶
func (m *MockTransport) GetWrittenFrames() [][]byte
GetWrittenFrames returns all frames written via Write().
func (*MockTransport) Read ¶
func (m *MockTransport) Read(ctx context.Context) ([]byte, error)
Read returns the next queued read frame or an error.
func (*MockTransport) RemoteAddr ¶
func (m *MockTransport) RemoteAddr() string
RemoteAddr returns the remote address.
func (*MockTransport) SetReadError ¶
func (m *MockTransport) SetReadError(err error)
SetReadError sets an error to return for all Read() calls.
func (*MockTransport) SetReadFrames ¶
func (m *MockTransport) SetReadFrames(frames [][]byte)
SetReadFrames sets the frames to return on Read() calls.
func (*MockTransport) SetWriteError ¶
func (m *MockTransport) SetWriteError(err error)
SetWriteError sets an error to return for all Write() calls.
type MockWSConn ¶
type MockWSConn struct {
NextMessage []byte
Messages [][]byte
IsText bool
Blocked bool
Closed bool
ReadBuf []byte
MaxWriteSize int
RemoteAddrHost string
// contains filtered or unexported fields
}
MockWSConn is a mock WebSocket connection for testing.
func (*MockWSConn) Close ¶
func (m *MockWSConn) Close() error
func (*MockWSConn) LocalAddr ¶
func (m *MockWSConn) LocalAddr() net.Addr
func (*MockWSConn) RemoteAddr ¶
func (m *MockWSConn) RemoteAddr() net.Addr
func (*MockWSConn) SetDeadline ¶
func (m *MockWSConn) SetDeadline(t time.Time) error
func (*MockWSConn) SetReadDeadline ¶
func (m *MockWSConn) SetReadDeadline(t time.Time) error
func (*MockWSConn) SetWriteDeadline ¶
func (m *MockWSConn) SetWriteDeadline(t time.Time) error