Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Add test for automatic update
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Dec 26, 2023
1 parent ce35a29 commit a3a8e31
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
39 changes: 37 additions & 2 deletions test/Squirrel.Packaging.Tests/WindowsPackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,41 @@ public void PackBuildsPackageWhichIsInstallable()
}
}

[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()
{
Expand All @@ -281,7 +316,7 @@ public void TestAllApplicationHooks()

// 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");
Expand All @@ -303,7 +338,7 @@ public void TestAllApplicationHooks()

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());

Expand Down
9 changes: 8 additions & 1 deletion test/TestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

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");
Expand All @@ -24,6 +26,11 @@
.WithBeforeUninstallFastCallback((v) => debugFile("args.txt", String.Join(" ", args)))
.Run(new ConsoleLogger());

if (shouldAutoUpdate) {
// this shouldn't be reached
return -1;
}

if (shouldExit) {
return 0;
}
Expand Down

0 comments on commit a3a8e31

Please sign in to comment.