From 6b11df9e92c7414968d71c65249d273183ecd716 Mon Sep 17 00:00:00 2001 From: DCjanus Date: Sat, 11 Jan 2020 23:39:17 +0800 Subject: upgrade dependencies(actix-web 0.7 -> 2) --- testing/Cargo.toml | 8 +++++--- testing/tests/actix_web.rs | 39 ++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 20 deletions(-) (limited to 'testing') diff --git a/testing/Cargo.toml b/testing/Cargo.toml index 73e0a8a..4aa80fe 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -6,7 +6,7 @@ workspace = ".." edition = "2018" [features] -actix = ["actix-web", "bytes", "askama/with-actix-web"] +actix = ["actix-web", "actix-rt", "bytes", "askama/with-actix-web", "futures"] default = [] full = ["actix", "with-iron", "serde-json", "with-gotham"] serde-json = ["serde_json", "askama/serde-json"] @@ -15,9 +15,11 @@ with-iron = ["iron", "askama/with-iron"] with-gotham = ["gotham", "askama/with-gotham", "mime", "hyper"] [dependencies] -actix-web = { version = "0.7", optional = true } +actix-web = { version = "2", optional = true } +actix-rt = { version = "1", optional = true } +futures = { version = "0.3", optional = true } askama = { path = "../askama", version = "*" } -bytes = { version = "0.4", optional = true } +bytes = { version = "0.5", optional = true } iron = { version = "0.6", optional = true } rocket = { version = "0.4", optional = true } serde_json = { version = "1.0", optional = true } diff --git a/testing/tests/actix_web.rs b/testing/tests/actix_web.rs index e434ce3..8beef3d 100644 --- a/testing/tests/actix_web.rs +++ b/testing/tests/actix_web.rs @@ -1,7 +1,7 @@ #![cfg(feature = "actix")] use actix_web::http::header::CONTENT_TYPE; use actix_web::test; -use actix_web::HttpMessage; +use actix_web::web; use askama::{actix_web::TemplateIntoResponse, Template}; use bytes::Bytes; @@ -11,39 +11,44 @@ struct HelloTemplate<'a> { name: &'a str, } -#[test] -fn test_actix_web() { - let mut srv = test::TestServer::new(|app| app.handler(|_| HelloTemplate { name: "world" })); +#[actix_rt::test] +async fn test_actix_web() { + let srv = test::start(|| { + actix_web::App::new() + .service(web::resource("/").to(|| async { HelloTemplate { name: "world" } })) + }); - let request = srv.get().finish().unwrap(); - let response = srv.execute(request.send()).unwrap(); + let request = srv.get("/"); + let mut response = request.send().await.unwrap(); assert!(response.status().is_success()); assert_eq!( response.headers().get(CONTENT_TYPE).unwrap(), "text/html; charset=utf-8" ); - let bytes = srv.execute(response.body()).unwrap(); + let bytes = response.body().await.unwrap(); assert_eq!(bytes, Bytes::from_static("Hello, world!".as_ref())); } -#[test] -fn test_actix_web_responder() { - let mut srv = test::TestServer::new(|app| { - app.handler(|_| { - let name = "world".to_owned(); - HelloTemplate { name: &name }.into_response() - }) +#[actix_rt::test] +async fn test_actix_web_responder() { + let srv = test::start(|| { + actix_web::App::new().service(web::resource("/").to(|| { + async { + let name = "world".to_owned(); + HelloTemplate { name: &name }.into_response() + } + })) }); - let request = srv.get().finish().unwrap(); - let response = srv.execute(request.send()).unwrap(); + let request = srv.get("/"); + let mut response = request.send().await.unwrap(); assert!(response.status().is_success()); assert_eq!( response.headers().get(CONTENT_TYPE).unwrap(), "text/html; charset=utf-8" ); - let bytes = srv.execute(response.body()).unwrap(); + let bytes = response.body().await.unwrap(); assert_eq!(bytes, Bytes::from_static("Hello, world!".as_ref())); } -- cgit