diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..f51483b --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,31 @@ +use axum::{Router, routing::get}; + +pub fn app() -> Router { + Router::new() + .route("/health", get(crate::health::health_handler)) +} + +pub mod users; +pub mod locations; +pub mod weather_thresholds; +pub mod notifications; +pub mod weather_poller; +pub mod health; + +#[cfg(test)] +mod tests { + use super::*; + use axum::body::Body; + use axum::http::{Request, StatusCode}; + use tower::ServiceExt; // for `oneshot` + use axum::body::to_bytes; + + #[tokio::test] + async fn test_health_endpoint() { + let app = app(); + let response = app.oneshot(Request::builder().uri("/health").body(Body::empty()).unwrap()).await.unwrap(); + assert_eq!(response.status(), StatusCode::OK); + let body = to_bytes(response.into_body(), 1024).await.unwrap(); + assert_eq!(&body[..], b"{\"status\":\"ok\"}"); + } +} |
