Skip to content

Commit

Permalink
add test for downloading cleo in dev mode
Browse files Browse the repository at this point in the history
  • Loading branch information
voelkera committed Apr 22, 2024
1 parent 3c52199 commit 5a4f323
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions opendut-carl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
33 changes: 33 additions & 0 deletions opendut-carl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

}

0 comments on commit 5a4f323

Please sign in to comment.