Skip to content

Commit

Permalink
add test server data test
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Dec 20, 2019
1 parent 4847636 commit 0cb1b06
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<usize>) -> 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;
Expand Down

0 comments on commit 0cb1b06

Please sign in to comment.