testpeer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package testpeer provides a scripted raw WebSocket peer for NT4 client tests. It deliberately does not import the production codec or implement NT state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(c *websocket.Conn, kind int, data []byte) error

Write sends a single raw server message with a finite deadline. The caller owns serialization when multiple scripts share the same connection.

Types

type Frame

type Frame struct {
	Type int
	Data []byte
}

Frame is one complete WebSocket data frame, copied before delivery.

type Peer

type Peer struct {
	Server         *httptest.Server
	Frames         chan Frame
	Connections    chan *websocket.Conn
	UpgradeGate    <-chan struct{} // set before dialing to hold the HTTP upgrade
	UpgradeEntered chan struct{}   // optional buffered notification before the gate
	PingObserved   chan struct{}   // optional buffered notification, with replies disabled
	Disconnected   chan struct{}   // buffered notification when a peer socket exits
	Protocol       string          // empty means no subprotocol selected
	// contains filtered or unexported fields
}

Peer accepts one connection at a time and lets a test script read/write raw frames. Frames is bounded; if the test stops draining it the socket read blocks, allowing deterministic writer pressure without an unbounded buffer.

func New

func New(protocol string) *Peer

func (*Peer) Address

func (p *Peer) Address() (string, int)

func (*Peer) Close

func (p *Peer) Close()

func (*Peer) Connect

func (p *Peer) Connect(ctx context.Context) (*websocket.Conn, error)

func (*Peer) Next

func (p *Peer) Next(ctx context.Context) (Frame, error)

Next waits for one client data message; it does not consume control pings.

Jump to

Keyboard shortcuts

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