surf icon indicating copy to clipboard operation
surf copied to clipboard

Provide mock `HttpClient`

Open abonander opened this issue 6 years ago • 2 comments

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 avatar Oct 18 '19 20:10 abonander

@abonander oh yeah, that'd be very nice to have!

yoshuawuyts avatar Oct 30 '19 15:10 yoshuawuyts

@abonander I've filed a tracking issue for it here: https://github.com/http-rs/http-client/issues/2

yoshuawuyts avatar Nov 20 '19 00:11 yoshuawuyts