Skip to content

Commit c15d441

Browse files
committed
tests: Add unit test code for function 'hello()'
1 parent 2031fd9 commit c15d441

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/main.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@
22
extern crate rocket;
33

44
#[get("/")]
5-
fn index() -> &'static str {
5+
fn hello() -> &'static str {
66
"Hello, world!"
77
}
88

99
#[launch]
1010
fn rocket() -> _ {
11-
rocket::build().mount("/", routes![index])
11+
rocket::build().mount("/", routes![hello])
12+
}
13+
14+
#[cfg(test)]
15+
mod test {
16+
use super::rocket;
17+
use rocket::local::blocking::Client;
18+
use rocket::http::Status;
19+
20+
#[test]
21+
fn test_hello() {
22+
let client = Client::tracked(rocket()).expect("valid rocket instance");
23+
let response = client.get(uri!(super::hello)).dispatch();
24+
25+
assert_eq!(response.status(), Status::Ok);
26+
assert_eq!(response.into_string().unwrap(), "Hello, world!");
27+
}
1228
}

0 commit comments

Comments
 (0)