Skip to content

Commit

Permalink
tests: Add unit test code for function 'hello()'
Browse files Browse the repository at this point in the history
  • Loading branch information
utilForever committed Jul 13, 2024
1 parent 2031fd9 commit c15d441
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@
extern crate rocket;

#[get("/")]
fn index() -> &'static str {
fn hello() -> &'static str {
"Hello, world!"
}

#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index])
rocket::build().mount("/", routes![hello])
}

#[cfg(test)]
mod test {
use super::rocket;
use rocket::local::blocking::Client;
use rocket::http::Status;

#[test]
fn test_hello() {
let client = Client::tracked(rocket()).expect("valid rocket instance");
let response = client.get(uri!(super::hello)).dispatch();

assert_eq!(response.status(), Status::Ok);
assert_eq!(response.into_string().unwrap(), "Hello, world!");
}
}

0 comments on commit c15d441

Please sign in to comment.