#[macro_use] extern crate json; #[macro_use] extern crate noir; #[macro_use] mod base_test; test!(); use std::io::{Error, ErrorKind}; #[test] fn test_responses_provided() { let actual = { API::get("/responses/one") .provide(responses![ EXAMPLE.get("/one") ]) .collect() }; assert_pass!(actual); } #[test] fn test_responses_provided_trailing_comma() { let actual = { API::get("/responses/one") .provide(responses![ EXAMPLE.get("/one"), ]) .collect() }; assert_pass!(actual); } #[test] fn test_responses_provided_missing() { let actual = { API::get("/responses/none") .provide(responses![ EXAMPLE.get("/one") ]) .collect() }; assert_fail!(r#"
Response Failure: GET request to \"http://localhost:4000/responses/none\" returned
1 error(s)
1)
Request Failure: GET response provided for \"https://example.com/one\" returned
1 error(s)
1.1) Expected a request for the response, but got
none. "#, actual); } #[test] fn test_responses_provided_ext_method() { let actual = { API::get("/response/upgrade") .provide(responses![ EXAMPLE.ext("UPGRADE", "/upgrade") ]) .collect() }; assert_pass!(actual); } #[test] fn test_responses_provided_with_error() { let actual = { API::get("/responses/one") .provide(responses![ EXAMPLE.get("/one").with_error(Error::new(ErrorKind::ConnectionRefused, "Mocked Error")) ]) .expected_body("Mocked Error") .collect() }; assert_pass!(actual); } #[test] fn test_responses_provided_multiple_errors() { let actual = { API::get("/responses/one") .provide(responses![ EXAMPLE.get("/one") .expected_header(ContentType(Mime(TopLevel::Application, SubLevel::Json, vec![]))) .expected_header(Server("Foo".to_string())) .expected_body("Hello World") ]) .collect() }; assert_fail!(r#"
Response Failure: GET request to \"http://localhost:4000/responses/one\" returned
3 error(s)
1)
Request Failure: GET response provided for \"https://example.com/one\" returned
3 error(s)
1.1) Request header \"Content-Type\" was expected to be present, but
is missing.
1.2) Request header \"Server\" was expected to be present, but
is missing.
1.3) Request raw body data does not match, expected the following 11 bytes: [0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64] but got the following
0 bytes instead: [] "#, actual); }