diff --git a/Cargo.lock b/Cargo.lock index d8f71770..2f0e5b21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2590,6 +2590,7 @@ name = "opendut-carl" version = "0.1.0" dependencies = [ "anyhow", + "assert_fs", "async-trait", "axum", "axum-server", diff --git a/opendut-carl/Cargo.toml b/opendut-carl/Cargo.toml index 271c296f..1302d3b0 100644 --- a/opendut-carl/Cargo.toml +++ b/opendut-carl/Cargo.toml @@ -44,6 +44,7 @@ url = { workspace = true, features = ["serde"] } uuid = { workspace = true } [dev-dependencies] +assert_fs = { workspace = true } async-trait = { workspace = true } rstest = { workspace = true } uuid = { workspace = true, features = ["v4"] } diff --git a/opendut-carl/src/lib.rs b/opendut-carl/src/lib.rs index b85a7e7c..2c06b4d5 100644 --- a/opendut-carl/src/lib.rs +++ b/opendut-carl/src/lib.rs @@ -459,3 +459,36 @@ impl CleoArch { CLEO_ARCH.iter() } } + +#[cfg(test)] +mod test { + use assert_fs::fixture::{FileTouch, PathChild}; + use assert_fs::TempDir; + use axum::extract::Path; + use axum::response::IntoResponse; + use googletest::assert_that; + use googletest::matchers::eq; + use http::header; + use tracing::warn; + use crate::{CleoArch, download_cleo}; + + #[tokio::test()] + async fn download_cleo_development_succeeds() -> anyhow::Result<()> { + let temp = TempDir::new().unwrap(); + + let dir = temp.child("target/debug/opendut-cleo"); + dir.touch().unwrap(); + + std::env::set_current_dir(&temp).unwrap_or_else(|_| warn!("Could not set back current directory to {}", temp.display())); + + let cleo = download_cleo(Path(CleoArch::Development)).await; + let response = cleo.into_response(); + let header = response.headers().get(header::CONTENT_DISPOSITION).unwrap(); + let expected_header = format!("attachment; filename=\"{}\"", CleoArch::Development.file_name()); + assert_that!(header.clone().to_str().unwrap(), eq(expected_header.as_str())); + + Ok(()) + } + +} +