-
Notifications
You must be signed in to change notification settings - Fork 82
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
Proposal: make_request helpers shouldn't assert status code #165
Comments
Ah, sorry for the confusion. When I wrote these, I was trying to minimize the boilerplate. It seemed like the alternative added several lines of code to every caller. It's not just the assertion about the status code. Today, we give you back either All existing callers today are relying on this behavior, and it's a public interface so this would be a breaking change. These interfaces are getting pretty unwieldy anyway. I'd suggest we develop a new client testing interface (it need not even be part of dropshot, though it could be if that's more convenient). There might be something out there already that does this better. If not, I'd probably start with a builder pattern. Maybe something like: TestRequest::build()
.method(Method::GET)
.url(...)
[.body(...)]
[.header(...)]
.execute()
.await
.assert_status_code(http::StatusCode::OK)
.parse_response_as::<Result<SuccessType>, HttpErrorResponseBody>() The existing thing also checks that a 204 has no response body. It'd be nice to preserve that. |
Totally agree about a new interface, that sounds great. We have a lot more examples to abstract from now. I've tried to do that a bit with wrappers around stuff in |
I don't mind the response-parsing stuff in the helpers, I think that's appropriate. I don't even mind the bit where we assert that a 204 actually has an empty body. All that stuff is about the internal consistency of a response. I just don't think asserting about a particular response code fits in with that. |
It confuses me every time that a helper called
make_request_with_body
takes a status code and asserts the response has it. I would much rather see explicit asserts in the calling test code. The main problem I see with making this change is that if you take out an assert, callers are required to add in the assert in their test code, otherwise any existing tests will continue to silently pass even if they're not supposed to.The text was updated successfully, but these errors were encountered: