-
Notifications
You must be signed in to change notification settings - Fork 124
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
Refactor test suite to make real requests to a real server #131
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mccutchen
changed the title
Giant test refactor
Refactor test suite to make real HTTP requests to a real HTTP server
Jun 27, 2023
mccutchen
changed the title
Refactor test suite to make real HTTP requests to a real HTTP server
Refactor test suite to make real requests to a real server
Jun 27, 2023
Codecov Report
@@ Coverage Diff @@
## main #131 +/- ##
==========================================
+ Coverage 97.84% 98.06% +0.21%
==========================================
Files 8 8
Lines 1482 1495 +13
==========================================
+ Hits 1450 1466 +16
+ Misses 23 21 -2
+ Partials 9 8 -1
|
mccutchen
added a commit
that referenced
this pull request
Jun 29, 2023
A set of test suite improvements following up on #131: - Make sure we always fully consume and close response bodies, to allow the shared HTTP client to reuse connections to the local test server whenever possible - Make order of arguments to equality assertions consistent, so failed test output makes sense
mccutchen
added a commit
that referenced
this pull request
Jul 1, 2023
Standardize on structured JSON error responses everywhere we can, with only one exception where the error is a warning for humans to read. Fixes #108 by adding a check to every request in the test suite to ensure that errors are never served with a Content-Type that might enable XSS or other vulnerabilities. While we're at it, continue refining the test suite and further adopting some of the testing helpers added in #131.
sonbui00
added a commit
to sonbui00/go-httpbin
that referenced
this pull request
Aug 7, 2023
Signed-off-by: Son Bui <sonbv00@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the course of validating #125, we discovered that using the stdlib's
httptest.ResponseRecorder
mechanism to drive the vast majority of our unit tests led to some slight brokenness due to subtle differences in the way those "simulated" requests are handled vs "real" requests to a live HTTP server, as explained in this comment.That prompted me to do a big ass refactor of the entire test suite, swapping httptest.ResponseRecorder for interacting with a live server instance via
httptest.Server
.This should make the test suite more accurate and reliable in the long run by ensuring that the vast majority of tests are making actual HTTP requests and reading responses from the wire.
Note that updating these tests also uncovered a few minor bugs in existing handler code, fixed in a separate commit for visibility.
P.S. I'm awfully sorry to anyone who tries to merge or rebase local test changes after this refactor lands, that is goign to be a nightmare. If you run into issues resolving conflicts, feel free to ping me and I can try to help!