From 0cb1b0642f17ca2906a02bcaa9405ce8368fec89 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 20 Dec 2019 23:18:59 +0600 Subject: [PATCH] add test server data test --- src/test.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/test.rs b/src/test.rs index a10490fd5..5f5fdc487 100644 --- a/src/test.rs +++ b/src/test.rs @@ -962,7 +962,7 @@ mod tests { use std::time::SystemTime; use super::*; - use crate::{http::header, web, App, HttpResponse}; + use crate::{http::header, web, App, HttpResponse, Responder}; #[actix_rt::test] async fn test_basics() { @@ -1148,6 +1148,25 @@ mod tests { assert!(res.status().is_success()); } + #[actix_rt::test] + async fn test_server_data() { + async fn handler(data: web::Data) -> impl Responder { + assert_eq!(**data, 10); + HttpResponse::Ok() + } + + let mut app = init_service( + App::new() + .data(10usize) + .service(web::resource("/index.html").to(handler)), + ) + .await; + + let req = TestRequest::post().uri("/index.html").to_request(); + let res = app.call(req).await.unwrap(); + assert!(res.status().is_success()); + } + #[actix_rt::test] async fn test_actor() { use actix::Actor;