Documentation
¶
Overview ¶
Package ssetest is the test seam between the sse hub and its clients: an httptest server for a hub, a frame reader for the wire, a recorder that answers http.ErrNotSupported to the deadline setters, and Fixture, the controllable server the TypeScript integration suites drive through the ssetest/cmd binary.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Fixture ¶
type Fixture struct {
// contains filtered or unexported fields
}
Fixture is the controllable SSE server the integration suites drive: a hub that /control/restart replaces, an in-memory subject store with one version counter per key, a presence table keyed by client tag, a stamped REST stub, and flags that stall, delay, fail or close a stream on demand. Every method is safe for concurrent use.
func NewFixture ¶
NewFixture builds a fixture whose hub carries WithReplay(1024), WithReplayTTL(10m), WithReplyMaxEvents(256), WithClientBuffer(4096) and the fixture's own presence hook, then the caller's options. It panics on an incoherent option set, which is a fixture bug rather than a runtime condition.
type Frame ¶
Frame is one dispatched event: the id: field, the event: name and the data: lines joined by LF. A retry: field is reported as a Frame with Event "retry" and the milliseconds in Data.
func ReadFrames ¶
ReadFrames parses the WHATWG event-stream line grammar from r and returns the first n dispatched frames, or every frame up to EOF when n <= 0. Comment lines are skipped, and a blank line that closes no data or retry field dispatches nothing, exactly as a browser's parser behaves.
This is the one-shot form: the buffered reader is discarded on return, and with it any bytes it read past frame n. Read successive batches off one live stream through a FrameReader instead.
type FrameReader ¶ added in v1.1.0
type FrameReader struct {
// contains filtered or unexported fields
}
FrameReader parses dispatched frames off one event stream across successive reads. It owns the buffered reader for the whole stream, which is what makes the second read correct: a buffered reader fills in chunks, so the bytes of frame n+1 routinely arrive in the same read as frame n, and a reader created per call would discard them along with itself. Not safe for concurrent use.
func NewFrameReader ¶ added in v1.1.0
func NewFrameReader(r io.Reader) *FrameReader
NewFrameReader returns a FrameReader over r, buffered for the hub's largest frame.
type Recorder ¶
type Recorder struct {
*httptest.ResponseRecorder
}
Recorder is an httptest.ResponseRecorder that flushes but answers http.ErrNotSupported to both deadline setters, the shape of a wrapper that exposes Flush without Unwrap, so a Serve against it runs the tolerated unbounded path.
func NewRecorder ¶
func NewRecorder() *Recorder
NewRecorder returns a Recorder over a fresh httptest.ResponseRecorder.
func (*Recorder) SetReadDeadline ¶
SetReadDeadline always answers http.ErrNotSupported.