diff options
| author | batsumaru <> | 2026-10-16 14:35:41 +0900 |
|---|---|---|
| committer | batsumaru <> | 2026-10-16 14:35:41 +0900 |
| commit | baaf466ff41c52a4e39624442ec2b122727feb89 (patch) | |
| tree | 2ad18275278230bba58d660375e140670caa312e /src/main.rs | |
| parent | 784e52da5f3bef26655c77b210b3b105847e3d9a (diff) | |
Add tests
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index 04f4c99..01a315a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,19 +2,18 @@ mod db; mod error; mod handlers; mod models; +#[cfg(test)] +mod tests; use axum::{ Router, routing::{delete, get, post, put}, }; use dotenvy::dotenv; +use sqlx::PgPool; -#[tokio::main] -async fn main() -> anyhow::Result<()> { - tracing_subscriber::fmt::init(); - dotenv().ok(); - let pool = db::connect().await?; - let app = Router::new() +fn router(pool: PgPool) -> Router { + Router::new() .route("/", get(handlers::index)) .route("/all", get(handlers::all)) .route("/add", post(handlers::add)) @@ -24,7 +23,15 @@ async fn main() -> anyhow::Result<()> { .route("/measurement/{id}", get(handlers::measurement_by_id)) .route("/delete/{id}", delete(handlers::delete)) .route("/update/{id}", put(handlers::update)) - .with_state(pool); + .with_state(pool) +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + tracing_subscriber::fmt::init(); + dotenv().ok(); + let pool = db::connect().await?; + let app = router(pool); let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?; tracing::info!("listening at 0.0.0.0:3000"); axum::serve(listener, app).await?; |
