154 lines
5.9 KiB
Rust
154 lines
5.9 KiB
Rust
use super::*;
|
|
|
|
#[test]
|
|
fn a_launch_hands_the_chosen_channels_package_to_the_installer_once() {
|
|
let key = key();
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let public = key.public_key().as_ref();
|
|
let stable = keep(dir.path(), &key, "stable", "1.1.0");
|
|
keep(dir.path(), &key, "stable", "1.0.1");
|
|
// Left from before a change to Stable, until the next check removes it.
|
|
let beta = keep(dir.path(), &key, "beta", "1.2.0-beta.1");
|
|
let launch = |channel, installed, start: Start, outcome: Outcome| {
|
|
update_at_launch(dir.path(), public, channel, installed, start, outcome)
|
|
};
|
|
let stable_launch =
|
|
|start: Start, outcome: Outcome| launch(UpdateChannel::Stable, "1.0.0", start, outcome);
|
|
|
|
let mut started = Vec::new();
|
|
let first = stable_launch(&mut recording(&mut started, 42), &mut no_installer);
|
|
assert!(applying(&first), "{first:?}");
|
|
assert_eq!(started, [stable]);
|
|
|
|
// A launch while the installer runs waits for it and leaves the app to the version it opens.
|
|
let succeeded = stable_launch(&mut never_started, &mut |pid| (pid == 42).then_some(0));
|
|
assert!(applying(&succeeded), "{succeeded:?}");
|
|
// After a failure the version in place loads and says so once, then never retries on its own.
|
|
let failed = stable_launch(&mut never_started, &mut |_| Some(1));
|
|
assert!(reports_failed(&failed, "1.1.0"), "{failed:?}");
|
|
let next = stable_launch(&mut never_started, &mut no_installer);
|
|
assert!(loads_quietly(&next), "{next:?}");
|
|
|
|
// « Redémarrer » retries it; an installer that is gone counts as failed.
|
|
let restart = restart_to_update(dir.path(), public, UpdateChannel::Stable, "1.0.0", |_| {
|
|
Ok(43)
|
|
});
|
|
assert!(restart.is_ok());
|
|
let gone = stable_launch(&mut never_started, &mut |pid| (pid != 43).then_some(0));
|
|
assert!(reports_failed(&gone, "1.1.0"), "{gone:?}");
|
|
|
|
// Once the new version is installed, nothing is left to apply.
|
|
let installed = launch(
|
|
UpdateChannel::Stable,
|
|
"1.1.0",
|
|
&mut never_started,
|
|
&mut no_installer,
|
|
);
|
|
assert!(loads_quietly(&installed), "{installed:?}");
|
|
// The Bêta channel takes only its own package.
|
|
let mut started = Vec::new();
|
|
let beta_launch = launch(
|
|
UpdateChannel::Beta,
|
|
"1.1.0",
|
|
&mut recording(&mut started, 44),
|
|
&mut no_installer,
|
|
);
|
|
assert!(applying(&beta_launch), "{beta_launch:?}");
|
|
assert_eq!(started, [beta]);
|
|
}
|
|
|
|
#[test]
|
|
fn an_altered_package_or_an_installer_that_cannot_start_leaves_the_installed_version() {
|
|
let key = key();
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let public = key.public_key().as_ref();
|
|
let package = keep(dir.path(), &key, "stable", "1.1.0");
|
|
let launch = |start: Start| {
|
|
update_at_launch(
|
|
dir.path(),
|
|
public,
|
|
UpdateChannel::Stable,
|
|
"1.0.0",
|
|
start,
|
|
no_installer,
|
|
)
|
|
};
|
|
|
|
// Altered between the download and this launch: refused before the installer sees it.
|
|
fs::write(&package, b"altered").unwrap();
|
|
let refused = launch(&mut never_started);
|
|
assert!(
|
|
matches!(
|
|
refused,
|
|
ControlFlow::Continue(Some(Error::InvalidUpdate(_)))
|
|
),
|
|
"{refused:?}"
|
|
);
|
|
let restart = restart_to_update(
|
|
dir.path(),
|
|
public,
|
|
UpdateChannel::Stable,
|
|
"1.0.0",
|
|
never_started,
|
|
);
|
|
assert!(matches!(restart, Err(Error::InvalidUpdate(_))));
|
|
|
|
// Downloaded again, then the installer cannot start: reported, and no launch loops on it.
|
|
fs::write(&package, b"package 1.1.0").unwrap();
|
|
let failed = launch(&mut |_| Err(std::io::ErrorKind::NotFound.into()));
|
|
assert!(reports_failed(&failed, "1.1.0"), "{failed:?}");
|
|
let next = launch(&mut never_started);
|
|
assert!(loads_quietly(&next), "{next:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_failed_version_is_not_retried_at_launch_but_a_newer_release_is() {
|
|
let key = key();
|
|
let (url, downloads) = serve(vec![publish(&key, "stable", "1.1.0")], false);
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let public = key.public_key().as_ref();
|
|
let check = || download_update(&url, dir.path(), public, UpdateChannel::Stable, "1.0.0");
|
|
let launch = |start: Start, outcome: Outcome| {
|
|
update_at_launch(
|
|
dir.path(),
|
|
public,
|
|
UpdateChannel::Stable,
|
|
"1.0.0",
|
|
start,
|
|
outcome,
|
|
)
|
|
};
|
|
assert_eq!(check().unwrap().as_deref(), Some("1.1.0"));
|
|
assert!(applying(&launch(&mut |_| Ok(42), &mut no_installer)));
|
|
|
|
// Velopack deletes a package it cannot open, then reopens the version in place.
|
|
let package = dir
|
|
.path()
|
|
.join("stable-1.1.0/ArenaTracker-1.1.0-stable-full.nupkg");
|
|
fs::remove_file(&package).unwrap();
|
|
let failed = launch(&mut never_started, &mut |_| Some(1));
|
|
assert!(reports_failed(&failed, "1.1.0"), "{failed:?}");
|
|
assert_eq!(check().unwrap().as_deref(), Some("1.1.0"));
|
|
assert_eq!(downloads.load(Ordering::SeqCst), 2);
|
|
let next = launch(&mut never_started, &mut no_installer);
|
|
assert!(loads_quietly(&next), "{next:?}");
|
|
|
|
// The next release gets its own attempt: the app never stays on the version in place.
|
|
let newer = vec![
|
|
publish(&key, "stable", "1.1.0"),
|
|
publish(&key, "stable", "1.2.0"),
|
|
publish(&key, "stable", "1.3.0"),
|
|
];
|
|
let (url, _) = serve(newer, false);
|
|
let ready = download_update(&url, dir.path(), public, UpdateChannel::Stable, "1.0.0");
|
|
assert_eq!(ready.unwrap().as_deref(), Some("1.3.0"));
|
|
assert_eq!(kept(dir.path()), ["stable-1.3.0"]);
|
|
let mut started = Vec::new();
|
|
let newest = launch(&mut recording(&mut started, 43), &mut no_installer);
|
|
assert!(applying(&newest), "{newest:?}");
|
|
let package = dir
|
|
.path()
|
|
.join("stable-1.3.0/ArenaTracker-1.3.0-stable-full.nupkg");
|
|
assert_eq!(started, [package]);
|
|
}
|