vcr

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 10 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 provides utilities for recording and replaying HTTP interactions in tests using go-vcr.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHTTPSClient

func GetHTTPSClient(t *testing.T) *https.Client

GetHTTPSClient creates an HTTPS client for integration tests with VCR support. It wraps the HTTP client with VCR recording/replay based on VCR_MODE environment variable. The cassette name is automatically derived from t.Name(). In replay mode, a dummy API key is used. In record/off modes, BRAINTRUST_API_KEY is required.

func NewHTTPClient

func NewHTTPClient(t *testing.T) *http.Client

NewHTTPClient creates a new HTTP client with VCR support. If VCR_MODE=off, returns a standard HTTP client. The cassette name is automatically derived from t.Name().

func NewVCRRecorder

func NewVCRRecorder(t *testing.T, cassettePath string) (*recorder.Recorder, error)

NewVCRRecorder creates a new VCR recorder for the given cassette path. The recorder automatically scrubs sensitive headers before saving.

func WrapHTTPClient

func WrapHTTPClient(t *testing.T, httpClient *http.Client) *http.Client

WrapHTTPClient wraps an existing http.Client with VCR recording/replay functionality. If VCR_MODE=off, returns the original client unchanged. The cassette name is automatically derived from t.Name(). Cassettes are stored in testdata/cassettes/<test-name>.yaml

Types

type Mode

type Mode string

Mode represents the mode for VCR operations

const (
	// ModeOff disables VCR and uses real HTTP requests
	ModeOff Mode = "off"
	// ModeRecord records or updates cassettes
	ModeRecord Mode = "record"
	// ModeReplay replays from existing cassettes (default)
	ModeReplay Mode = "replay"
)

func GetVCRMode

func GetVCRMode() Mode

GetVCRMode reads the VCR_MODE environment variable and returns the mode. Defaults to replay mode if not set or invalid.

Jump to

Keyboard shortcuts

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