vcr

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const RecordEnv = "VCR_RECORD"

RecordEnv makes ForTest record against the real service. VCR_RECORD=1 go test ./... sets it.

View Source
const Redacted = "REDACTED"

Redacted replaces every secret value in a saved cassette.

Variables

View Source
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

func ForTest(t testing.TB, path string, s Scrubber) http.RoundTripper

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.

func New

func New(path string, o Options) (*recorder.Recorder, error)

New returns a recorder for the cassette at path (with or without the .yaml extension). It replays unless o.Record is set; replaying a missing cassette fails. Call Stop to save a recording.

func Recording

func Recording() bool

Recording reports whether cassettes should be recorded instead of replayed.

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

type Replacement struct {
	Pattern *regexp.Regexp
	With    string
}

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.

Jump to

Keyboard shortcuts

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