#[macro_use] extern crate json; #[macro_use] extern crate noir; #[macro_use] mod base_test; test!(); #[test] fn test_responses_provided_with_header() { let actual = { API::get("/responses/one") .provide(responses![ EXAMPLE.get("/one") .with_header(Accept(vec![ qitem(Mime(TopLevel::Application, SubLevel::Json, vec![])) ])) ]) .expected_header(Accept(vec![ qitem(Mime(TopLevel::Application, SubLevel::Json, vec![])) ])) .collect() }; assert_pass!(actual); } #[test] fn test_responses_provided_with_expected_header() { let actual = { API::get("/responses/one") .provide(responses![ EXAMPLE.get("/one") .expected_header(Accept(vec![ qitem(Mime(TopLevel::Application, SubLevel::Json, vec![])) ])) ]) .collect() }; assert_pass!(actual); } #[test] fn test_responses_provided_with_expected_header_multiple() { let actual = { API::get("/responses/one") .provide(responses![ EXAMPLE.get("/one") .expected_headers(headers![ Accept(vec![ qitem(Mime(TopLevel::Application, SubLevel::Json, vec![])) ]) ]) ]) .collect() }; assert_pass!(actual); } #[test] fn test_responses_provided_with_expected_header_mismatch() { let actual = { API::get("/responses/one") .provide(responses![ EXAMPLE.get("/one") .expected_header(Accept(vec![ qitem(Mime(TopLevel::Text, SubLevel::Plain, vec![])) ])) ]) .collect() }; assert_fail!(r#"
Response Failure: GET request to \"http://localhost:4000/responses/one\" returned
1 error(s)
1)
Request Failure: GET response provided for \"https://example.com/one\" returned
1 error(s)
1.1) Request header \"Accept\" does not match, expected: \"text/plain\" but got: \"
application/json\" "#, actual); } #[test] fn test_responses_provided_with_unexpected_header() { let actual = { API::get("/responses/one") .provide(responses![ EXAMPLE.get("/one") .unexpected_header::() ]) .collect() }; assert_pass!(actual); } #[test] fn test_responses_provided_with_unexpected_header_mismatch() { let actual = { API::get("/responses/one") .provide(responses![ EXAMPLE.get("/one") .unexpected_header::() ]) .collect() }; assert_fail!(r#"
Response Failure: GET request to \"http://localhost:4000/responses/one\" returned
1 error(s)
1)
Request Failure: GET response provided for \"https://example.com/one\" returned
1 error(s)
1.1) Request header \"Accept\" was expected to be absent, but
is present. "#, actual); }