Skip to content
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

Provide mock HttpClient #81

Open
abonander opened this issue Oct 18, 2019 · 2 comments
Open

Provide mock HttpClient #81

abonander opened this issue Oct 18, 2019 · 2 comments

Comments

@abonander
Copy link
Contributor

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.

@yoshuawuyts
Copy link
Member

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

@yoshuawuyts
Copy link
Member

@abonander I've filed a tracking issue for it here: http-rs/http-client#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants