-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.rs
31 lines (25 loc) · 843 Bytes
/
lib.rs
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
use actix_web::{get, HttpResponse, Responder};
#[get("/")]
pub async fn handler() -> impl Responder {
HttpResponse::Ok().body("Hello Actix World!")
}
#[cfg(test)]
mod tests {
use super::*;
use actix_http::Request;
use actix_web::{http::StatusCode, test, App};
use bytes::Bytes;
fn create_req() -> Request {
test::TestRequest::with_uri("/").to_request()
}
#[actix_rt::test]
async fn test_handler() {
let mut app = test::init_service(App::new().service(handler)).await;
let req = create_req();
let resp = test::call_service(&mut app, req).await;
assert_eq!(resp.status(), StatusCode::OK);
let req = create_req();
let result = test::read_response(&mut app, req).await;
assert_eq!(result, Bytes::from_static(b"Hello Actix World!"));
}
}