yup-hyper-mock 3.15.0

A utility library for testing clients using hyper

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.


Set it up for use in tests in Cargo.toml

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

mod tests {
    use hyper;

    mock_connector!(MockRedirectPolicy {
        "" =>       "HTTP/1.1 301 Redirect\r\n\
                                     Server: mock1\r\n\
        "" =>       "HTTP/1.1 302 Found\r\n\
                                     Server: mock2\r\n\
        "" =>      "HTTP/1.1 200 OK\r\n\
                                     Server: mock3\r\n\

    fn test_redirect_followall() {
        let mut client = hyper::Client::with_connector(MockRedirectPolicy::default());

        let res = client.get("").send().unwrap();
        assert_eq!(res.headers.get(), Some(&hyper::header::Server("mock3".to_owned())));


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


Licensed under either of


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.