use std::net::{Ipv4Addr, SocketAddr}; use axum::{body::Body, http::Request}; use http_body_util::BodyExt; use tower::ServiceExt; use upl::app::{AppConfig, build_router}; #[tokio::test] async fn serves_index_page() -> Result<(), Box> { let app = test_app(); let response = app .oneshot(Request::builder().uri("/").body(Body::empty())?) .await?; assert_eq!(response.status(), axum::http::StatusCode::OK); let body = response.into_body().collect().await?.to_bytes(); let body = String::from_utf8(body.to_vec())?; assert!(body.contains("upl")); assert!(body.contains("Select file")); Ok(()) } #[tokio::test] async fn reports_health() -> Result<(), Box> { let app = test_app(); let response = app .oneshot(Request::builder().uri("/healthz").body(Body::empty())?) .await?; assert_eq!(response.status(), axum::http::StatusCode::OK); let body = response.into_body().collect().await?.to_bytes(); assert_eq!(body.as_ref(), b"ok"); Ok(()) } fn test_app() -> axum::Router { build_router(&AppConfig::new( SocketAddr::from((Ipv4Addr::LOCALHOST, 0)), concat!(env!("CARGO_MANIFEST_DIR"), "/static"), )) }