2023-03-26 16:58:45 +02:00

44 lines
1.1 KiB
Rust

use rocket::{get, routes, Build, Rocket};
use rocket_dyn_templates::Template;
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
}
pub fn start() -> Rocket<Build> {
rocket::build()
.mount("/", routes![index])
.attach(Template::fairing())
}
#[cfg(test)]
mod test {
use super::start;
use rocket::http::Status;
use rocket::local::asynchronous::Client;
use rocket::uri;
use sqlx::SqlitePool;
#[sqlx::test]
fn hello_world() {
let pool = SqlitePool::connect(":memory:").await.unwrap();
sqlx::query_file!("./migration.sql")
.execute(&pool)
.await
.unwrap();
sqlx::query_file!("./seeds.sql")
.execute(&pool)
.await
.unwrap();
let client = Client::tracked(start())
.await
.expect("valid rocket instance");
let response = client.get(uri!(super::index)).dispatch().await;
assert_eq!(response.status(), Status::Ok);
assert_eq!(response.into_string().await, Some("Hello, world!".into()));
}
}