update json tests

This commit is contained in:
Corentin Henry
2017-05-31 16:42:44 -07:00
parent 2f1b3b352b
commit 80a80379d3

View File

@@ -827,7 +827,7 @@ mod tests {
let mut json_data = HashMap::new();
json_data.insert("foo", "bar");
r = r.json(&json_data);
r = r.json(&json_data).unwrap();
// Make sure the content type was set
assert_eq!(r.headers.get::<ContentType>(), Some(&ContentType::json()));
@@ -837,4 +837,24 @@ mod tests {
let body_should_be = serde_json::to_string(&json_data).unwrap();
assert_eq!(buf, body_should_be);
}
#[test]
fn add_json_fail() {
use serde::{Serialize, Serializer};
use serde::ser::Error;
struct MyStruct;
impl Serialize for MyStruct {
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer
{
Err(S::Error::custom("nope"))
}
}
let client = Client::new().unwrap();
let some_url = "https://google.com/";
let r = client.post(some_url);
let json_data = MyStruct{};
assert_eq!(format!("{}", r.json(&json_data).unwrap_err()), "nope".to_string());
}
}