mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Fix more tests
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Velopack.Packaging;
|
||||
using Velopack.Sources;
|
||||
|
||||
namespace Velopack.Deployment;
|
||||
|
||||
public class RepositoryOptions
|
||||
{
|
||||
public string Channel { get; set; }
|
||||
public string Channel { get; set; } = ReleaseEntryHelper.GetDefaultChannel();
|
||||
|
||||
public DirectoryInfo ReleaseDir { get; set; }
|
||||
}
|
||||
|
||||
@@ -218,26 +218,23 @@ namespace Velopack.Packaging
|
||||
runtimeDependenciesText = $"<runtimeDependencies>{runtimeDeps}</runtimeDependencies>";
|
||||
}
|
||||
|
||||
var extraLines = String.Join(Environment.NewLine, new[] { osMinVersionText, machineArchitectureText, releaseNotesText, runtimeDependenciesText })
|
||||
.Split(new char[] { '\r', '\n' })
|
||||
.Where(e => !String.IsNullOrWhiteSpace(e))
|
||||
.Select(e => $" {e.Trim()}")
|
||||
.ToArray();
|
||||
|
||||
string nuspec = $"""
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>{packId}</id>
|
||||
<title>{packTitle ?? packId}</title>
|
||||
<description>{packTitle ?? packId}</description>
|
||||
<authors>{packAuthors ?? packId}</authors>
|
||||
<version>{packVersion}</version>
|
||||
<channel>{Channel}</channel>
|
||||
<mainExe>{MainExeName}</mainExe>
|
||||
<os>{rid.BaseRID.GetOsShortName()}</os>
|
||||
{String.Join(Environment.NewLine, extraLines)}
|
||||
</metadata>
|
||||
<metadata>
|
||||
<id>{packId}</id>
|
||||
<title>{packTitle ?? packId}</title>
|
||||
<description>{packTitle ?? packId}</description>
|
||||
<authors>{packAuthors ?? packId}</authors>
|
||||
<version>{packVersion}</version>
|
||||
<channel>{Channel}</channel>
|
||||
<mainExe>{MainExeName}</mainExe>
|
||||
<os>{rid.BaseRID.GetOsShortName()}</os>
|
||||
{osMinVersionText}
|
||||
{machineArchitectureText}
|
||||
{releaseNotesText}
|
||||
{runtimeDependenciesText}
|
||||
</metadata>
|
||||
</package>
|
||||
""".Trim();
|
||||
|
||||
|
||||
@@ -162,13 +162,13 @@ namespace Velopack.Sources
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task DownloadReleaseEntry(ILogger logger, ReleaseEntry releaseEntry, string localFile, Action<int> progress)
|
||||
public Task DownloadReleaseEntry(ILogger logger, ReleaseEntry releaseEntry, string localFile, Action<int> progress)
|
||||
{
|
||||
if (releaseEntry is GithubReleaseEntry githubEntry) {
|
||||
// this might be a browser url or an api url (depending on whether we have a AccessToken or not)
|
||||
// https://docs.github.com/en/rest/reference/releases#get-a-release-asset
|
||||
var assetUrl = GetAssetUrlFromName(githubEntry.Release, releaseEntry.OriginalFilename);
|
||||
await Downloader.DownloadFile(assetUrl, localFile, progress, Authorization, "application/octet-stream").ConfigureAwait(false);
|
||||
return Downloader.DownloadFile(assetUrl, localFile, progress, Authorization, "application/octet-stream");
|
||||
}
|
||||
|
||||
throw new ArgumentException($"Expected releaseEntry to be {nameof(GithubReleaseEntry)} but got {releaseEntry.GetType().Name}.");
|
||||
|
||||
@@ -165,13 +165,13 @@ namespace Velopack.Sources
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task DownloadReleaseEntry(ILogger logger, ReleaseEntry releaseEntry, string localFile, Action<int> progress)
|
||||
public Task DownloadReleaseEntry(ILogger logger, ReleaseEntry releaseEntry, string localFile, Action<int> progress)
|
||||
{
|
||||
if (releaseEntry is GitlabReleaseEntry githubEntry) {
|
||||
// this might be a browser url or an api url (depending on whether we have a AccessToken or not)
|
||||
// https://docs.github.com/en/rest/reference/releases#get-a-release-asset
|
||||
var assetUrl = GetAssetUrlFromName(githubEntry.Release, releaseEntry.OriginalFilename);
|
||||
await Downloader.DownloadFile(assetUrl, localFile, progress, Authorization, "application/octet-stream").ConfigureAwait(false);
|
||||
return Downloader.DownloadFile(assetUrl, localFile, progress, Authorization, "application/octet-stream");
|
||||
}
|
||||
|
||||
throw new ArgumentException($"Expected releaseEntry to be {nameof(GitlabReleaseEntry)} but got {releaseEntry.GetType().Name}.");
|
||||
|
||||
@@ -135,9 +135,9 @@ This is just a _test_!
|
||||
if (String.IsNullOrEmpty(GITHUB_TOKEN))
|
||||
throw new Exception("VELOPACK_GITHUB_TEST_TOKEN is not set.");
|
||||
|
||||
var newVer = $"{VelopackRuntimeInfo.VelopackNugetVersion}-{uniqueSuffix}";
|
||||
PackTestApp(id, $"0.0.1-{uniqueSuffix}", "t1", releaseDir, logger, notesPath);
|
||||
PackTestApp(id, newVer, "t2", releaseDir, logger, notesPath);
|
||||
var newVer = $"{VelopackRuntimeInfo.VelopackNugetVersion}";
|
||||
PackTestApp(id, $"0.0.1", "t1", releaseDir, logger, notesPath, channel: uniqueSuffix);
|
||||
PackTestApp(id, newVer, "t2", releaseDir, logger, notesPath, channel: uniqueSuffix);
|
||||
|
||||
// deploy
|
||||
var gh = new GitHubRepository(logger);
|
||||
@@ -148,6 +148,7 @@ This is just a _test_!
|
||||
Token = GITHUB_TOKEN,
|
||||
Prerelease = false,
|
||||
Publish = true,
|
||||
Channel = uniqueSuffix,
|
||||
};
|
||||
gh.UploadMissingAssetsAsync(options).GetAwaiterResult();
|
||||
|
||||
@@ -158,14 +159,14 @@ This is just a _test_!
|
||||
|
||||
// update
|
||||
var source = new GithubSource(GITHUB_REPOURL, GITHUB_TOKEN, false);
|
||||
var releases = source.GetReleaseFeed(logger: logger).GetAwaiterResult();
|
||||
var releases = source.GetReleaseFeed(channel: uniqueSuffix, logger: logger).GetAwaiterResult();
|
||||
|
||||
var ghrel = releases.Select(r => (GithubReleaseEntry) r).ToArray();
|
||||
Assert.Equal(2, ghrel.Length);
|
||||
foreach (var r in ghrel) {
|
||||
Assert.Equal(releaseName, r.Release.Name);
|
||||
Assert.Equal(id, r.PackageId);
|
||||
Assert.Equal(newVer, r.Version.ToNormalizedString());
|
||||
Assert.Equal(newVer + "-" + uniqueSuffix, r.Version.ToNormalizedString());
|
||||
}
|
||||
|
||||
using var _2 = Utility.GetTempDirectory(out var releaseDirNew);
|
||||
@@ -173,9 +174,10 @@ This is just a _test_!
|
||||
Token = GITHUB_TOKEN,
|
||||
RepoUrl = GITHUB_REPOURL,
|
||||
ReleaseDir = new DirectoryInfo(releaseDirNew),
|
||||
Channel = uniqueSuffix,
|
||||
}).GetAwaiterResult();
|
||||
|
||||
var filename = $"{id}-{newVer}-{VelopackRuntimeInfo.SystemOs.GetOsShortName()}-full.nupkg";
|
||||
var filename = $"{id}-{newVer}-{uniqueSuffix}-full.nupkg";
|
||||
Assert.True(File.Exists(Path.Combine(releaseDirNew, filename)));
|
||||
}
|
||||
|
||||
|
||||
@@ -58,10 +58,10 @@ public class WindowsPackTests
|
||||
var runner = new WindowsPackCommandRunner(logger);
|
||||
runner.Run(options).GetAwaiterResult();
|
||||
|
||||
var nupkgPath = Path.Combine(tmpReleaseDir, $"{id}-{version}-asd123-win-x64-full.nupkg");
|
||||
var nupkgPath = Path.Combine(tmpReleaseDir, $"{id}-{version}-asd123-full.nupkg");
|
||||
Assert.True(File.Exists(nupkgPath));
|
||||
|
||||
var setupPath = Path.Combine(tmpReleaseDir, $"{id}-win-x64-asd123-Setup.exe");
|
||||
var setupPath = Path.Combine(tmpReleaseDir, $"{id}-asd123-Setup.exe");
|
||||
Assert.True(File.Exists(setupPath));
|
||||
|
||||
var releasesPath = Path.Combine(tmpReleaseDir, $"RELEASES-asd123");
|
||||
@@ -89,72 +89,6 @@ public class WindowsPackTests
|
||||
Assert.False(File.Exists(Path.Combine(unzipDir, "lib", "app", Path.GetFileName(pdb))));
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void PackBuildMultipleChannelsSameRid()
|
||||
{
|
||||
Skip.IfNot(VelopackRuntimeInfo.IsWindows);
|
||||
|
||||
using var logger = _output.BuildLoggerFor<WindowsPackTests>();
|
||||
|
||||
using var _1 = Utility.GetTempDirectory(out var tmpOutput);
|
||||
using var _2 = Utility.GetTempDirectory(out var tmpReleaseDir);
|
||||
|
||||
var exe = "testawareapp.exe";
|
||||
var pdb = Path.ChangeExtension(exe, ".pdb");
|
||||
var id = "Test.Squirrel-App";
|
||||
var version = "1.0.0";
|
||||
|
||||
PathHelper.CopyRustAssetTo(exe, tmpOutput);
|
||||
PathHelper.CopyRustAssetTo(pdb, tmpOutput);
|
||||
|
||||
var options = new WindowsPackOptions {
|
||||
EntryExecutableName = exe,
|
||||
ReleaseDir = new DirectoryInfo(tmpReleaseDir),
|
||||
PackId = id,
|
||||
PackVersion = version,
|
||||
TargetRuntime = RID.Parse("win10.0.19043-x64"),
|
||||
Runtimes = "net6",
|
||||
PackAuthors = "author",
|
||||
PackTitle = "Test Squirrel App",
|
||||
PackDirectory = tmpOutput,
|
||||
};
|
||||
|
||||
var runner = new WindowsPackCommandRunner(logger);
|
||||
runner.Run(options).GetAwaiterResult();
|
||||
|
||||
|
||||
var nupkgPath1 = Path.Combine(tmpReleaseDir, $"{id}-{version}-win-x64-full.nupkg");
|
||||
Assert.True(File.Exists(nupkgPath1));
|
||||
|
||||
var setupPath1 = Path.Combine(tmpReleaseDir, $"{id}-win-x64-Setup.exe");
|
||||
Assert.True(File.Exists(setupPath1));
|
||||
|
||||
var releasesPath1 = Path.Combine(tmpReleaseDir, $"RELEASES");
|
||||
Assert.True(File.Exists(releasesPath1));
|
||||
|
||||
var rel1 = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasesPath1, Encoding.UTF8));
|
||||
Assert.Equal(1, rel1.Count());
|
||||
|
||||
options.Channel = "hello";
|
||||
runner.Run(options).GetAwaiterResult();
|
||||
|
||||
var nupkgPath2 = Path.Combine(tmpReleaseDir, $"{id}-{version}-hello-win-x64-full.nupkg");
|
||||
Assert.True(File.Exists(nupkgPath2));
|
||||
|
||||
var setupPath2 = Path.Combine(tmpReleaseDir, $"{id}-win-x64-hello-Setup.exe");
|
||||
Assert.True(File.Exists(setupPath2));
|
||||
|
||||
var releasesPath2 = Path.Combine(tmpReleaseDir, $"RELEASES-hello");
|
||||
Assert.True(File.Exists(releasesPath2));
|
||||
|
||||
rel1 = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasesPath1, Encoding.UTF8));
|
||||
Assert.Equal(1, rel1.Count());
|
||||
|
||||
var rel2 = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasesPath2, Encoding.UTF8));
|
||||
Assert.Equal(1, rel2.Count());
|
||||
}
|
||||
|
||||
|
||||
[SkippableFact]
|
||||
public void PackBuildRefuseSameVersion()
|
||||
{
|
||||
@@ -288,7 +222,7 @@ public class WindowsPackTests
|
||||
var runner = new WindowsPackCommandRunner(logger);
|
||||
runner.Run(options).GetAwaiterResult();
|
||||
|
||||
var setupPath1 = Path.Combine(tmpReleaseDir, $"{id}-win-x64-Setup.exe");
|
||||
var setupPath1 = Path.Combine(tmpReleaseDir, $"{id}-win-Setup.exe");
|
||||
Assert.True(File.Exists(setupPath1));
|
||||
|
||||
RunNoCoverage(setupPath1, new[] { "--nocolor", "--silent", "--installto", tmpInstallDir }, Environment.CurrentDirectory, logger);
|
||||
@@ -355,7 +289,7 @@ public class WindowsPackTests
|
||||
PackTestApp(id, "1.0.0", "version 1 test", releaseDir, logger);
|
||||
|
||||
// install app
|
||||
var setupPath1 = Path.Combine(releaseDir, $"{id}-win-x64-Setup.exe");
|
||||
var setupPath1 = Path.Combine(releaseDir, $"{id}-win-Setup.exe");
|
||||
RunNoCoverage(setupPath1, new string[] { "--nocolor", "--silent", "--installto", installDir },
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.Desktop), logger);
|
||||
|
||||
@@ -363,7 +297,7 @@ public class WindowsPackTests
|
||||
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 fileName = $"{id}-2.0.0-win-full.nupkg";
|
||||
var mvFrom = Path.Combine(releaseDir, fileName);
|
||||
var mvTo = Path.Combine(installDir, "packages", fileName);
|
||||
File.Copy(mvFrom, mvTo);
|
||||
@@ -387,7 +321,7 @@ public class WindowsPackTests
|
||||
PackTestApp(id, "2.0.0", "version 2 test", releaseDir, logger);
|
||||
|
||||
// did a zsdiff get created for our v2 update?
|
||||
var deltaPath = Path.Combine(releaseDir, $"{id}-2.0.0-win-x64-delta.nupkg");
|
||||
var deltaPath = Path.Combine(releaseDir, $"{id}-2.0.0-win-delta.nupkg");
|
||||
Assert.True(File.Exists(deltaPath));
|
||||
using var _2 = Utility.GetTempDirectory(out var extractDir);
|
||||
EasyZip.ExtractZipToDirectory(logger, deltaPath, extractDir);
|
||||
@@ -401,14 +335,14 @@ public class WindowsPackTests
|
||||
// apply delta and check package
|
||||
var output = Path.Combine(releaseDir, "delta.patched");
|
||||
new DeltaPatchCommandRunner(logger).Run(new DeltaPatchOptions {
|
||||
BasePackage = Path.Combine(releaseDir, $"{id}-1.0.0-win-x64-full.nupkg"),
|
||||
BasePackage = Path.Combine(releaseDir, $"{id}-1.0.0-win-full.nupkg"),
|
||||
OutputFile = output,
|
||||
PatchFiles = new[] { new FileInfo(deltaPath) },
|
||||
}).GetAwaiterResult();
|
||||
|
||||
// are the packages the same?
|
||||
Assert.True(File.Exists(output));
|
||||
var v2 = Path.Combine(releaseDir, $"{id}-2.0.0-win-x64-full.nupkg");
|
||||
var v2 = Path.Combine(releaseDir, $"{id}-2.0.0-win-full.nupkg");
|
||||
var f1 = File.ReadAllBytes(output);
|
||||
var f2 = File.ReadAllBytes(v2);
|
||||
Assert.True(new ReadOnlySpan<byte>(f1).SequenceEqual(new ReadOnlySpan<byte>(f2)));
|
||||
@@ -429,7 +363,7 @@ public class WindowsPackTests
|
||||
PackTestApp(id, "1.0.0", "version 1 test", releaseDir, logger);
|
||||
|
||||
// install app
|
||||
var setupPath1 = Path.Combine(releaseDir, $"{id}-win-x64-Setup.exe");
|
||||
var setupPath1 = Path.Combine(releaseDir, $"{id}-win-Setup.exe");
|
||||
RunNoCoverage(setupPath1, new string[] { "--nocolor", "--installto", installDir },
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.Desktop), logger);
|
||||
|
||||
@@ -478,7 +412,7 @@ public class WindowsPackTests
|
||||
PackTestApp(id, "1.0.0", "version 1 test", releaseDir, logger);
|
||||
|
||||
// install app
|
||||
var setupPath1 = Path.Combine(releaseDir, $"{id}-win-x64-Setup.exe");
|
||||
var setupPath1 = Path.Combine(releaseDir, $"{id}-win-Setup.exe");
|
||||
RunNoCoverage(setupPath1, new string[] { "--nocolor", "--silent", "--installto", installDir },
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.Desktop), logger);
|
||||
|
||||
@@ -512,8 +446,8 @@ public class WindowsPackTests
|
||||
PackTestApp(id, "3.0.0", "version 3 test", releaseDir, logger);
|
||||
|
||||
// corrupt v2/v3 full packages as we want to test delta's
|
||||
File.WriteAllText(Path.Combine(releaseDir, $"{id}-2.0.0-win-x64-full.nupkg"), "nope");
|
||||
File.WriteAllText(Path.Combine(releaseDir, $"{id}-3.0.0-win-x64-full.nupkg"), "nope");
|
||||
File.WriteAllText(Path.Combine(releaseDir, $"{id}-2.0.0-win-full.nupkg"), "nope");
|
||||
File.WriteAllText(Path.Combine(releaseDir, $"{id}-3.0.0-win-full.nupkg"), "nope");
|
||||
|
||||
// perform full update, check that we get v3
|
||||
// apply should fail if there's not an update downloaded
|
||||
|
||||
Reference in New Issue
Block a user