diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-01 16:47:50 +0200 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-01 16:47:50 +0200 |
| commit | f6eb35d7f63893269b8ca13b45e820c335f8f6c8 (patch) | |
| tree | 34f4a789bbdae8f665f233e5dc1141980f2a3d6b /src | |
| download | genenetwork4-f6eb35d7f63893269b8ca13b45e820c335f8f6c8.tar.gz | |
init
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..84e8c7e --- /dev/null +++ b/src/main.rs @@ -0,0 +1,41 @@ +use axum::{routing::get, Router}; + +/// Build the application router. Kept separate from `main` so tests can +/// exercise it directly without binding a real socket. +fn app() -> Router { + Router::new().route("/", get(hello_world)) +} + +async fn hello_world() -> &'static str { + "Hello, world!" +} + +#[tokio::main] +async fn main() { + let listener = tokio::net::TcpListener::bind("0.0.0.0:3000") + .await + .unwrap(); + axum::serve(listener, app()).await.unwrap(); +} + +#[cfg(test)] +mod tests { + use super::*; + use axum::body::Body; + use axum::http::{Request, StatusCode}; + use http_body_util::BodyExt; + use tower::ServiceExt; + + #[tokio::test] + async fn hello_world_returns_ok_with_greeting() { + let response = app() + .oneshot(Request::builder().uri("/").body(Body::empty()).unwrap()) + .await + .unwrap(); + + assert_eq!(response.status(), StatusCode::OK); + + let body = response.into_body().collect().await.unwrap().to_bytes(); + assert_eq!(&body[..], b"Hello, world!"); + } +} |
