Skip to content

Commit f8db4bb

Browse files
committed
Add test case for deserialize error
1 parent 6ace820 commit f8db4bb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/error.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ impl RestPath<u16> for HttpBinDelay {
4242
}
4343
}
4444

45+
#[derive(Serialize, Deserialize)]
46+
struct HttpBinBase64 {}
47+
48+
impl RestPath<String> for HttpBinBase64 {
49+
fn get_path(data: String) -> Result<String, Error> {
50+
Ok(format!("base64/{}", data))
51+
}
52+
}
53+
4554
#[test]
4655
fn invalid_baseurl() {
4756
match RestClient::new("1234") {
@@ -106,3 +115,18 @@ fn request_timeout() {
106115
panic!("expected timeout error");
107116
}
108117
}
118+
119+
#[test]
120+
fn deserialize_error() {
121+
let mut client = RestClient::new("http://httpbin.org").unwrap();
122+
123+
// Service returns decoded base64 in body which should be string 'test'.
124+
// This fails JSON deserialization and is returned in the Error
125+
if let Err(Error::DeserializeParseError(_, data)) =
126+
client.get::<String, HttpBinBase64>("dGVzdA==".to_string())
127+
{
128+
assert!(data == "test");
129+
} else {
130+
panic!("expected serialized error");
131+
}
132+
}

0 commit comments

Comments
 (0)