mirror of
https://github.com/rmcrackan/Libation.git
synced 2026-09-12 21:57:19 -04:00
Libation asked GitHub for a newer release every time it started, with no way to stop it. That is noise for anyone whose install is updated by something else - a package manager, or an AppImage updater - because the prompt it raises is one they can do nothing useful with. Add CheckForUpgradesAtStartup, on by default so nothing changes for people who rely on the prompt. Only the automatic check is optional: the About window's "Check for Upgrade" button and the CLI's `version --check` ask for a check outright, so they run either way. That is why the setting is read in a new CheckForUpgradeAtStartupAsync rather than inside CheckForUpgradeAsync, which the startup path and the About button share. The new setting takes the slot of BetaOptIn, which is deleted here. It was declared, described and logged, but no axaml or designer ever bound it and nothing read the value: GetLatestRelease only ever asks for the stable release, so there was no beta channel for it to select. A stale BetaOptIn key in an existing Settings.json needs no migration, since PersistentDictionary ignores keys with no matching property. Closes #1999 Co-authored-by: rmcrackan <rmcrackan@gmail.com>
82 lines
2.7 KiB
C#
82 lines
2.7 KiB
C#
using LibationFileManager;
|
|
|
|
namespace LibationUiBase.Tests;
|
|
|
|
/// <summary>
|
|
/// Covers the one thing the CheckForUpgradesAtStartup setting has to do: keep the startup check off
|
|
/// the network when it is off, and leave it alone when it is on.
|
|
/// <para>
|
|
/// <see cref="MockUpgrader"/> is the seam. With <see cref="MockUpgrader.CheckForUpgradeSucceeds"/>
|
|
/// false, the check reports its own distinctive failure and the flow returns before reaching
|
|
/// <c>InteropFactory</c>, whose <c>CanUpgrade</c> throws off-platform. That failure message is
|
|
/// therefore proof that the check ran, and its absence proof that it did not.
|
|
/// </para>
|
|
/// </summary>
|
|
[TestClass]
|
|
[DoNotParallelize]
|
|
public class StartupUpgradeCheckTests
|
|
{
|
|
private const string CheckRanMessage = "Mock Check For Upgrade Failed";
|
|
|
|
[TestCleanup]
|
|
public void Cleanup()
|
|
{
|
|
Configuration.RestoreSingletonInstance();
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task Startup_checks_when_the_setting_is_on()
|
|
{
|
|
var config = Configuration.CreateMockInstance();
|
|
config.CheckForUpgradesAtStartup = true;
|
|
|
|
var (upgrader, failures) = BuildUpgraderThatFailsItsCheck();
|
|
await upgrader.CheckForUpgradeAtStartupAsync(ShouldNotBeCalled);
|
|
|
|
Assert.AreEqual(1, failures.Count);
|
|
StringAssert.Contains(failures[0], CheckRanMessage);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task Startup_does_not_check_when_the_setting_is_off()
|
|
{
|
|
var config = Configuration.CreateMockInstance();
|
|
config.CheckForUpgradesAtStartup = false;
|
|
|
|
var (upgrader, failures) = BuildUpgraderThatFailsItsCheck();
|
|
await upgrader.CheckForUpgradeAtStartupAsync(ShouldNotBeCalled);
|
|
|
|
Assert.AreEqual(0, failures.Count);
|
|
}
|
|
|
|
// Turning the automatic check off must not disable the About window's "Check for Upgrade"
|
|
// button, which calls CheckForUpgradeAsync directly.
|
|
[TestMethod]
|
|
public async Task A_requested_check_still_runs_when_the_setting_is_off()
|
|
{
|
|
var config = Configuration.CreateMockInstance();
|
|
config.CheckForUpgradesAtStartup = false;
|
|
|
|
var (upgrader, failures) = BuildUpgraderThatFailsItsCheck();
|
|
var result = await upgrader.CheckForUpgradeAsync(ShouldNotBeCalled);
|
|
|
|
Assert.AreEqual(AppScaffolding.VersionCheckOutcome.UnableToDetermine, result.Outcome);
|
|
Assert.AreEqual(1, failures.Count);
|
|
StringAssert.Contains(failures[0], CheckRanMessage);
|
|
}
|
|
|
|
private static (MockUpgrader Upgrader, List<string> Failures) BuildUpgraderThatFailsItsCheck()
|
|
{
|
|
var upgrader = new MockUpgrader { CheckForUpgradeSucceeds = false };
|
|
List<string> failures = [];
|
|
upgrader.UpgradeFailed += (_, message) => failures.Add(message);
|
|
return (upgrader, failures);
|
|
}
|
|
|
|
private static Task ShouldNotBeCalled(UpgradeEventArgs e)
|
|
{
|
|
Assert.Fail("The upgrade-available handler ran, but the check was supposed to fail before an update could be offered.");
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|