A Go library for recording and replaying HTTP/HTTPS interactions as mock cassettes for offline testing.
govcr is an HTTP mock library for Go that records live HTTP traffic to cassette files and replays those interactions during subsequent test runs. It enables reliable offline testing by eliminating flaky network dependencies and ensuring deterministic test behavior.
Go developers writing unit, behavioral, or integration tests that involve HTTP or HTTPS calls and need to mock external API dependencies.
Developers choose govcr for its flexible, non-intrusive approach to mocking HTTP interactions without modifying application logic, and for features like configurable request matching, track mutators, cassette encryption, and support for multiple storage backends including AWS S3.
HTTP mock for Golang: record and replay HTTP/HTTPS interactions for offline testing
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Supports configurable matchers from strict to relaxed comparison, allowing developers to ignore dynamic headers like timestamps for reliable playback, as shown in the simple VCR example.
Enables transformation of requests and responses during recording or playback via mutators, useful for handling sensitive data or dynamic IDs without modifying application logic, detailed in the cookbook recipes.
Provides built-in encryption with AES-GCM or ChaCha20Poly1305 ciphers using secret keys, securing sensitive test data in cassette files, with examples for encryption and decryption.
Allows cassettes to be stored locally or on cloud services like AWS S3, facilitating team collaboration and CI/CD integration, as demonstrated in the AWS S3 storage recipe.
Does not properly handle HTTP headers with multiple values, which can break mocking for APIs that depend on such headers, as acknowledged in the limitations section.
Serializes HTTP transport errors into strings when recording to cassette, losing the original Go error type and making precise error assertions in tests difficult, despite some mitigations for common errors.
Recording of TLS data, especially PublicKey in certificates, is unreliable due to Go's json package limitations with interface{} types, as noted in the bugs section.