From ed98793b506c66723c713991f40c0065557a35d5 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Sat, 21 Jul 2018 19:10:48 +0000 Subject: Tests for actix_web --- testing/tests/actix_web.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 testing/tests/actix_web.rs (limited to 'testing/tests/actix_web.rs') diff --git a/testing/tests/actix_web.rs b/testing/tests/actix_web.rs new file mode 100644 index 0000000..12724d9 --- /dev/null +++ b/testing/tests/actix_web.rs @@ -0,0 +1,29 @@ +#[macro_use] +extern crate askama; +extern crate actix_web; +extern crate bytes; + +use actix_web::http::header::CONTENT_TYPE; +use actix_web::test; +use actix_web::HttpMessage; +use askama::Template; +use bytes::Bytes; + +#[derive(Template)] +#[template(path = "hello.html")] +struct HelloTemplate<'a> { + name: &'a str, +} + +#[test] +fn test_actix_web() { + let mut srv = test::TestServer::new(|app| app.handler(|_| HelloTemplate { name: "world" })); + + let request = srv.get().finish().unwrap(); + let response = srv.execute(request.send()).unwrap(); + assert!(response.status().is_success()); + assert_eq!(response.headers().get(CONTENT_TYPE).unwrap(), "text/html"); + + let bytes = srv.execute(response.body()).unwrap(); + assert_eq!(bytes, Bytes::from_static("Hello, world!".as_ref())); +} -- cgit