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

34 lines
903 B
Rust
Raw Normal View History

2019-06-24 17:43:31 -04:00
use actix_web::{HttpRequest, Responder};
#[allow(dead_code)]
fn index(_req: HttpRequest) -> impl Responder {
"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::dev::Service;
use actix_web::{test, web, App};
2019-06-17 15:39:58 -04:00
2019-06-24 17:43:31 -04:00
#[test]
fn test_index_get() {
let mut app = test::init_service(App::new().route("/", web::get().to(index)));
let req = test::TestRequest::get().uri("/").to_request();
let resp = test::block_on(app.call(req)).unwrap();
2019-06-17 15:39:58 -04:00
2019-06-24 17:43:31 -04:00
assert!(resp.status().is_success());
}
2019-06-17 15:39:58 -04:00
2019-06-24 17:43:31 -04:00
#[test]
fn test_index_post() {
let mut app = test::init_service(App::new().route("/", web::get().to(index)));
let req = test::TestRequest::post().uri("/").to_request();
let resp = test::block_on(app.call(req)).unwrap();
2019-06-17 15:39:58 -04:00
2019-06-24 17:43:31 -04:00
assert!(resp.status().is_client_error());
}
}
2019-06-17 15:39:58 -04:00
// </integration-one>