Files
upl/tests/static_server.rs
T
ddidderr 24ecdbd251 feat: persist upload creation metadata
Add the first upload API endpoint from PLAN.md. POST /api/uploads now
validates the requested file name, generates a server-owned upload id, creates
the staging and complete directory layout, and writes durable meta.json before
returning chunk scheduling details to the browser.

Keep filesystem layout knowledge in storage.rs so later chunk upload and
completion work can reuse the same boundary. API handlers translate storage
errors into JSON HTTP responses without leaking layout details into the router.

Document the new modules and UPL_DATA_DIR configuration, and extend TESTS.md
with the automated creation coverage.

Test Plan:
- just check

Refs: PLAN.md milestone 2
2026-05-30 16:57:48 +02:00

53 lines
1.4 KiB
Rust

use std::{
net::{Ipv4Addr, SocketAddr},
path::Path,
};
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<dyn std::error::Error>> {
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("<title>upl</title>"));
assert!(body.contains("Select file"));
Ok(())
}
#[tokio::test]
async fn reports_health() -> Result<(), Box<dyn std::error::Error>> {
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"),
Path::new(env!("CARGO_MANIFEST_DIR")).join("target/test-data/static-server"),
))
}