1
0
mirror of https://github.com/actix/actix-website synced 2025-02-26 05:43:52 +01:00

40 lines
1.0 KiB
Rust
Raw Normal View History

2019-06-24 17:43:31 -04:00
pub mod integration_one;
pub mod integration_two;
pub mod stream_response;
use actix_web::{http, web, App, HttpRequest, HttpResponse};
2019-06-17 15:39:58 -04:00
async fn index(req: HttpRequest) -> HttpResponse {
2019-06-17 15:39:58 -04:00
if let Some(hdr) = req.headers().get(http::header::CONTENT_TYPE) {
if let Ok(_s) = hdr.to_str() {
return HttpResponse::Ok().into();
}
}
HttpResponse::BadRequest().into()
}
fn main() {
2019-06-24 17:43:31 -04:00
App::new().route("/", web::get().to(index));
}
// <unit-tests>
#[cfg(test)]
mod tests {
use super::*;
use actix_web::test;
2019-06-17 15:39:58 -04:00
#[actix_rt::test]
async fn test_index_ok() {
let req = test::TestRequest::with_header("content-type", "text/plain").to_http_request();
let resp = index(req).await;
2019-06-24 17:43:31 -04:00
assert_eq!(resp.status(), http::StatusCode::OK);
}
#[actix_rt::test]
async fn test_index_not_ok() {
2019-06-24 17:43:31 -04:00
let req = test::TestRequest::default().to_http_request();
let resp = index(req).await;
2019-06-24 17:43:31 -04:00
assert_eq!(resp.status(), http::StatusCode::BAD_REQUEST);
}
2019-06-17 15:39:58 -04:00
}
// </unit-tests>