Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RedactSimulation ¶
func RedactSimulation(sim *Simulation, opts RedactOptions)
RedactSimulation sanitizes all sensitive data in a simulation.
func ResetCounters ¶
func ResetCounters()
ResetCounters resets the redaction counters (call between capture runs).
func SaveSimulation ¶
func SaveSimulation(path string, sim *Simulation) error
SaveSimulation writes a simulation to a JSON file.
Types ¶
type Pair ¶
type Pair struct {
Description string `json:"description,omitempty"`
Request Request `json:"request"`
Response Response `json:"response"`
}
Pair is a single recorded request/response exchange.
type RecordingTransport ¶
type RecordingTransport struct {
Base http.RoundTripper
Pairs []Pair
}
RecordingTransport wraps an http.RoundTripper and records all request/response pairs.
func (*RecordingTransport) BuildSimulation ¶
func (rt *RecordingTransport) BuildSimulation() *Simulation
BuildSimulation creates a Simulation from recorded pairs.
type RedactOptions ¶
type RedactOptions struct {
// Domain to replace real TP domain with.
ReplacementDomain string
// RealDomain is the actual domain to find and replace.
RealDomain string
}
RedactOptions controls what gets redacted in simulations.
func DefaultRedactOptions ¶
func DefaultRedactOptions(realDomain string) RedactOptions
DefaultRedactOptions returns standard redaction settings.
type Request ¶
type Request struct {
Method string `json:"method"`
Path string `json:"path"`
Query map[string]string `json:"query,omitempty"`
}
Request describes the expected HTTP request to match.
type Response ¶
type Response struct {
Status int `json:"status"`
Headers map[string]string `json:"headers,omitempty"`
Body json.RawMessage `json:"body"`
}
Response describes the canned HTTP response to return.
type Simulation ¶
type Simulation struct {
Pairs []Pair `json:"pairs"`
}
Simulation holds a set of request/response pairs for replay.
func LoadSimulation ¶
func LoadSimulation(path string) (*Simulation, error)
LoadSimulation reads a simulation file from disk.
func LoadSimulationsFromDir ¶
func LoadSimulationsFromDir(dir string) (*Simulation, error)
LoadSimulationsFromDir loads all .json files from a directory.
type SimulationServer ¶
SimulationServer wraps an httptest.Server that replays recorded simulations.
func NewSimulationServer ¶
func NewSimulationServer(sim *Simulation) *SimulationServer
NewSimulationServer creates and starts a test server from simulation data.
func (*SimulationServer) Close ¶
func (ss *SimulationServer) Close()
Close shuts down the test server.
func (*SimulationServer) Requests ¶
func (ss *SimulationServer) Requests() []recordedRequest
Requests returns all recorded requests.
func (*SimulationServer) URL ¶
func (ss *SimulationServer) URL() string
URL returns the test server's URL.