From 1c7ea7154e0305d8a4cdbb5f00b052fa6777ba3c Mon Sep 17 00:00:00 2001 From: Rafael Bachmann Date: Sun, 30 Jan 2022 17:17:18 +0100 Subject: [PATCH] Update basics/hello-world to v4. (#477) --- Cargo.lock | 6 +++--- basics/hello-world/Cargo.toml | 9 +++------ basics/hello-world/src/main.rs | 13 +++++-------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7d37fc0..95039c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2873,9 +2873,9 @@ dependencies = [ name = "hello-world" version = "2.0.0" dependencies = [ - "actix-rt 1.1.1", - "actix-web 3.3.3", - "env_logger 0.8.4", + "actix-rt 2.6.0", + "actix-web 4.0.0-beta.21", + "env_logger 0.9.0", ] [[package]] diff --git a/basics/hello-world/Cargo.toml b/basics/hello-world/Cargo.toml index 8d6f72b..6c14d48 100644 --- a/basics/hello-world/Cargo.toml +++ b/basics/hello-world/Cargo.toml @@ -2,11 +2,8 @@ name = "hello-world" version = "2.0.0" authors = ["Nikolay Kim "] -edition = "2018" +edition = "2021" [dependencies] -actix-web = "3" -env_logger = "0.8" - -[dev-dependencies] -actix-rt = "1" +actix-web = "4.0.0-beta.21" +env_logger = "0.9.0" diff --git a/basics/hello-world/src/main.rs b/basics/hello-world/src/main.rs index ab04c90..45df7f3 100644 --- a/basics/hello-world/src/main.rs +++ b/basics/hello-world/src/main.rs @@ -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(()) }