-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_world.rs
49 lines (40 loc) · 1.09 KB
/
hello_world.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use super::*;
use actix_web::{App, HttpRequest, Responder};
pub fn get_service_root() -> String {
format!("/hello/{}", VER)
}
pub fn get_service_path() -> String {
get_service_root() + "/"
}
pub fn index(_req: &HttpRequest) -> impl Responder {
"Hello World!".to_string()
}
pub fn service() -> App {
let app = App::new()
.middleware(Logger::default())
.middleware(Logger::new("%a %{User-Agent}i"))
.resource(
&get_service_path(),
|r| r.get().f(index));
app
}
#[cfg(test)]
mod tests {
use super::*;
use actix_web::{http, test};
#[test]
fn test_get_service_root() {
assert_eq!(get_service_root(), format!("/hello/{}", VER));
}
#[test]
fn test_get_service_path() {
assert_eq!(get_service_path(), format!("/hello/{}/", VER));
}
#[test]
fn hello_response() {
let resp = test::TestRequest::with_header("content-type", "text/plain")
.run(&index)
.unwrap();
assert_eq!(resp.status(), http::StatusCode::OK);
}
}