Documentation
¶
Overview ¶
Package websocket provides a bounded protocol client for independent consumer tests. Dial performs real HTTP/WebSocket I/O; this is not a production SDK.
Index ¶
- func AssertType(t testing.TB, response protocol.Response, want protocol.ResponseType)
- func DecodePayload[T any](ctx context.Context, response protocol.Response, descriptor contract.JSON[T], ...) (T, error)
- type Client
- func Connect(t testing.TB, url string, headers http.Header, maxFrameBytes int) *Client
- func Dial(ctx context.Context, url string, headers stdhttp.Header, maxFrameBytes int) (*Client, error)
- func DialTicket(ctx context.Context, url string, headers stdhttp.Header, maxFrameBytes int, ...) (*Client, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertType ¶
AssertType reports a test error when the response type differs from want.
func DecodePayload ¶
func DecodePayload[T any](ctx context.Context, response protocol.Response, descriptor contract.JSON[T], limits contract.JSONLimits) (T, error)
DecodePayload validates an event payload through its generated contract. The caller supplies the exact bounded response received from Client.Receive.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client permits one reader and serializes writes. A canceled I/O context closes the transport, following the underlying WebSocket connection contract.
func Connect ¶
Connect performs the real protocol handshake and owns test cleanup, including cleanup after a subsequent Fatal/Goexit. Each test gets its own connection.
func Dial ¶
func Dial(ctx context.Context, url string, headers stdhttp.Header, maxFrameBytes int) (*Client, error)
Dial connects a test client using the Foundry WebSocket subprotocol and the supplied frame limit.
func DialTicket ¶
func DialTicket(ctx context.Context, url string, headers stdhttp.Header, maxFrameBytes int, ticket secret.String) (*Client, error)
DialTicket performs a browser-style handshake: the single-use ticket travels as one extra Sec-WebSocket-Protocol entry, never in the URL.
func (*Client) Close ¶
Close closes the socket immediately; a nil or disconnected client is harmless.
func (*Client) Receive ¶
Receive reads and validates a bounded text response with the expected protocol version.