replay

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

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 LoadCases

func LoadCases[T any](path string) ([]T, error)

LoadCases reads portable synthetic case arrays used by both language suites.

func SemanticEqual

func SemanticEqual(a, b []byte) bool

SemanticEqual compares JSON structure while retaining exact decimal number values.

Types

type Exchange

type Exchange struct {
	Request  Request  `json:"request"`
	Response Response `json:"response"`
}

Exchange is one recorded request and its response. Bodies are byte-exact unless JSON is true.

func LoadExchange

func LoadExchange(path string) (Exchange, error)

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 Pair

type Pair struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

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 Response

type Response struct {
	Status  int             `json:"status"`
	Headers http.Header     `json:"headers"`
	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 NewTransport(xs ...Exchange) *Transport

func (*Transport) AssertConsumed

func (t *Transport) AssertConsumed() error

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

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

type WebSocketServer struct {
	Server *httptest.Server
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

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