update json tests
This commit is contained in:
		| @@ -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()); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user