yup-hyper-mock 0.1.8

A utility library for testing clients using hyper
docs.rs failed to build yup-hyper-mock-0.1.8
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: yup-hyper-mock-8.0.0

Build Status

hyper-mock is a utility library to help hyper clients with their testing. It provides types used to test hyper itself, most notably, mock connections and macros to ease their use.

Usage

Set it up for use in tests in Cargo.toml

[dev-dependencies]
yup-hyper-mock = "*"
log = "*"  # log macros are used within yup-hyper-mock

Link it in case you are testing only in your src/(lib.rs|main.rs)

#[cfg(test)] #[macro_use]
extern crate "yup-hyper-mock" as hyper_mock

In your tests module

#[cfg(test)]
mod tests {
    use hyper;

    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\
                                    "

    #[test]
    fn test_redirect_followall() {
        let mut client = hyper::Client::with_connector(MockRedirectPolicy);
        client.set_redirect_policy(hyper::RedirectPolicy::FollowAll);

        let res = client.get("http://127.0.0.1").send().unwrap();
        assert_eq!(res.headers.get(), Some(&hyper::Server("mock3".to_string())));
    }
}

Credits

yup-hyper-mock is code from hyper/src/mock.rs, which was adjusted to work within its very own crate.