1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +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"
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]]

View File

@ -2,11 +2,8 @@
name = "hello-world"
version = "2.0.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
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"

View File

@ -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(())
}