-
-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add server-side recording and test replay #101
Conversation
renamed to draft since this likely needs more tests |
6176d57
to
327472e
Compare
Hey @calvinmclean , Nice PR, thanks! Let me know when it's ready for review and I'll check it out :) |
@dnaeon, I made a few improvements and added more tests so it should be ready for review! |
Hey @calvinmclean , Thanks again! Could you please rebase the PR against the latest changes in |
Hey @calvinmclean , I've just pushed EDIT-1: Actually, nevermind, lets use EDIT-2: @calvinmclean , I've just completed with the refactoring for next There were some long-standing things I wanted to clean up from the code base, which I just did. Would you mind refactoring the code against the |
@dnaeon thanks! I'll rebase shortly. I can also change the header matching function to try and reuse some of the existing matcher instead of requiring Go 1.22 features for maps and slices to preserve some compatibility. What do you think? |
@calvinmclean , I've just set the minimum version of Go to I think you should probably use whatever is provided in the standard lib as part of 1.22 and later, that makes the code more idiomatic. Thanks! |
@calvinmclean , something else that I was thinking about is whether to call the |
Yeah good idea! I'll use |
- Use a server-side middleware to record requests from an external client and record the server's response - Replay these recorded interactions to test that the server produces the same responses
bd14a61
to
1a8ab5f
Compare
@dnaeon The new options pattern in v4 is a nice improvement! |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## v4 #101 +/- ##
==========================================
- Coverage 59.01% 51.91% -7.11%
==========================================
Files 2 4 +2
Lines 427 497 +70
==========================================
+ Hits 252 258 +6
- Misses 156 218 +62
- Partials 19 21 +2 ☔ View full report in Codecov by Sentry. |
1a8ab5f
to
5ae4774
Compare
Hey @calvinmclean , thanks! |
Description
Rather than mocking/recording external HTTP interactions, this enables recording and replaying incoming interactions with your application's HTTP server.
This works by putting the
Recorder
in a middleware and uses the existing code for recording request/response. Instead of using aRoundTripper
to get the response, the middleware provides the underlying handler's actual response.Then, a few methods are added to the
cassette
package for replaying and testing the recorded interactions.No breaking changes.
More details
Hello! Thanks for creating such a great library for testing HTTP clients.
I have a need for doing something similar on the server-side to record interactions and convert them into regression tests. Initially I was able to create a separate library that wraps the
Recorder
to achieve this, but realized it will be better if I integrate it directly, especially after seeing #88.If I create this as a separate library/package, then I have to use
rec.SetRealTransport
for each request in the middleware which likely isn't safe for concurrent use.I expect to receive some feedback and discussion as part of this PR, so I am open to any suggestions on how to make this a better fit for the library.
Lastly, no hard feelings if you choose to decline this PR 🙂