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"`
BodyEncoding string `json:"body_encoding,omitempty"`
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 NewUnorderedTransport ¶ added in v0.5.0
NewUnorderedTransport permits explicitly independent requests to consume cassettes in any order while still requiring a one-time exact match.
func (*Transport) AssertConsumed ¶
type WSHandshake ¶ added in v0.5.0
type WSHandshake struct {
Origin string `json:"origin,omitempty"`
Host string `json:"host,omitempty"`
Path string `json:"path,omitempty"`
Query url.Values `json:"query,omitempty"`
Headers http.Header `json:"headers,omitempty"`
}
WSHandshake is the expected upgrade origin, host, path, query, and application headers. Empty Origin means the request must have no Origin header. Empty Host means the server's loopback host, which is assigned after the test server starts.
type WSStep ¶
type WSStep struct {
// Channel names an AsyncAPI channel for the production inventory gate.
Channel string `json:"channel,omitempty"`
Kind string `json:"kind"`
Frame string `json:"frame"`
Body json.RawMessage `json:"body"`
// Template enables explicit $uuid:name and $ref:name bindings in JSON text frames.
Template bool `json:"template,omitempty"`
}
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, handshakes ...WSHandshake) *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.