use axum_test::TestServer; use ares_server::config::Config; use ares_server::state::AppState; use ares_server::store; use ares_server::router; static TEST_DB_COUNTER: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); pub fn test_server() -> TestServer { let n = TEST_DB_COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed); let db_path = std::env::temp_dir() .join(format!("ares_test_{}_{}.db", std::process::id(), n)) .to_string_lossy() .into_owned(); let cfg = Config { db_path, ..Default::default() }; let conn = store::open(&cfg).unwrap(); let state = AppState::new(cfg, conn); TestServer::new(router(state)) } pub async fn announce_test_file(server: &TestServer, name: &str, ftype: &str, hash: &str) { server.post("/api/v1/announce") .json(&serde_json::json!({ "peer_id": "peer9", "name": name, "description": "", "type": ftype, "extension": name.rsplit('.').next().unwrap_or("bin"), "size_bytes": 100, "hash": hash, "license": "authored" })) .await; }