Add full update integration test

This commit is contained in:
Caelan Sayler
2023-12-23 15:08:47 +00:00
parent a21656bb6a
commit 19fc1be949
12 changed files with 328 additions and 29 deletions

View File

@@ -0,0 +1,19 @@
using Microsoft.Extensions.Logging;
class ConsoleLogger : ILogger
{
public IDisposable BeginScope<TState>(TState state) where TState : notnull
{
return null;
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
Console.WriteLine(formatter(state, exception));
}
}

1
test/TestApp/Const.cs Normal file
View File

@@ -0,0 +1 @@
class Const { public const string TEST_STRING = "Hello, World!"; }

64
test/TestApp/Program.cs Normal file
View File

@@ -0,0 +1,64 @@
using Squirrel;
using Squirrel.Locators;
try {
if (args.Length >= 1 && args[0].StartsWith("--squirrel")) {
// squirrel hooks
File.AppendAllText(Path.Combine(AppContext.BaseDirectory, "args.txt"), String.Join(" ", args) + Environment.NewLine);
return 0;
}
if (args.Length == 1 && args[0] == "version") {
var locator = SquirrelLocator.GetDefault(new ConsoleLogger());
Console.WriteLine(locator.CurrentlyInstalledVersion);
return 0;
}
if (args.Length == 1 && args[0] == "test") {
Console.WriteLine(Const.TEST_STRING);
return 0;
}
if (args.Length == 2) {
if (args[0] == "check") {
var um = new UpdateManager(args[1], null, new ConsoleLogger());
var info = um.CheckForUpdates();
if (info == null) {
Console.WriteLine("no updates");
return 0;
} else {
Console.WriteLine("update: " + info.TargetFullRelease.Version);
return 0;
}
}
if (args[0] == "download") {
var um = new UpdateManager(args[1], null, new ConsoleLogger());
var info = um.CheckForUpdates();
if (info == null) {
Console.WriteLine("no updates");
return -1;
}
um.DownloadUpdates(info, (x) => Console.WriteLine(x));
return 0;
}
if (args[0] == "apply") {
var um = new UpdateManager(args[1], null, new ConsoleLogger());
if (!um.IsUpdatePendingRestart) {
Console.WriteLine("not pending restart");
return -1;
}
Console.WriteLine("applying...");
um.ApplyUpdatesAndExit();
return 0;
}
}
} catch (Exception ex) {
Console.WriteLine("exception: " + ex.ToString());
return -1;
}
Console.WriteLine("Invalid args: " + String.Join(", ", args));
return -1;

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Squirrel\Squirrel.csproj" />
</ItemGroup>
</Project>