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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
pub use actix_http::test::TestBuffer;
mod test_request;
mod test_services;
mod test_utils;
pub use self::test_request::TestRequest;
#[allow(deprecated)]
pub use self::test_services::{default_service, ok_service, simple_service};
#[allow(deprecated)]
pub use self::test_utils::{
call_and_read_body, call_and_read_body_json, call_service, init_service, read_body,
read_body_json, read_response, read_response_json,
};
#[cfg(test)]
pub(crate) use self::test_utils::try_init_service;
#[cfg(test)]
macro_rules! assert_body_eq {
($res:ident, $expected:expr) => {
assert_eq!(
::actix_http::body::to_bytes($res.into_body())
.await
.expect("error reading test response body"),
::bytes::Bytes::from_static($expected),
)
};
}
#[cfg(test)]
pub(crate) use assert_body_eq;
#[cfg(test)]
mod tests {
use super::*;
use crate::{http::StatusCode, service::ServiceResponse, HttpResponse};
#[actix_rt::test]
async fn assert_body_works_for_service_and_regular_response() {
let res = HttpResponse::with_body(StatusCode::OK, "http response");
assert_body_eq!(res, b"http response");
let req = TestRequest::default().to_http_request();
let res = HttpResponse::with_body(StatusCode::OK, "service response");
let res = ServiceResponse::new(req, res);
assert_body_eq!(res, b"service response");
}
}