Skip to content

Commit

Permalink
fix Rust integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amr-crabnebula committed Nov 23, 2023
1 parent 6126668 commit 53ee617
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
9 changes: 3 additions & 6 deletions crates/updater/tests/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ fn main() {
let format = std::env::var("UPDATER_FORMAT").unwrap_or_default();

match format.as_str() {
"nsis" => {
// /D sets the default installation directory ($INSTDIR),
// overriding InstallDir and InstallDirRegKey.
// It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces.
// Only absolute paths are supported.
"nsis" | "wix" => {
// NOTE: we only need this because this is an integration test and we don't want to install the app in the programs folder
builder = builder.installer_args(vec![format!(
"/D={}",
"{}={}",
if format == "nsis" { "/D" } else { "INSTALLDIR" },
std::env::current_exe().unwrap().parent().unwrap().display()
)]);
}
Expand Down
57 changes: 56 additions & 1 deletion crates/updater/tests/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn build_app(cwd: &Path, root_dir: &Path, version: &str, target: &[UpdaterFormat
"--package",
"cargo-packager",
"--",
"--verbose",
"-f",
&target.iter().map(|t|t.name()).collect::<Vec<_>>().join(","),
"-c",
Expand Down Expand Up @@ -141,7 +142,7 @@ fn update_app() {
let out_updater_path = if out_package_path.is_dir() {
out_package_path.with_extension(format!("{}.{}", out_package_ext, "tar.gz"))
} else {
out_package_path
out_package_path.clone()
};

let signature_path = out_updater_path.with_extension(format!(
Expand Down Expand Up @@ -221,6 +222,60 @@ fn update_app() {
// bundle initial app version
build_app(&manifest_dir, &root_dir, "0.1.0", &[updater_format]);

// install the app through the installer
#[cfg(windows)]
{
let install_dir = root_dir
.join("target/debug")
.display()
.to_string()
.replace("\\\\?\\", "");

let mut installer_arg = std::ffi::OsString::new();
installer_arg.push("\"");
installer_arg.push(
out_package_path
.display()
.to_string()
.replace("\\\\?\\", ""),
);
installer_arg.push("\"");

let status = Command::new("powershell.exe")
.args(["-NoProfile", "-WindowStyle", "Hidden"])
.args(["Start-Process"])
.arg(installer_arg)
.arg("-ArgumentList")
.arg(
[
match updater_format {
UpdaterFormat::Wix => "/passive",
UpdaterFormat::Nsis => "/P",
_ => unreachable!(),
},
&format!(
"{}={}",
match updater_format {
UpdaterFormat::Wix => "INSTALLDIR",
UpdaterFormat::Nsis => "/D",
_ => unreachable!(),
},
install_dir
),
]
.join(", "),
)
.status()
.expect("failed to run installer");

if !status.success() {
panic!("failed to run installer");
}
}

// wait 2secs to make sure the installer have released its lock on the binary
std::thread::sleep(std::time::Duration::from_secs(2));

let mut binary_cmd = if cfg!(windows) {
Command::new(root_dir.join("target/debug/cargo-packager-updater-app-test.exe"))
} else if cfg!(target_os = "macos") {
Expand Down

0 comments on commit 53ee617

Please sign in to comment.