2019-06-24 23:43:31 +02:00
|
|
|
pub mod integration_one;
|
|
|
|
pub mod integration_two;
|
|
|
|
pub mod stream_response;
|
|
|
|
use actix_web::{http, web, App, HttpRequest, HttpResponse};
|
2019-06-17 21:39:58 +02:00
|
|
|
|
2020-01-21 22:40:37 +01:00
|
|
|
async fn index(req: HttpRequest) -> HttpResponse {
|
2019-06-17 21:39:58 +02: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 23:43:31 +02:00
|
|
|
App::new().route("/", web::get().to(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
// <unit-tests>
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2022-02-26 04:56:24 +01:00
|
|
|
use actix_web::{
|
|
|
|
http::{self, header::ContentType},
|
|
|
|
test,
|
|
|
|
};
|
2019-06-17 21:39:58 +02:00
|
|
|
|
2022-02-26 04:56:24 +01:00
|
|
|
#[actix_web::test]
|
2020-01-21 22:40:37 +01:00
|
|
|
async fn test_index_ok() {
|
2022-02-26 04:56:24 +01:00
|
|
|
let req = test::TestRequest::default()
|
|
|
|
.insert_header(ContentType::plaintext())
|
|
|
|
.to_http_request();
|
2020-01-21 22:40:37 +01:00
|
|
|
let resp = index(req).await;
|
2019-06-24 23:43:31 +02:00
|
|
|
assert_eq!(resp.status(), http::StatusCode::OK);
|
|
|
|
}
|
|
|
|
|
2022-02-26 04:56:24 +01:00
|
|
|
#[actix_web::test]
|
2020-01-21 22:40:37 +01:00
|
|
|
async fn test_index_not_ok() {
|
2019-06-24 23:43:31 +02:00
|
|
|
let req = test::TestRequest::default().to_http_request();
|
2020-01-21 22:40:37 +01:00
|
|
|
let resp = index(req).await;
|
2019-06-24 23:43:31 +02:00
|
|
|
assert_eq!(resp.status(), http::StatusCode::BAD_REQUEST);
|
|
|
|
}
|
2019-06-17 21:39:58 +02:00
|
|
|
}
|
|
|
|
// </unit-tests>
|