rowt/src/rest/mod.rs

44 lines
1.1 KiB
Rust
Raw Normal View History

2023-03-26 14:40:56 +02:00
use rocket::{get, routes, Build, Rocket};
2023-03-26 16:58:45 +02:00
use rocket_dyn_templates::Template;
2023-03-26 14:40:56 +02:00
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
}
pub fn start() -> Rocket<Build> {
2023-03-26 16:58:45 +02:00
rocket::build()
.mount("/", routes![index])
.attach(Template::fairing())
2023-03-26 14:40:56 +02:00
}
#[cfg(test)]
mod test {
use super::start;
use rocket::http::Status;
2023-03-26 16:58:45 +02:00
use rocket::local::asynchronous::Client;
2023-03-26 14:40:56 +02:00
use rocket::uri;
2023-03-26 16:58:45 +02:00
use sqlx::SqlitePool;
2023-03-26 14:40:56 +02:00
2023-03-26 16:58:45 +02:00
#[sqlx::test]
2023-03-26 14:40:56 +02:00
fn hello_world() {
2023-03-26 16:58:45 +02:00
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;
2023-03-26 14:40:56 +02:00
assert_eq!(response.status(), Status::Ok);
2023-03-26 16:58:45 +02:00
assert_eq!(response.into_string().await, Some("Hello, world!".into()));
2023-03-26 14:40:56 +02:00
}
}