1
0
mirror of https://github.com/actix/examples synced 2025-02-17 15:23:31 +01:00

Update basics/hello-world to v4. (#477)

This commit is contained in:
Rafael Bachmann 2022-01-30 17:17:18 +01:00 committed by GitHub
parent a3726b0874
commit 1c7ea7154e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 17 deletions

6
Cargo.lock generated
View File

@ -2873,9 +2873,9 @@ dependencies = [
name = "hello-world" name = "hello-world"
version = "2.0.0" version = "2.0.0"
dependencies = [ dependencies = [
"actix-rt 1.1.1", "actix-rt 2.6.0",
"actix-web 3.3.3", "actix-web 4.0.0-beta.21",
"env_logger 0.8.4", "env_logger 0.9.0",
] ]
[[package]] [[package]]

View File

@ -2,11 +2,8 @@
name = "hello-world" name = "hello-world"
version = "2.0.0" version = "2.0.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"] authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
edition = "2018" edition = "2021"
[dependencies] [dependencies]
actix-web = "3" actix-web = "4.0.0-beta.21"
env_logger = "0.8" env_logger = "0.9.0"
[dev-dependencies]
actix-rt = "1"

View File

@ -25,25 +25,22 @@ async fn main() -> std::io::Result<()> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use actix_web::body::to_bytes;
use actix_web::dev::Service; use actix_web::dev::Service;
use actix_web::{http, test, web, App, Error}; use actix_web::{http, test, web, App, Error};
#[actix_rt::test] #[actix_web::test]
async fn test_index() -> Result<(), Error> { async fn test_index() -> Result<(), Error> {
let app = App::new().route("/", web::get().to(index)); 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 req = test::TestRequest::get().uri("/").to_request();
let resp = app.call(req).await.unwrap(); let resp = app.call(req).await.unwrap();
assert_eq!(resp.status(), http::StatusCode::OK); assert_eq!(resp.status(), http::StatusCode::OK);
let response_body = match resp.response().body().as_ref() { let response_body = resp.into_body();
Some(actix_web::body::Body::Bytes(bytes)) => bytes, assert_eq!(to_bytes(response_body).await.unwrap(), r##"Hello world!"##);
_ => panic!("Response error"),
};
assert_eq!(response_body, r##"Hello world!"##);
Ok(()) Ok(())
} }