Documentation
¶
Overview ¶
Package vcr records HTTP interactions into go-vcr cassettes and replays them in tests. A Scrubber removes credentials before a cassette is saved and refuses to save one that still contains a secret.
Index ¶
Constants ¶
const RecordEnv = "VCR_RECORD"
RecordEnv makes ForTest record against the real service. VCR_RECORD=1 go test ./... sets it.
const Redacted = "REDACTED"
Redacted replaces every secret value in a saved cassette.
Variables ¶
var ErrSecretLeft = errors.New("secret left in cassette")
ErrSecretLeft is returned when a secret is still in an interaction after scrubbing.
Functions ¶
func DefaultHeaders ¶
func DefaultHeaders() []string
DefaultHeaders lists the headers a Scrubber always drops from requests and responses.
func ForTest ¶
ForTest returns a transport for the cassette at path that records when Recording is true and replays otherwise. The recording is saved when the test ends.
Types ¶
type Options ¶
type Options struct {
Record bool // record against Real and overwrite the cassette
Real http.RoundTripper // used when recording; nil means [http.DefaultTransport]
Scrubber Scrubber
}
Options configures New.
type Replacement ¶
Replacement rewrites every match of Pattern with With.
type Scrubber ¶
type Scrubber struct {
Headers []string // dropped in addition to [DefaultHeaders]
Secrets []string // literal values replaced with [Redacted]; empty strings are ignored
Replace []Replacement // applied after Secrets, for values such as account IDs
Match []string // request headers the matcher compares, such as X-Amz-Target
}
Scrubber removes credentials from interactions before they are saved.
func (Scrubber) Matcher ¶
func (s Scrubber) Matcher() recorder.MatcherFunc
Matcher matches a request with a recorded one by method, URL and body after scrubbing the request the same way, so recorded tokens in URLs still match. Headers are ignored, except those in Match: the others carry credentials and client versions.
func (Scrubber) Scrub ¶
func (s Scrubber) Scrub(i *cassette.Interaction) error
Scrub cleans i in place and fails with ErrSecretLeft if a secret survives.