mirror of
https://github.com/actix/actix-website
synced 2025-02-13 00:25:35 +01:00
34 lines
995 B
Rust
34 lines
995 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 actix_web::{http::header::ContentType, test, web, App};
|
|
|
|
use super::*;
|
|
|
|
#[actix_web::test]
|
|
async fn test_index_get() {
|
|
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;
|
|
assert!(resp.status().is_success());
|
|
}
|
|
|
|
#[actix_web::test]
|
|
async fn test_index_post() {
|
|
let 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(&app, req).await;
|
|
assert!(resp.status().is_client_error());
|
|
}
|
|
}
|
|
// </integration-one>
|