Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify updater tests #2060

Draft
wants to merge 14 commits into
base: v2
Choose a base branch
from
2 changes: 2 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions plugins/updater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ flate2 = { version = "1", optional = true }
tar = "0.4"
flate2 = "1"

[dev-dependencies]
dunce = { workspace = true }

[features]
default = ["rustls-tls", "zip"]
zip = ["dep:zip", "dep:tar", "dep:flate2"]
Expand Down
18 changes: 11 additions & 7 deletions plugins/updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,20 +616,24 @@ impl Update {
.chain(self.installer_args())
.collect(),
WindowsUpdaterType::Msi { path, .. } => {
let escaped_args = current_args
.iter()
.map(escape_msi_property_arg)
.collect::<Vec<_>>()
.join(" ");
msi_args = OsString::from(format!("LAUNCHAPPARGS=\"{escaped_args}\""));
msi_args = if !current_args.is_empty() {
let escaped_args = current_args
.iter()
.map(escape_msi_property_arg)
.collect::<Vec<_>>()
.join(" ");
OsString::from(format!("LAUNCHAPPARGS=\"{escaped_args}\""))
} else {
OsString::new()
};

[OsStr::new("/i"), path.as_os_str()]
.into_iter()
.chain(install_mode.msiexec_args().iter().map(OsStr::new))
.chain(once(OsStr::new("/promptrestart")))
.chain(self.installer_args())
.chain(once(OsStr::new("AUTOLAUNCHAPP=True")))
.chain(once(msi_args.as_os_str()))
.chain(once(msi_args.as_os_str()).filter(|a| !a.is_empty()))
.collect()
}
};
Expand Down
5 changes: 5 additions & 0 deletions plugins/updater/tests/app-updater/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[target.'cfg(windows)']
runner = "powershell -Command Start-Process -Verb runAs -FilePath"

[target.x86_64-unknown-linux-gnu]
runner = 'sudo -E'
3 changes: 3 additions & 0 deletions plugins/updater/tests/app-updater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ tauri-plugin-updater = { path = "../.." }
tiny_http = "0.12"
time = { version = "0.3", features = ["formatting"] }

[target."cfg(windows)".dependencies]
dunce = { workspace = true }

[features]
prod = ["tauri/custom-protocol"]
36 changes: 19 additions & 17 deletions plugins/updater/tests/app-updater/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,31 @@ fn main() {
.plugin(tauri_plugin_updater::Builder::new().build())
.setup(|app| {
let handle = app.handle().clone();
eprintln!("app version: {}", app.package_info().version);

tauri::async_runtime::spawn(async move {
#[allow(unused_mut)]
let mut builder = handle.updater_builder();
if std::env::var("TARGET").unwrap_or_default() == "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.
// 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={}",
tauri::utils::platform::current_exe()
.unwrap()
.parent()
.unwrap()
.display()
)]);

// Overriding installation directory for integration tests on Windows
#[cfg(windows)]
{
let target = std::env::var("TARGET").unwrap_or_default();
let exe = tauri::utils::platform::current_exe().unwrap();
let dir = dunce::simplified(exe.parent().unwrap()).display();
if target == "nsis" {
builder = builder.installer_arg(format!("/D=\"{dir}\"",));
} else if target == "msi" {
builder = builder.installer_arg(format!("INSTALLDIR=\"{dir}\""));
}
}

let updater = builder.build().unwrap();

match updater.check().await {
Ok(Some(update)) => {
if let Err(e) = update.download_and_install(|_, _| {}, || {}).await {
println!("{e}");
eprintln!("{e}");
std::process::exit(1);
}
std::process::exit(0);
Expand All @@ -45,8 +47,8 @@ fn main() {
std::process::exit(2);
}
Err(e) => {
println!("{e}");
std::process::exit(1);
eprintln!("{e}");
std::process::exit(3);
}
}
});
Expand Down
3 changes: 1 addition & 2 deletions plugins/updater/tests/app-updater/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"endpoints": ["http://localhost:3007"],
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEUwNDRGMjkwRjg2MDhCRDAKUldUUWkyRDRrUEpFNEQ4SmdwcU5PaXl6R2ZRUUNvUnhIaVkwVUltV0NMaEx6VTkrWVhpT0ZqeEEK",
"windows": {
"installMode": "quiet",
"installerArgs": ["/NS"]
"installMode": "quiet"
}
}
},
Expand Down
Loading
Loading