surf
surf copied to clipboard
Provide mock `HttpClient`
This would make testing anything using a REST API simpler as one could just mock out the responses.
yup_hyper_mock lets you create a mock Connector implementation that responds to various hostnames:
mock_connector!(MockRedirectPolicy {
"http://127.0.0.1" => "HTTP/1.1 301 Redirect\r\n\
Location: http://127.0.0.2\r\n\
Server: mock1\r\n\
\r\n\
"
"http://127.0.0.2" => "HTTP/1.1 302 Found\r\n\
Location: https://127.0.0.3\r\n\
Server: mock2\r\n\
\r\n\
"
"https://127.0.0.3" => "HTTP/1.1 200 OK\r\n\
Server: mock3\r\n\
\r\n\
"
});
Since we have access to the full request in HttpClient we have a lot more flexibility with matching requests; ideally it should be able to match on paths and body contents.
@abonander oh yeah, that'd be very nice to have!
@abonander I've filed a tracking issue for it here: https://github.com/http-rs/http-client/issues/2