Skip to content

Commit

Permalink
tests: add tests for download --install-file
Browse files Browse the repository at this point in the history
  • Loading branch information
devmatteini committed Jul 25, 2024
1 parent 8e42163 commit d2a87c1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/assertions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
50 changes: 50 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod assertions;
mod docker;
mod fs;

mod archives {
Expand All @@ -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")]
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d2a87c1

Please sign in to comment.