Add test for automatic update

This commit is contained in:
Caelan Sayler
2023-12-26 20:45:38 +00:00
parent ce35a294db
commit a3a8e319bd
2 changed files with 45 additions and 3 deletions

View File

@@ -266,6 +266,41 @@ public class WindowsPackTests
}
}
[SkippableFact]
public void TestAppAutoUpdatesWhenLocalIsAvailable()
{
Skip.IfNot(SquirrelRuntimeInfo.IsWindows);
using var logger = _output.BuildLoggerFor<WindowsPackTests>();
using var _1 = Utility.GetTempDirectory(out var releaseDir);
using var _2 = Utility.GetTempDirectory(out var installDir);
string id = "SquirrelAutoUpdateTest";
var appPath = Path.Combine(installDir, "current", "TestApp.exe");
// pack v1
PackTestApp(id, "1.0.0", "version 1 test", releaseDir, logger);
// install app
var setupPath1 = Path.Combine(releaseDir, $"{id}-Setup-[win-x64].exe");
RunNoCoverage(setupPath1, new string[] { "--nocolor", "--silent", "--installto", installDir },
Environment.GetFolderPath(Environment.SpecialFolder.Desktop), logger);
// pack v2
PackTestApp(id, "2.0.0", "version 2 test", releaseDir, logger);
// move package into local packages dir
var fileName = $"{id}-2.0.0-win-x64-full.nupkg";
var mvFrom = Path.Combine(releaseDir, fileName);
var mvTo = Path.Combine(installDir, "packages", fileName);
File.Copy(mvFrom, mvTo);
RunCoveredDotnet(appPath, new string[] { "--autoupdate" }, installDir, logger, exitCode: null);
Thread.Sleep(2000);
var chk1version = RunCoveredDotnet(appPath, new string[] { "version" }, installDir, logger);
Assert.EndsWith(Environment.NewLine + "2.0.0", chk1version);
}
[SkippableFact]
public void TestAllApplicationHooks()
{
@@ -281,7 +316,7 @@ public class WindowsPackTests
// install app
var setupPath1 = Path.Combine(releaseDir, $"{id}-Setup-[win-x64].exe");
RunNoCoverage(setupPath1, new string[] { "--nocolor", "--verbose", "--installto", installDir },
RunNoCoverage(setupPath1, new string[] { "--nocolor", "--installto", installDir },
Environment.GetFolderPath(Environment.SpecialFolder.Desktop), logger);
var argsPath = Path.Combine(installDir, "args.txt");
@@ -303,7 +338,7 @@ public class WindowsPackTests
var logFile = Path.Combine(installDir, "Clowd.Squirrel.log");
logger.Info("TEST: update log output - " + Environment.NewLine + File.ReadAllText(logFile));
Assert.Contains("--squirrel-obsolete 1.0.0", File.ReadAllText(argsPath).Trim());
Assert.Contains("--squirrel-updated 2.0.0", File.ReadAllText(argsPath).Trim());

View File

@@ -6,8 +6,10 @@ using Squirrel.Locators;
try {
bool shouldExit = false;
bool shouldAutoUpdate = args.Any(a => a.Equals("--autoupdate", StringComparison.OrdinalIgnoreCase));
SquirrelApp.Build()
.SetAutoApplyOnStartup(false)
.SetAutoApplyOnStartup(shouldAutoUpdate)
.WithFirstRun((v) => {
debugFile("firstrun", v.ToString());
Console.WriteLine("was first run");
@@ -24,6 +26,11 @@ try {
.WithBeforeUninstallFastCallback((v) => debugFile("args.txt", String.Join(" ", args)))
.Run(new ConsoleLogger());
if (shouldAutoUpdate) {
// this shouldn't be reached
return -1;
}
if (shouldExit) {
return 0;
}