aboutsummaryrefslogtreecommitdiffstats
path: root/testing/tests/actix_web.rs
diff options
context:
space:
mode:
Diffstat (limited to 'testing/tests/actix_web.rs')
-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()));
}