diff --git a/tests/assertions/mod.rs b/tests/assertions/mod.rs index 836355d..57db58a 100644 --- a/tests/assertions/mod.rs +++ b/tests/assertions/mod.rs @@ -2,6 +2,7 @@ #![allow(clippy::uninlined_format_args)] use crate::docker::ExecResult; +use std::path::Path; pub fn assert_success(result: ExecResult) -> String { match result { @@ -29,3 +30,9 @@ pub fn assert_contains(expected: &str, actual: &str) { expected ) } + +pub fn assert_file_exists(path: &Path) { + if !path.exists() { + panic!("File does not exist: {:?}", path) + } +} diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 97f9a03..3c2d12f 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1,3 +1,5 @@ +mod assertions; +mod docker; mod fs; mod archives { @@ -8,6 +10,8 @@ mod archives { use assert_cmd::assert::OutputAssertExt; use assert_cmd::prelude::CommandCargoExt; + use crate::assertions::assert_file_exists; + #[cfg(target_family = "unix")] #[test_case("helloworld.tar.gz"; "tar gzip")] #[test_case("helloworld.tgz"; "tar tgz")] @@ -77,6 +81,52 @@ mod archives { .failure() .stderr(predicates::str::contains("No executable found")); } + + #[cfg(target_family = "unix")] + #[test_case("helloworld-many-executables-unix.tar.gz", "helloworld-v2"; "install helloworld-v2")] + fn install_file_successfully(asset: &str, file: &str) { + let temp_dir = any_temp_dir(); + let expected_installed_file = temp_dir.join(file); + let output_dir = path_to_string(temp_dir); + + let mut cmd = Command::cargo_bin("dra").unwrap(); + + let result = cmd + .arg("download") + .args(["-I", file]) + .args(["-s", asset]) + .args(["-o", &output_dir]) + .arg("devmatteini/dra-tests") + .assert(); + + result + .success() + .stdout(predicates::str::contains("Installation completed")); + assert_file_exists(&expected_installed_file); + } + + #[cfg(target_os = "windows")] + #[test_case("helloworld-many-executables-windows.zip", "helloworld-v2.exe"; "install helloworld-v2.exe")] + fn install_file_successfully(asset: &str, file: &str) { + let temp_dir = any_temp_dir(); + let expected_installed_file = temp_dir.join(file); + let output_dir = path_to_string(temp_dir); + + let mut cmd = Command::cargo_bin("dra").unwrap(); + + let result = cmd + .arg("download") + .args(["-I", file]) + .args(["-s", asset]) + .args(["-o", &output_dir]) + .arg("devmatteini/dra-tests") + .assert(); + + result + .success() + .stdout(predicates::str::contains("Installation completed")); + assert_file_exists(&expected_installed_file); + } } mod download {