mirror of
https://github.com/actix/examples
synced 2025-06-27 01:27:43 +02:00
Update basics/hello-world to v4. (#477)
This commit is contained in:
@ -25,25 +25,22 @@ async fn main() -> std::io::Result<()> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use actix_web::body::to_bytes;
|
||||
use actix_web::dev::Service;
|
||||
use actix_web::{http, test, web, App, Error};
|
||||
|
||||
#[actix_rt::test]
|
||||
#[actix_web::test]
|
||||
async fn test_index() -> Result<(), Error> {
|
||||
let app = App::new().route("/", web::get().to(index));
|
||||
let mut app = test::init_service(app).await;
|
||||
let app = test::init_service(app).await;
|
||||
|
||||
let req = test::TestRequest::get().uri("/").to_request();
|
||||
let resp = app.call(req).await.unwrap();
|
||||
|
||||
assert_eq!(resp.status(), http::StatusCode::OK);
|
||||
|
||||
let response_body = match resp.response().body().as_ref() {
|
||||
Some(actix_web::body::Body::Bytes(bytes)) => bytes,
|
||||
_ => panic!("Response error"),
|
||||
};
|
||||
|
||||
assert_eq!(response_body, r##"Hello world!"##);
|
||||
let response_body = resp.into_body();
|
||||
assert_eq!(to_bytes(response_body).await.unwrap(), r##"Hello world!"##);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user