This commit is contained in:
philipp 2023-03-26 16:58:45 +02:00
parent bb8fb03b61
commit 546381511e
3 changed files with 1270 additions and 14 deletions

1253
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,5 +7,8 @@ edition = "2021"
[dependencies] [dependencies]
rocket = { version = "0.5.0-rc.3"} rocket = { version = "0.5.0-rc.3"}
rocket_dyn_templates = {version = "0.1.0-rc.3", features = [ "tera" ] }
log = "0.4" log = "0.4"
env_logger = "0.10" env_logger = "0.10"
sqlx = { version = "0.6", features = ["sqlite", "runtime-tokio-rustls"] }

View File

@ -1,4 +1,5 @@
use rocket::{get, routes, Build, Rocket}; use rocket::{get, routes, Build, Rocket};
use rocket_dyn_templates::Template;
#[get("/")] #[get("/")]
fn index() -> &'static str { fn index() -> &'static str {
@ -6,22 +7,37 @@ fn index() -> &'static str {
} }
pub fn start() -> Rocket<Build> { pub fn start() -> Rocket<Build> {
rocket::build().mount("/", routes![index]) rocket::build()
.mount("/", routes![index])
.attach(Template::fairing())
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::start; use super::start;
use rocket::http::Status; use rocket::http::Status;
use rocket::local::blocking::Client; use rocket::local::asynchronous::Client;
use rocket::uri; use rocket::uri;
use sqlx::SqlitePool;
#[test] #[sqlx::test]
fn hello_world() { fn hello_world() {
let client = Client::tracked(start()).expect("valid rocket instance"); let pool = SqlitePool::connect(":memory:").await.unwrap();
let response = client.get(uri!(super::index)).dispatch(); 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.status(), Status::Ok);
assert_eq!(response.into_string(), Some("Hello, world!".into())); assert_eq!(response.into_string().await, Some("Hello, world!".into()));
} }
} }