#[macro_use] extern crate json;
#[macro_use] extern crate noir;
#[macro_use]
mod base_test;
test!();
// Expected Header ------------------------------------------------------------
#[test]
fn test_headers_expected() {
let actual = {
API::get("/get/hello")
.expected_header(Server("Servername".to_string()))
.collect()
};
assert_pass!(actual);
}
#[test]
fn test_headers_expected_multiple() {
let actual = {
API::get("/get/hello")
.expected_headers(headers![
Server("Servername".to_string())
])
.collect()
};
assert_pass!(actual);
}
#[test]
fn test_headers_expected_multiple_trailing_comma() {
let actual = {
API::get("/get/hello")
.expected_headers(headers![
Server("Servername".to_string()),
])
.collect()
};
assert_pass!(actual);
}
#[test]
fn test_headers_expected_mismatch() {
let actual = {
API::get("/get/hello")
.expected_header(Server("Servername Foo".to_string()))
.collect()
};
assert_fail!(r#"
Response Failure: GET request to \"http://localhost:4000/get/hello\" returned
1 error(s)
1) Response header \"Server\" does not match, expected:
\"Servername Foo\"
but got:
\"
Servername\"
"#, actual);
}
// With Headers ---------------------------------------------------------------
#[test]
fn test_headers_with_expected() {
let actual = {
API::get("/headers/echo")
.with_header(Accept(vec![
qitem(Mime(TopLevel::Application, SubLevel::Json, vec![]))
]))
.expected_headers(headers![Accept(vec![
qitem(Mime(TopLevel::Application, SubLevel::Json, vec![]))
])])
.collect()
};
assert_pass!(actual);
}
// Unexpected Header ------------------------------------------------------------
#[test]
fn test_headers_unexpected() {
let actual = {
API::get("/echo/method")
.unexpected_header::()
.collect()
};
assert_pass!(actual);
}
#[test]
fn test_headers_unexpected_mismatch() {
let actual = {
API::get("/get/hello")
.unexpected_header::()
.collect()
};
assert_fail!(r#"
Response Failure: GET request to \"http://localhost:4000/get/hello\" returned
1 error(s)
1) Response header \"Server\" was expected to be absent, but
is present.
"#, actual);
}