websocket

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertType

func AssertType(t testing.TB, response protocol.Response, want protocol.ResponseType)

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

func Connect(t testing.TB, url string, headers http.Header, maxFrameBytes int) *Client

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

func (c *Client) Close() error

Close closes the socket immediately; a nil or disconnected client is harmless.

func (*Client) Receive

func (c *Client) Receive(ctx context.Context) (protocol.Response, error)

Receive reads and validates a bounded text response with the expected protocol version.

func (*Client) Send

func (c *Client) Send(ctx context.Context, request protocol.Request) error

Send JSON-encodes and sends a protocol request.

func (*Client) SendText

func (c *Client) SendText(ctx context.Context, data []byte) error

SendText intentionally permits malformed protocol data for rejection tests.

Jump to

Keyboard shortcuts

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