gocloud.devgocloud.dev/internal/testing/replay Index | Files

package replay

import "gocloud.dev/internal/testing/replay"

Package replay provides the ability to record and replay HTTP requests.

Index

Functions

func NewGCPDialOptions

func NewGCPDialOptions(t *testing.T, mode recorder.Mode, filename string) (opts []grpc.DialOption, done func())

NewGCPDialOptions return grpc.DialOptions that are to be appended to a GRPC dial request. These options allow a recorder/replayer to intercept RPCs and save RPCs to the file at filename, or read the RPCs from the file and return them.

func NewRecorder

func NewRecorder(t *testing.T, mode recorder.Mode, matcher *ProviderMatcher, filename string) (r *recorder.Recorder, done func(), err error)

NewRecorder returns a go-vcr.Recorder which reads or writes golden files from the given path. When recording, done() saves the recording to a golden file. The Authorization request header is dropped, but otherwise the raw HTTP requests/responses are saved When replaying, HTTP requests are expected to arrive in the same order as in the recording. They are verified to have the same: -- Method -- URL -- Specific HTTP headers ((optional, via matcher). -- Body (optionally scrubbed, via matcher).

Types

type ProviderMatcher

type ProviderMatcher struct {
	// Headers is a slice of HTTP request headers that will be verified to match.
	Headers []string
	// DropRequestHeaders causes all HTTP request headers that match the given
	// regular expression to be dropped from the recording.
	// There should be no overlap with Headers.
	// In addition, the "Authorization" header is always dropped.
	DropRequestHeaders *regexp.Regexp
	// DropResponseHeaders causes all HTTP response headers that match the given
	// regular expression to be dropped from the recording.
	// In addition, the "Duration" header is always dropped.
	DropResponseHeaders *regexp.Regexp
	// URLScrubbers is a slice of regular expressions that will be used to
	// scrub the URL before matching, via ReplaceAllString.
	URLScrubbers []*regexp.Regexp
	// BodyScrubber is a slice of regular expressions that will be used to
	// scrub the HTTP request body before matching, via ReplaceAllString.
	BodyScrubbers []*regexp.Regexp
}

ProviderMatcher allows providers to customize how HTTP requests are matched and recorded.

Source Files

replay.go

Version
v0.13.0
Published
Apr 24, 2019
Platform
js/wasm
Imports
12 packages
Last checked
12 hours ago

Tools for package owners.