aboutsummaryrefslogtreecommitdiffstats
path: root/testing/tests/actix_web.rs
diff options
context:
space:
mode:
authorLibravatar DCjanus <DCjanus@dcjanus.com>2020-01-11 23:39:17 +0800
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-01-11 17:43:55 +0100
commit6b11df9e92c7414968d71c65249d273183ecd716 (patch)
tree7ebe693dd95d87ed7c1bc0a4976a7bb40e8dab9b /testing/tests/actix_web.rs
parentcef055108de6c51c1423cd6a8919730ef01f64a3 (diff)
downloadaskama-6b11df9e92c7414968d71c65249d273183ecd716.tar.gz
askama-6b11df9e92c7414968d71c65249d273183ecd716.tar.bz2
askama-6b11df9e92c7414968d71c65249d273183ecd716.zip
upgrade dependencies(actix-web 0.7 -> 2)
Diffstat (limited to '')
-rw-r--r--testing/tests/actix_web.rs39
1 files changed, 22 insertions, 17 deletions
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()));
}