go-vcr — screenshot of github.com

go-vcr

go-vcr is a Go library for recording and replaying HTTP interactions, simplifying the creation of fast, deterministic, and accurate tests. I find this essential for mocking external APIs without complex setup.

Visit github.com →

Questions & Answers

What is go-vcr?
go-vcr is a Go library designed to record and replay HTTP interactions. It enables deterministic testing by capturing external HTTP requests and responses into YAML "cassettes" and then replaying them in subsequent test runs without making actual network calls.
Who can benefit from using go-vcr?
Developers writing Go applications that interact with external HTTP services can benefit from go-vcr. It is particularly useful for those who need to create reliable, fast, and isolated unit or integration tests without depending on live external APIs.
How does go-vcr compare to other Go testing approaches?
Unlike simple mocking libraries that require manual definition of HTTP responses, go-vcr automates the capture and replay process. It creates actual YAML files representing HTTP interactions, providing a concrete and replayable artifact that can be version-controlled, contrasting with runtime-only mocking.
When is the best time to incorporate go-vcr into a project?
go-vcr is ideal for use during the testing phase of a project where your code makes HTTP requests to third-party APIs or external services. It helps ensure tests are stable and quick by removing network dependencies and flaky external services.
Can go-vcr handle sensitive data in recorded interactions?
Yes, go-vcr provides "hooks" that allow modification of interactions at various stages, such as AfterCaptureHook or BeforeSaveHook. Developers can use these hooks to redact or remove sensitive information, like Authorization headers, before data is stored in the cassette.