1
0
mirror of https://github.com/actix/actix-website synced 2025-02-13 08:32:20 +01:00
actix-website/examples/testing/src/integration_one.rs

31 lines
947 B
Rust
Raw Normal View History

2019-06-24 17:43:31 -04:00
use actix_web::{HttpRequest, Responder};
#[allow(dead_code)]
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 {
use super::*;
use actix_web::{test, web, App};
2019-06-17 15:39:58 -04:00
#[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;
2019-06-24 17:43:31 -04:00
assert!(resp.status().is_success());
}
2019-06-17 15:39:58 -04:00
#[actix_rt::test]
async fn test_index_post() {
let mut 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();
let resp = test::call_service(&mut 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>