fix tests for ContentDisposition macro support
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
bb93521103
commit
1d0b06b581
@ -28,7 +28,7 @@ pub struct Request {
|
|||||||
#[ruma_api(header = LOCATION)]
|
#[ruma_api(header = LOCATION)]
|
||||||
pub location: String,
|
pub location: String,
|
||||||
#[ruma_api(header = CONTENT_DISPOSITION)]
|
#[ruma_api(header = CONTENT_DISPOSITION)]
|
||||||
pub content_disposition: ContentDisposition,
|
pub content_disposition: Option<ContentDisposition>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Response type for the `required_headers` endpoint.
|
/// Response type for the `required_headers` endpoint.
|
||||||
@ -37,7 +37,7 @@ pub struct Response {
|
|||||||
#[ruma_api(header = LOCATION)]
|
#[ruma_api(header = LOCATION)]
|
||||||
pub stuff: String,
|
pub stuff: String,
|
||||||
#[ruma_api(header = CONTENT_DISPOSITION)]
|
#[ruma_api(header = CONTENT_DISPOSITION)]
|
||||||
pub content_disposition: ContentDisposition,
|
pub content_disposition: Option<ContentDisposition>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -45,8 +45,10 @@ fn request_serde() {
|
|||||||
let location = "https://other.tld/page/";
|
let location = "https://other.tld/page/";
|
||||||
let content_disposition = ContentDisposition::new(ContentDispositionType::Attachment)
|
let content_disposition = ContentDisposition::new(ContentDispositionType::Attachment)
|
||||||
.with_filename(Some("my_file".to_owned()));
|
.with_filename(Some("my_file".to_owned()));
|
||||||
let req =
|
let req = Request {
|
||||||
Request { location: location.to_owned(), content_disposition: content_disposition.clone() };
|
location: location.to_owned(),
|
||||||
|
content_disposition: Some(content_disposition.clone()),
|
||||||
|
};
|
||||||
|
|
||||||
let mut http_req = req
|
let mut http_req = req
|
||||||
.clone()
|
.clone()
|
||||||
@ -61,7 +63,7 @@ fn request_serde() {
|
|||||||
|
|
||||||
let req2 = Request::try_from_http_request::<_, &str>(http_req.clone(), &[]).unwrap();
|
let req2 = Request::try_from_http_request::<_, &str>(http_req.clone(), &[]).unwrap();
|
||||||
assert_eq!(req2.location, location);
|
assert_eq!(req2.location, location);
|
||||||
assert_eq!(req2.content_disposition, content_disposition);
|
assert_eq!(req2.content_disposition, Some(content_disposition));
|
||||||
|
|
||||||
// Try removing the headers.
|
// Try removing the headers.
|
||||||
http_req.headers_mut().remove(LOCATION).unwrap();
|
http_req.headers_mut().remove(LOCATION).unwrap();
|
||||||
@ -93,8 +95,10 @@ fn response_serde() {
|
|||||||
let location = "https://other.tld/page/";
|
let location = "https://other.tld/page/";
|
||||||
let content_disposition = ContentDisposition::new(ContentDispositionType::Attachment)
|
let content_disposition = ContentDisposition::new(ContentDispositionType::Attachment)
|
||||||
.with_filename(Some("my_file".to_owned()));
|
.with_filename(Some("my_file".to_owned()));
|
||||||
let res =
|
let res = Response {
|
||||||
Response { stuff: location.to_owned(), content_disposition: content_disposition.clone() };
|
stuff: location.to_owned(),
|
||||||
|
content_disposition: Some(content_disposition.clone()),
|
||||||
|
};
|
||||||
|
|
||||||
let mut http_res = res.clone().try_into_http_response::<Vec<u8>>().unwrap();
|
let mut http_res = res.clone().try_into_http_response::<Vec<u8>>().unwrap();
|
||||||
assert_matches!(http_res.headers().get(LOCATION), Some(_));
|
assert_matches!(http_res.headers().get(LOCATION), Some(_));
|
||||||
@ -102,7 +106,7 @@ fn response_serde() {
|
|||||||
|
|
||||||
let res2 = Response::try_from_http_response(http_res.clone()).unwrap();
|
let res2 = Response::try_from_http_response(http_res.clone()).unwrap();
|
||||||
assert_eq!(res2.stuff, location);
|
assert_eq!(res2.stuff, location);
|
||||||
assert_eq!(res2.content_disposition, content_disposition);
|
assert_eq!(res2.content_disposition, Some(content_disposition));
|
||||||
|
|
||||||
// Try removing the headers.
|
// Try removing the headers.
|
||||||
http_res.headers_mut().remove(LOCATION).unwrap();
|
http_res.headers_mut().remove(LOCATION).unwrap();
|
||||||
|
@ -313,7 +313,7 @@ mod tests {
|
|||||||
let outgoing_metadata = ContentMetadata::new();
|
let outgoing_metadata = ContentMetadata::new();
|
||||||
let outgoing_content = FileOrLocation::File(Content {
|
let outgoing_content = FileOrLocation::File(Content {
|
||||||
file: file.to_vec(),
|
file: file.to_vec(),
|
||||||
content_type: Some(content_type.to_owned()),
|
content_type: Some(content_type.into()),
|
||||||
content_disposition: Some(content_disposition.clone()),
|
content_disposition: Some(content_disposition.clone()),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -340,7 +340,7 @@ mod tests {
|
|||||||
let outgoing_metadata = ContentMetadata::new();
|
let outgoing_metadata = ContentMetadata::new();
|
||||||
let outgoing_content = FileOrLocation::File(Content {
|
let outgoing_content = FileOrLocation::File(Content {
|
||||||
file: file.to_vec(),
|
file: file.to_vec(),
|
||||||
content_type: Some(content_type.to_owned()),
|
content_type: Some(content_type.into()),
|
||||||
content_disposition: Some(content_disposition.clone()),
|
content_disposition: Some(content_disposition.clone()),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ impl Response {
|
|||||||
let syn::GenericArgument::Type(field_type) = option_args.first().unwrap() else {
|
let syn::GenericArgument::Type(field_type) = option_args.first().unwrap() else {
|
||||||
panic!("Option brackets should contain type");
|
panic!("Option brackets should contain type");
|
||||||
};
|
};
|
||||||
let syn::Type::Path(syn::TypePath { path: syn::Path { segments, .. }, .. }) = field_type else {
|
let Type::Path(syn::TypePath { path: syn::Path { segments, .. }, .. }) = field_type else {
|
||||||
panic!("Option type should have a path")
|
panic!("Option type should have a path")
|
||||||
};
|
};
|
||||||
let ident = &segments.last().expect("Option type should have path segments").ident;
|
let ident = &segments.last().expect("Option type should have path segments").ident;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user