1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-22 20:52:27 +00:00
deprecated-gotham-restful/tests/resource_error.rs

38 lines
1 KiB
Rust
Raw Permalink Normal View History

2020-11-22 23:18:28 +01:00
use gotham_restful::ResourceError;
#[derive(ResourceError)]
enum Error {
#[display("I/O Error: {0}")]
IoError(#[from] std::io::Error),
#[status(INTERNAL_SERVER_ERROR)]
#[display("Internal Server Error: {0}")]
InternalServerError(String)
}
2021-01-14 18:37:51 +01:00
#[allow(deprecated)]
2020-11-22 23:18:28 +01:00
mod resource_error {
use super::Error;
use gotham::hyper::StatusCode;
use gotham_restful::IntoResponseError;
use mime::APPLICATION_JSON;
#[test]
fn io_error() {
let err = Error::IoError(std::io::Error::last_os_error());
let res = err.into_response_error().unwrap();
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
assert_eq!(res.mime(), Some(&APPLICATION_JSON));
2020-11-22 23:18:28 +01:00
}
#[test]
fn internal_server_error() {
let err = Error::InternalServerError("Brocken".to_owned());
assert_eq!(&format!("{}", err), "Internal Server Error: Brocken");
let res = err.into_response_error().unwrap();
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
assert_eq!(res.mime(), None); // TODO shouldn't this be a json error message?
2020-11-22 23:18:28 +01:00
}
}