-
Notifications
You must be signed in to change notification settings - Fork 2
/
integration.rs
62 lines (54 loc) · 1.85 KB
/
integration.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
50
51
52
53
54
55
56
57
58
59
60
61
62
use {
rust_web_boilerplate::{config::Config, make_server},
tide::http::{Body, Request, Response, Url},
};
#[async_std::test]
async fn test_not_found() {
let server = make_server(Config {
host: "0.0.0.0".to_string(),
port: 5000,
});
let mut req = Request::get(Url::parse("http://localhost:5000/foobar").unwrap());
req.set_body(Body::empty());
let resp: Response = server.respond(req).await.unwrap();
assert_eq!(resp.status(), 404);
}
#[async_std::test]
async fn test_ping() {
let server = make_server(Config {
host: "0.0.0.0".to_string(),
port: 5000,
});
let mut req = Request::get(Url::parse("http://localhost:5000/ping").unwrap());
req.set_body(Body::empty());
let mut resp: Response = server.respond(req).await.unwrap();
assert_eq!(resp.status(), 200);
let body = resp.body_string().await.unwrap();
assert_eq!(&body, "OK");
}
#[async_std::test]
async fn test_hello() {
let server = make_server(Config {
host: "0.0.0.0".to_string(),
port: 5000,
});
let mut req = Request::get(Url::parse("http://localhost:5000/hello/foobar").unwrap());
req.set_body(Body::empty());
let mut resp: Response = server.respond(req).await.unwrap();
assert_eq!(resp.status(), 200);
let body = resp.body_string().await.unwrap();
assert_eq!(&body, "Hello, foobar!");
}
#[async_std::test]
async fn test_hello_with_body() {
let server = make_server(Config {
host: "0.0.0.0".to_string(),
port: 5000,
});
let mut req = Request::post(Url::parse("http://localhost:5000/hello/foobar").unwrap());
req.set_body("baz");
let mut resp: Response = server.respond(req).await.unwrap();
assert_eq!(resp.status(), 200);
let body = resp.body_string().await.unwrap();
assert_eq!(&body, "Hello, foobar!\nYour message was \"baz\".");
}