2019-06-24 17:43:31 -04:00
|
|
|
use actix_web::{HttpRequest, Responder};
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
2020-01-22 00:40:37 +03:00
|
|
|
async fn index(_req: HttpRequest) -> impl Responder {
|
2019-06-24 17:43:31 -04:00
|
|
|
"Hello world!"
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:39:58 -04:00
|
|
|
// <integration-one>
|
2019-06-24 17:43:31 -04:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2022-02-26 03:56:24 +00:00
|
|
|
use actix_web::{http::header::ContentType, test, web, App};
|
|
|
|
|
2019-06-24 17:43:31 -04:00
|
|
|
use super::*;
|
2019-06-17 15:39:58 -04:00
|
|
|
|
2022-02-26 03:56:24 +00:00
|
|
|
#[actix_web::test]
|
2020-01-22 00:40:37 +03:00
|
|
|
async fn test_index_get() {
|
2022-02-26 03:56:24 +00:00
|
|
|
let app = test::init_service(App::new().route("/", web::get().to(index))).await;
|
|
|
|
let req = test::TestRequest::default()
|
|
|
|
.insert_header(ContentType::plaintext())
|
|
|
|
.to_request();
|
|
|
|
let resp = test::call_service(&app, req).await;
|
2019-06-24 17:43:31 -04:00
|
|
|
assert!(resp.status().is_success());
|
|
|
|
}
|
2019-06-17 15:39:58 -04:00
|
|
|
|
2022-02-26 03:56:24 +00:00
|
|
|
#[actix_web::test]
|
2020-01-22 00:40:37 +03:00
|
|
|
async fn test_index_post() {
|
2022-02-26 03:56:24 +00:00
|
|
|
let app = test::init_service(App::new().route("/", web::get().to(index))).await;
|
2019-06-24 17:43:31 -04:00
|
|
|
let req = test::TestRequest::post().uri("/").to_request();
|
2022-02-26 03:56:24 +00:00
|
|
|
let resp = test::call_service(&app, req).await;
|
2019-06-24 17:43:31 -04:00
|
|
|
assert!(resp.status().is_client_error());
|
|
|
|
}
|
|
|
|
}
|
2019-06-17 15:39:58 -04:00
|
|
|
// </integration-one>
|