1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02: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
3 changed files with 11 additions and 17 deletions

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