vcr

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Test

func Test[T any](t *testing.T, m Mode, bootstrap BootstrapFunc[T], test TestFunc[T])

Test is a helper function that should be used when writing tests that make HTTP requests. It sets up everything necessary to record and replay HTTP interactions. The mode determines whether the test should record or replay interactions. Recorded interactions (a.k.a cassettes) are stored in `fixtures/${cassetteName}` adjacent to the test file that uses this function. A bootstrap function can be provided to set up the client that will be used in the test. The test function should contain the actual test logic. The cassette is passed to the test function so that it can be used to assert on the recorded interactions.

Types

type BootstrapFunc

type BootstrapFunc[T any] func(t *testing.T, m Mode, r *recorder.Recorder) T

BootstrapFunc is a function that is used create and return the http client that will be used in the test. Additionally, the recorder can be used to further configure recording behavior as needed. More information on addition configuration can be found here

type Cassette

type Cassette func() *libcassette.Cassette

Cassette can be used to retrieve the cassette that was recorded or replayed during the test.

type Mode

type Mode string

Mode is used to represent the supported modes.

const (
	Replay Mode = "REPLAY"
	Record Mode = "RECORD"
)

func (Mode) ToLibMode

func (m Mode) ToLibMode() recorder.Mode

type TestFunc

type TestFunc[T any] func(*testing.T, T, Cassette)

TestFunc is a function that contains the actual test logic. It should accept the client and the cassette as arguments.

Jump to

Keyboard shortcuts

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