go-vcr — screenshot of github.com

go-vcr

I use go-vcr to record HTTP interactions, which then allows replaying them in future test runs. This ensures fast, deterministic, and accurate testing by avoiding external API calls.

Visit github.com →

Questions & Answers

What is go-vcr?
go-vcr is a Go library that simplifies testing by recording HTTP interactions during the first run and replaying them in subsequent test runs. This process helps provide fast, deterministic, and accurate testing for code that makes external HTTP requests.
Who should use go-vcr?
go-vcr is designed for Go developers who need to test components that interact with external HTTP services. It helps ensure consistent test results by eliminating reliance on live external APIs.
How does go-vcr improve testing?
go-vcr improves testing by replacing live network calls with recorded "cassettes," making tests run faster and more reliably. It ensures determinism, as external service states or network flakiness do not affect test outcomes.
When should I use go-vcr in my tests?
You should use go-vcr when writing integration or unit tests for Go applications that make HTTP requests to third-party APIs or external services. It's particularly useful when these external dependencies are slow, unreliable, or costly to call repeatedly.
Can go-vcr customize how requests are matched or recorded?
Yes, go-vcr allows customization of request matching during replay mode through `recorder.MatcherFunc` functions. It also supports `Hooks` to modify requests or responses before they are saved or replayed, useful for redacting sensitive data like Authorization headers.