diff --git a/Cargo.lock b/Cargo.lock index 95d5ee71..7d37fc00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3215,10 +3215,8 @@ checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd" name = "json-example" version = "0.1.0" dependencies = [ - "actix-rt 1.1.1", - "actix-service 1.0.6", - "actix-web 3.3.3", - "env_logger 0.8.4", + "actix-web 4.0.0-beta.21", + "env_logger 0.9.0", "futures", "json", "serde 1.0.136", diff --git a/json/json/Cargo.toml b/json/json/Cargo.toml index 9f7c358b..90b216d3 100644 --- a/json/json/Cargo.toml +++ b/json/json/Cargo.toml @@ -5,13 +5,9 @@ authors = ["Nikolay Kim "] edition = "2018" [dependencies] -actix-web = "3" -actix-service = "1.0.0" +actix-web = "4.0.0-beta.21" futures = "0.3" -env_logger = "0.8" +env_logger = "0.9.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -json = "0.12" - -[dev-dependencies] -actix-rt = "1" +json = "0.12" \ No newline at end of file diff --git a/json/json/src/main.rs b/json/json/src/main.rs index df988329..e2976483 100644 --- a/json/json/src/main.rs +++ b/json/json/src/main.rs @@ -67,11 +67,11 @@ async fn main() -> std::io::Result<()> { App::new() // enable logger .wrap(middleware::Logger::default()) - .data(web::JsonConfig::default().limit(4096)) // <- limit size of the payload (global configuration) + .app_data(web::JsonConfig::default().limit(4096)) // <- limit size of the payload (global configuration) .service(web::resource("/extractor").route(web::post().to(index))) .service( web::resource("/extractor2") - .data(web::JsonConfig::default().limit(1024)) // <- limit size of the payload (resource level) + .app_data(web::JsonConfig::default().limit(1024)) // <- limit size of the payload (resource level) .route(web::post().to(extract_item)), ) .service(web::resource("/manual").route(web::post().to(index_manual))) @@ -86,12 +86,13 @@ 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}; - #[actix_rt::test] - async fn test_index() -> Result<(), Error> { - let mut app = test::init_service( + #[actix_web::test] + async fn test_index() { + let app = test::init_service( App::new().service(web::resource("/").route(web::post().to(index))), ) .await; @@ -107,13 +108,7 @@ mod tests { 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##"{"name":"my-name","number":43}"##); - - Ok(()) + let body_bytes = to_bytes(resp.into_body()).await.unwrap(); + assert_eq!(body_bytes, r##"{"name":"my-name","number":43}"##); } }