diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-01 16:57:48 +0200 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-01 16:57:48 +0200 |
| commit | b6374cf8d80c161cfed761d4c97eff320f311539 (patch) | |
| tree | e8189619ad397a5da116e8296c1b74205808a7e1 /src | |
| parent | 093c81ba42be704a73dad0193d901e4e3c878ace (diff) | |
| download | genenetwork4-b6374cf8d80c161cfed761d4c97eff320f311539.tar.gz | |
Move tests out
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 11 | ||||
| -rw-r--r-- | src/main.rs | 36 |
2 files changed, 12 insertions, 35 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d5bbaec --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,11 @@ +use axum::{routing::get, Router}; + +/// Build the application router. Public so integration tests (tests/) and +/// the binary (src/main.rs) can both use it without binding a real socket. +pub fn app() -> Router { + Router::new().route("/", get(hello_world)) +} + +async fn hello_world() -> &'static str { + "Hello, world!" +} diff --git a/src/main.rs b/src/main.rs index 84e8c7e..d303abd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,41 +1,7 @@ -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!"); - } + axum::serve(listener, genenetwork4::app()).await.unwrap(); } |
