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

34 lines
995 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 {
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]
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]
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>