aboutsummaryrefslogtreecommitdiffstats
path: root/testing/tests/actix_web.rs
blob: 12724d99aaa0c7da0cb990e59552c75013cc65c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()));
}