Golang Unit Testing library to ensuring API/JSON based contracts using snapshots.
- Ignore changing values in snapshots
- First class API JSON support
- Extends existing unit and integration tests
- Compare current and recorded responses from the API
- Autoupdate response snapshots for visibility.
- Report errors if responses formats doesn't match
func TestAPIContract(t *testing.T) {
var apiResponse interface{}
// check that the result is the same as the last time the snapshot was updated
snapcontract.SnapshotT(t, apiResponseast)
}
UPDATE_SNAPSHOTS=true go test ./...
This will fail all tests where the snapshot was updated (to stop you accidentally updating snapshots in CI) but your snapshot files will now have been updated to reflect the current output of your code.