diff --git a/diesel/src/main.rs b/diesel/src/main.rs index 37603ee7..b2c23523 100644 --- a/diesel/src/main.rs +++ b/diesel/src/main.rs @@ -60,8 +60,7 @@ async fn add( /// This handler manually parse json object. Bytes object supports FromRequest trait (extractor) /// and could be loaded from request payload automatically -async fn index_add(body: Bytes, pool: web::Data) -> Result { - let mut body = BytesMut::new(); +async fn index_add(body: web::Bytes, pool: web::Data) -> Result { // body is loaded, now we can deserialize id with serde-json let r_obj = serde_json::from_slice::(&body); diff --git a/json/Cargo.toml b/json/Cargo.toml index c0ba58db..d0399551 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -6,8 +6,9 @@ workspace = ".." edition = "2018" [dependencies] -actix-web = "2.0.0-alpha.3" +actix-web = "2.0.0-alpha.4" actix-rt = "1.0.0-alpha.3" +actix-service = "1.0.0-alpha.4" bytes = "0.5.2" futures = "0.3.1" diff --git a/json/src/main.rs b/json/src/main.rs index 791f574a..19005e44 100644 --- a/json/src/main.rs +++ b/json/src/main.rs @@ -90,10 +90,12 @@ mod tests { use actix_web::dev::Service; use actix_web::{http, test, web, App}; - #[test] - fn test_index() -> Result<(), Error> { - let app = App::new().route("/", web::post().to(index)); - let mut app = test::init_service(app); + #[actix_rt::test] + async fn test_index() -> Result<(), Error> { + let mut app = test::init_service( + App::new().service(web::resource("/").route(web::post().to(index))), + ) + .await; let req = test::TestRequest::post() .uri("/") @@ -102,7 +104,7 @@ mod tests { number: 43, }) .to_request(); - let resp = test::block_on(app.call(req)).unwrap(); + let resp = app.call(req).await.unwrap(); assert_eq!(resp.status(), http::StatusCode::OK);