Remove verbose error types from tests
This commit is contained in:
parent
19806cc9d1
commit
a774771fc9
@ -37,7 +37,7 @@ ruma_api! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn request_serde() -> Result<(), Box<dyn std::error::Error + 'static>> {
|
fn request_serde() {
|
||||||
let req = Request {
|
let req = Request {
|
||||||
hello: "hi".to_owned(),
|
hello: "hi".to_owned(),
|
||||||
world: "test".to_owned(),
|
world: "test".to_owned(),
|
||||||
@ -47,8 +47,8 @@ fn request_serde() -> Result<(), Box<dyn std::error::Error + 'static>> {
|
|||||||
user: user_id!("@bazme:ruma.io"),
|
user: user_id!("@bazme:ruma.io"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let http_req = req.clone().try_into_http_request("https://homeserver.tld", None)?;
|
let http_req = req.clone().try_into_http_request("https://homeserver.tld", None).unwrap();
|
||||||
let req2 = Request::try_from_http_request(http_req.map(std::io::Cursor::new))?;
|
let req2 = Request::try_from_http_request(http_req.map(std::io::Cursor::new)).unwrap();
|
||||||
|
|
||||||
assert_eq!(req.hello, req2.hello);
|
assert_eq!(req.hello, req2.hello);
|
||||||
assert_eq!(req.world, req2.world);
|
assert_eq!(req.world, req2.world);
|
||||||
@ -56,12 +56,10 @@ fn request_serde() -> Result<(), Box<dyn std::error::Error + 'static>> {
|
|||||||
assert_eq!(req.q2, req2.q2);
|
assert_eq!(req.q2, req2.q2);
|
||||||
assert_eq!(req.bar, req2.bar);
|
assert_eq!(req.bar, req2.bar);
|
||||||
assert_eq!(req.user, req2.user);
|
assert_eq!(req.user, req2.user);
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn request_with_user_id_serde() -> Result<(), Box<dyn std::error::Error + 'static>> {
|
fn request_with_user_id_serde() {
|
||||||
let req = Request {
|
let req = Request {
|
||||||
hello: "hi".to_owned(),
|
hello: "hi".to_owned(),
|
||||||
world: "test".to_owned(),
|
world: "test".to_owned(),
|
||||||
@ -73,7 +71,7 @@ fn request_with_user_id_serde() -> Result<(), Box<dyn std::error::Error + 'stati
|
|||||||
|
|
||||||
let user_id = user_id!("@_virtual_:ruma.io");
|
let user_id = user_id!("@_virtual_:ruma.io");
|
||||||
let http_req =
|
let http_req =
|
||||||
req.try_into_http_request_with_user_id("https://homeserver.tld", None, user_id)?;
|
req.try_into_http_request_with_user_id("https://homeserver.tld", None, user_id).unwrap();
|
||||||
|
|
||||||
let query = http_req.uri().query().unwrap();
|
let query = http_req.uri().query().unwrap();
|
||||||
|
|
||||||
@ -81,8 +79,6 @@ fn request_with_user_id_serde() -> Result<(), Box<dyn std::error::Error + 'stati
|
|||||||
query,
|
query,
|
||||||
"q1=query_param_special_chars+%25%2F%26%40%21&q2=55&user_id=%40_virtual_%3Aruma.io"
|
"q1=query_param_special_chars+%25%2F%26%40%21&q2=55&user_id=%40_virtual_%3Aruma.io"
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod without_query {
|
mod without_query {
|
||||||
@ -118,8 +114,7 @@ mod without_query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn request_without_query_with_user_id_serde() -> Result<(), Box<dyn std::error::Error + 'static>>
|
fn request_without_query_with_user_id_serde() {
|
||||||
{
|
|
||||||
let req = Request {
|
let req = Request {
|
||||||
hello: "hi".to_owned(),
|
hello: "hi".to_owned(),
|
||||||
world: "test".to_owned(),
|
world: "test".to_owned(),
|
||||||
@ -128,13 +123,12 @@ mod without_query {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let user_id = user_id!("@_virtual_:ruma.io");
|
let user_id = user_id!("@_virtual_:ruma.io");
|
||||||
let http_req =
|
let http_req = req
|
||||||
req.try_into_http_request_with_user_id("https://homeserver.tld", None, user_id)?;
|
.try_into_http_request_with_user_id("https://homeserver.tld", None, user_id)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let query = http_req.uri().query().unwrap();
|
let query = http_req.uri().query().unwrap();
|
||||||
|
|
||||||
assert_eq!(query, "user_id=%40_virtual_%3Aruma.io");
|
assert_eq!(query, "user_id=%40_virtual_%3Aruma.io");
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,14 +60,14 @@ mod tests {
|
|||||||
use super::IncomingRequest;
|
use super::IncomingRequest;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_unset_request() -> Result<(), Box<dyn std::error::Error>> {
|
fn deserialize_unset_request() {
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
IncomingRequest::try_from_http_request(
|
IncomingRequest::try_from_http_request(
|
||||||
http::Request::builder()
|
http::Request::builder()
|
||||||
.method("PUT")
|
.method("PUT")
|
||||||
.uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url")
|
.uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url")
|
||||||
.body(&[] as &[u8])?,
|
.body(&[] as &[u8]).unwrap(),
|
||||||
)?,
|
).unwrap(),
|
||||||
IncomingRequest { user_id, avatar_url: None } if user_id == "@foo:bar.org"
|
IncomingRequest { user_id, avatar_url: None } if user_id == "@foo:bar.org"
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -78,9 +78,9 @@ mod tests {
|
|||||||
.method("PUT")
|
.method("PUT")
|
||||||
.uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url")
|
.uri("https://bar.org/_matrix/client/r0/profile/@foo:bar.org/avatar_url")
|
||||||
.body(std::io::Cursor::new(
|
.body(std::io::Cursor::new(
|
||||||
serde_json::to_vec(&serde_json::json!({ "avatar_url": "" }))?,
|
serde_json::to_vec(&serde_json::json!({ "avatar_url": "" })).unwrap(),
|
||||||
))?,
|
)).unwrap(),
|
||||||
)?,
|
).unwrap(),
|
||||||
IncomingRequest { user_id, avatar_url: None } if user_id == "@foo:bar.org"
|
IncomingRequest { user_id, avatar_url: None } if user_id == "@foo:bar.org"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user