1
0
mirror of https://github.com/actix/actix-website synced 2025-02-08 22:36:07 +01:00
actix-website/examples/testing/src/integration_one.rs
Evgeniy Tatarkin bc4e0422c8 update testing to actix-web 2.0.0 and improve stream testing code (#141)
* update testing to actix-web 2.0.0 and improve stream testing code
2020-01-22 06:40:37 +09:00

31 lines
947 B
Rust

use actix_web::{HttpRequest, Responder};
#[allow(dead_code)]
async fn index(_req: HttpRequest) -> impl Responder {
"Hello world!"
}
// <integration-one>
#[cfg(test)]
mod tests {
use super::*;
use actix_web::{test, web, App};
#[actix_rt::test]
async fn test_index_get() {
let mut app = test::init_service(App::new().route("/", web::get().to(index))).await;
let req = test::TestRequest::with_header("content-type", "text/plain").to_request();
let resp = test::call_service(&mut app, req).await;
assert!(resp.status().is_success());
}
#[actix_rt::test]
async fn test_index_post() {
let mut app = test::init_service(App::new().route("/", web::get().to(index))).await;
let req = test::TestRequest::post().uri("/").to_request();
let resp = test::call_service(&mut app, req).await;
assert!(resp.status().is_client_error());
}
}
// </integration-one>