Documentation
¶
Overview ¶
Package replay provides strict, local-only transports for deterministic tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SemanticEqual ¶
SemanticEqual compares JSON structure while retaining exact decimal number values.
Types ¶
type Exchange ¶
Exchange is one recorded request and its response. Bodies are byte-exact unless JSON is true.
func LoadExchange ¶
LoadExchange decodes a JSON cassette file. Response bodies are represented as JSON strings.
type HeadersMode ¶
type HeadersMode string
HeadersMode controls cassette header matching. Empty mode is exact.
const ( HeadersExact HeadersMode = "exact" HeadersRequired HeadersMode = "required" )
type RecordedMessage ¶
type RecordedMessage struct {
Direction string `json:"direction"`
Frame string `json:"frame"`
Payload json.RawMessage `json:"payload"`
}
RecordedMessage preserves a sanitized wire frame and its direction. Tests select the exchange needed for a behavior instead of replaying a whole stream.
type Request ¶
type Request struct {
Method string `json:"method"`
Origin string `json:"origin"`
Path string `json:"path"`
Query []Pair `json:"query"`
Headers http.Header `json:"headers"`
HeadersMode HeadersMode `json:"headers_mode,omitempty"`
Body json.RawMessage `json:"body"`
JSON bool `json:"json,omitempty"`
}
type SessionRecording ¶
type SessionRecording struct {
Messages []RecordedMessage `json:"messages"`
}
func LoadSessionRecording ¶
func LoadSessionRecording(path string) (SessionRecording, error)
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport replays each cassette at most once and never dials a network destination.
func NewTransport ¶
func (*Transport) AssertConsumed ¶
type WSStep ¶
type WSStep struct {
Kind string `json:"kind"`
Frame string `json:"frame"`
Body json.RawMessage `json:"body"`
}
WSStep either expects a client frame or sends a server frame. Kind is "expect" or "send".
type WebSocketServer ¶
WebSocketServer serves one scripted connection on a loopback httptest server.
func NewWebSocketServer ¶
func NewWebSocketServer(steps []WSStep, timeout time.Duration) *WebSocketServer
NewWebSocketServer starts a strict scripted WebSocket peer. Each read has a bounded deadline.
func (*WebSocketServer) AssertComplete ¶
func (w *WebSocketServer) AssertComplete(timeout time.Duration) error
AssertComplete waits for the script and reports mismatch, disconnect, or timeout.
func (*WebSocketServer) Close ¶
func (w *WebSocketServer) Close()
Close stops the server and closes an active client connection so shutdown remains bounded.
func (*WebSocketServer) URL ¶
func (w *WebSocketServer) URL() string
URL returns the local websocket URL for a client dialer.