mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Sort out test projects
This commit is contained in:
12
Squirrel.sln
12
Squirrel.sln
@@ -32,7 +32,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrel.Packaging.OSX", "s
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrel.Deployment", "src\Squirrel.Deployment\Squirrel.Deployment.csproj", "{D19EA72C-E7AE-4A7B-924A-E7550901A49C}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrel.Deployment", "src\Squirrel.Deployment\Squirrel.Deployment.csproj", "{D19EA72C-E7AE-4A7B-924A-E7550901A49C}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrel.Integration.Tests", "test\Squirrel.Integration.Tests\Squirrel.Integration.Tests.csproj", "{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrel.Packaging.Tests", "test\Squirrel.Packaging.Tests\Squirrel.Packaging.Tests.csproj", "{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -72,10 +72,10 @@ Global
|
|||||||
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D19EA72C-E7AE-4A7B-924A-E7550901A49C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0}.Release|Any CPU.Build.0 = Release|Any CPU
|
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -83,7 +83,7 @@ Global
|
|||||||
GlobalSection(NestedProjects) = preSolution
|
GlobalSection(NestedProjects) = preSolution
|
||||||
{98AEB048-E27D-42F4-9440-505B7F78BAFD} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
|
{98AEB048-E27D-42F4-9440-505B7F78BAFD} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
|
||||||
{519EAB50-47B8-425F-8B20-AB9548F220B4} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
|
{519EAB50-47B8-425F-8B20-AB9548F220B4} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
|
||||||
{1A20C135-05FA-4FBA-BC53-5E6E75E136B0} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
|
{175B06A5-5C09-4DAB-A6AF-C8A2257BD1B6} = {7AC3A776-B582-4B65-9D03-BD52332B5CA3}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {68CA987A-9BAB-4C75-8EEB-4596BA6BBD07}
|
SolutionGuid = {68CA987A-9BAB-4C75-8EEB-4596BA6BBD07}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
|
|||||||
|
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
[assembly: InternalsVisibleTo("Squirrel.Tests, PublicKey=" + SNK.SHA1)]
|
[assembly: InternalsVisibleTo("Squirrel.Tests, PublicKey=" + SNK.SHA1)]
|
||||||
[assembly: InternalsVisibleTo("Squirrel.Integration.Tests, PublicKey=" + SNK.SHA1)]
|
[assembly: InternalsVisibleTo("Squirrel.Packaging.Tests, PublicKey=" + SNK.SHA1)]
|
||||||
[assembly: InternalsVisibleTo("Squirrel, PublicKey=" + SNK.SHA1)]
|
[assembly: InternalsVisibleTo("Squirrel, PublicKey=" + SNK.SHA1)]
|
||||||
[assembly: InternalsVisibleTo("Squirrel.Deployment, PublicKey=" + SNK.SHA1)]
|
[assembly: InternalsVisibleTo("Squirrel.Deployment, PublicKey=" + SNK.SHA1)]
|
||||||
[assembly: InternalsVisibleTo("Squirrel.Packaging, PublicKey=" + SNK.SHA1)]
|
[assembly: InternalsVisibleTo("Squirrel.Packaging, PublicKey=" + SNK.SHA1)]
|
||||||
|
|||||||
@@ -1,29 +1,25 @@
|
|||||||
using Squirrel.CommandLine.Commands;
|
namespace Squirrel.CommandLine.Tests;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Squirrel.CommandLine.Tests
|
public abstract class BaseCommandTests<T> : TempFileTestBase
|
||||||
|
where T : BaseCommand, new()
|
||||||
{
|
{
|
||||||
public abstract class BaseCommandTests<T> : TempFileTestBase
|
public virtual bool ShouldBeNonEmptyReleaseDir => false;
|
||||||
where T : BaseCommand, new()
|
|
||||||
|
[Fact]
|
||||||
|
public void ReleaseDirectory_WithDirectory_ParsesValue()
|
||||||
{
|
{
|
||||||
public virtual bool ShouldBeNonEmptyReleaseDir => false;
|
var releaseDirectory = CreateTempDirectory();
|
||||||
|
|
||||||
[Fact]
|
if (ShouldBeNonEmptyReleaseDir)
|
||||||
public void ReleaseDirectory_WithDirectory_ParsesValue()
|
CreateTempFile(releaseDirectory, "anything");
|
||||||
{
|
|
||||||
var releaseDirectory = CreateTempDirectory();
|
|
||||||
|
|
||||||
if (ShouldBeNonEmptyReleaseDir)
|
BaseCommand command = new T();
|
||||||
CreateTempFile(releaseDirectory, "anything");
|
|
||||||
|
|
||||||
BaseCommand command = new T();
|
var cli = GetRequiredDefaultOptions() + $"--outputDir \"{releaseDirectory.FullName}\"";
|
||||||
|
var parseResult = command.ParseAndApply(cli);
|
||||||
|
|
||||||
var cli = GetRequiredDefaultOptions() + $"--outputDir \"{releaseDirectory.FullName}\"";
|
Assert.Equal(releaseDirectory.FullName, command.ReleaseDirectory);
|
||||||
var parseResult = command.ParseAndApply(cli);
|
|
||||||
|
|
||||||
Assert.Equal(releaseDirectory.FullName, command.ReleaseDirectory);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual string GetRequiredDefaultOptions() => "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual string GetRequiredDefaultOptions() => "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,102 +1,97 @@
|
|||||||
using System.CommandLine.Parsing;
|
namespace Squirrel.CommandLine.Tests.Commands;
|
||||||
using Squirrel.CommandLine.Commands;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Squirrel.CommandLine.Tests.Commands
|
public abstract class GitHubCommandTests<T> : BaseCommandTests<T>
|
||||||
|
where T : GitHubBaseCommand, new()
|
||||||
{
|
{
|
||||||
public abstract class GitHubCommandTests<T> : BaseCommandTests<T>
|
[Fact]
|
||||||
where T : GitHubBaseCommand, new()
|
public void RepoUrl_WithUrl_ParsesValue()
|
||||||
{
|
{
|
||||||
[Fact]
|
GitHubBaseCommand command = new T();
|
||||||
public void RepoUrl_WithUrl_ParsesValue()
|
|
||||||
{
|
|
||||||
GitHubBaseCommand command = new T();
|
|
||||||
|
|
||||||
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"http://clowd.squirrel.com\"");
|
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"http://clowd.squirrel.com\"");
|
||||||
|
|
||||||
Assert.Empty(parseResult.Errors);
|
Assert.Empty(parseResult.Errors);
|
||||||
Assert.Equal("http://clowd.squirrel.com/", command.RepoUrl);
|
Assert.Equal("http://clowd.squirrel.com/", command.RepoUrl);
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RepoUrl_WithNonHttpValue_ShowsError()
|
|
||||||
{
|
|
||||||
GitHubBaseCommand command = new T();
|
|
||||||
|
|
||||||
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"file://clowd.squirrel.com\"");
|
|
||||||
|
|
||||||
Assert.Equal(1, parseResult.Errors.Count);
|
|
||||||
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol);
|
|
||||||
Assert.StartsWith("--repoUrl must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RepoUrl_WithRelativeUrl_ShowsError()
|
|
||||||
{
|
|
||||||
GitHubBaseCommand command = new T();
|
|
||||||
|
|
||||||
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"clowd.squirrel.com\"");
|
|
||||||
|
|
||||||
Assert.Equal(1, parseResult.Errors.Count);
|
|
||||||
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol);
|
|
||||||
Assert.StartsWith("--repoUrl must contain an absolute Uri.", parseResult.Errors[0].Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Token_WithValue_ParsesValue()
|
|
||||||
{
|
|
||||||
GitHubBaseCommand command = new T();
|
|
||||||
|
|
||||||
string cli = GetRequiredDefaultOptions() + $"--token \"abc\"";
|
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
|
||||||
|
|
||||||
Assert.Equal("abc", command.Token);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string GetRequiredDefaultOptions()
|
|
||||||
{
|
|
||||||
return $"--repoUrl \"https://clowd.squirrel.com\" ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GitHubDownloadCommandTests : GitHubCommandTests<GitHubDownloadCommand>
|
[Fact]
|
||||||
|
public void RepoUrl_WithNonHttpValue_ShowsError()
|
||||||
{
|
{
|
||||||
[Fact]
|
GitHubBaseCommand command = new T();
|
||||||
public void Pre_BareOption_SetsFlag()
|
|
||||||
{
|
|
||||||
var command = new GitHubDownloadCommand();
|
|
||||||
|
|
||||||
string cli = GetRequiredDefaultOptions() + "--pre";
|
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"file://clowd.squirrel.com\"");
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
|
||||||
|
|
||||||
Assert.True(command.Pre);
|
Assert.Equal(1, parseResult.Errors.Count);
|
||||||
}
|
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol);
|
||||||
|
Assert.StartsWith("--repoUrl must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GitHubUploadCommandTests : GitHubCommandTests<GitHubUploadCommand>
|
[Fact]
|
||||||
|
public void RepoUrl_WithRelativeUrl_ShowsError()
|
||||||
{
|
{
|
||||||
public override bool ShouldBeNonEmptyReleaseDir => true;
|
GitHubBaseCommand command = new T();
|
||||||
|
|
||||||
[Fact]
|
ParseResult parseResult = command.ParseAndApply($"--repoUrl \"clowd.squirrel.com\"");
|
||||||
public void Publish_BareOption_SetsFlag()
|
|
||||||
{
|
|
||||||
var command = new GitHubUploadCommand();
|
|
||||||
|
|
||||||
string cli = GetRequiredDefaultOptions() + "--publish";
|
Assert.Equal(1, parseResult.Errors.Count);
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
//Assert.Equal(command.RepoUrl, parseResult.Errors[0].SymbolResult?.Symbol);
|
||||||
|
Assert.StartsWith("--repoUrl must contain an absolute Uri.", parseResult.Errors[0].Message);
|
||||||
|
}
|
||||||
|
|
||||||
Assert.True(command.Publish);
|
[Fact]
|
||||||
}
|
public void Token_WithValue_ParsesValue()
|
||||||
|
{
|
||||||
|
GitHubBaseCommand command = new T();
|
||||||
|
|
||||||
[Fact]
|
string cli = GetRequiredDefaultOptions() + $"--token \"abc\"";
|
||||||
public void ReleaseName_WithName_ParsesValue()
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
{
|
|
||||||
var command = new GitHubUploadCommand();
|
|
||||||
|
|
||||||
string cli = GetRequiredDefaultOptions() + $"--releaseName \"my release\"";
|
Assert.Equal("abc", command.Token);
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
}
|
||||||
|
|
||||||
Assert.Equal("my release", command.ReleaseName);
|
protected override string GetRequiredDefaultOptions()
|
||||||
}
|
{
|
||||||
|
return $"--repoUrl \"https://clowd.squirrel.com\" ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GitHubDownloadCommandTests : GitHubCommandTests<GitHubDownloadCommand>
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Pre_BareOption_SetsFlag()
|
||||||
|
{
|
||||||
|
var command = new GitHubDownloadCommand();
|
||||||
|
|
||||||
|
string cli = GetRequiredDefaultOptions() + "--pre";
|
||||||
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
|
|
||||||
|
Assert.True(command.Pre);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GitHubUploadCommandTests : GitHubCommandTests<GitHubUploadCommand>
|
||||||
|
{
|
||||||
|
public override bool ShouldBeNonEmptyReleaseDir => true;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Publish_BareOption_SetsFlag()
|
||||||
|
{
|
||||||
|
var command = new GitHubUploadCommand();
|
||||||
|
|
||||||
|
string cli = GetRequiredDefaultOptions() + "--publish";
|
||||||
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
|
|
||||||
|
Assert.True(command.Publish);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ReleaseName_WithName_ParsesValue()
|
||||||
|
{
|
||||||
|
var command = new GitHubUploadCommand();
|
||||||
|
|
||||||
|
string cli = GetRequiredDefaultOptions() + $"--releaseName \"my release\"";
|
||||||
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
|
|
||||||
|
Assert.Equal("my release", command.ReleaseName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,45 @@
|
|||||||
using System.CommandLine.Parsing;
|
|
||||||
using Squirrel.CommandLine.Commands;
|
namespace Squirrel.CommandLine.Tests.Commands;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Squirrel.CommandLine.Tests.Commands
|
public class HttpDownloadCommandTests : BaseCommandTests<HttpDownloadCommand>
|
||||||
{
|
{
|
||||||
public class HttpDownloadCommandTests : BaseCommandTests<HttpDownloadCommand>
|
[Fact]
|
||||||
|
public void Url_WithUrl_ParsesValue()
|
||||||
{
|
{
|
||||||
[Fact]
|
var command = new HttpDownloadCommand();
|
||||||
public void Url_WithUrl_ParsesValue()
|
|
||||||
{
|
|
||||||
var command = new HttpDownloadCommand();
|
|
||||||
|
|
||||||
ParseResult parseResult = command.ParseAndApply($"--url \"http://clowd.squirrel.com\"");
|
ParseResult parseResult = command.ParseAndApply($"--url \"http://clowd.squirrel.com\"");
|
||||||
|
|
||||||
Assert.Empty(parseResult.Errors);
|
Assert.Empty(parseResult.Errors);
|
||||||
Assert.Equal("http://clowd.squirrel.com/", command.Url);
|
Assert.Equal("http://clowd.squirrel.com/", command.Url);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Url_WithNonHttpValue_ShowsError()
|
public void Url_WithNonHttpValue_ShowsError()
|
||||||
{
|
{
|
||||||
var command = new HttpDownloadCommand();
|
var command = new HttpDownloadCommand();
|
||||||
|
|
||||||
ParseResult parseResult = command.ParseAndApply($"--url \"file://clowd.squirrel.com\"");
|
ParseResult parseResult = command.ParseAndApply($"--url \"file://clowd.squirrel.com\"");
|
||||||
|
|
||||||
Assert.Equal(1, parseResult.Errors.Count);
|
Assert.Equal(1, parseResult.Errors.Count);
|
||||||
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol);
|
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol);
|
||||||
Assert.StartsWith("--url must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
|
Assert.StartsWith("--url must contain a Uri with one of the following schems: http, https.", parseResult.Errors[0].Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Url_WithRelativeUrl_ShowsError()
|
public void Url_WithRelativeUrl_ShowsError()
|
||||||
{
|
{
|
||||||
var command = new HttpDownloadCommand();
|
var command = new HttpDownloadCommand();
|
||||||
|
|
||||||
ParseResult parseResult = command.ParseAndApply($"--url \"clowd.squirrel.com\"");
|
ParseResult parseResult = command.ParseAndApply($"--url \"clowd.squirrel.com\"");
|
||||||
|
|
||||||
Assert.Equal(1, parseResult.Errors.Count);
|
Assert.Equal(1, parseResult.Errors.Count);
|
||||||
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol);
|
//Assert.Equal(command.Url, parseResult.Errors[0].SymbolResult?.Symbol);
|
||||||
Assert.StartsWith("--url must contain an absolute Uri.", parseResult.Errors[0].Message);
|
Assert.StartsWith("--url must contain an absolute Uri.", parseResult.Errors[0].Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string GetRequiredDefaultOptions()
|
protected override string GetRequiredDefaultOptions()
|
||||||
{
|
{
|
||||||
return $"--url \"https://clowd.squirrel.com\" ";
|
return $"--url \"https://clowd.squirrel.com\" ";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,125 +1,118 @@
|
|||||||
using System.CommandLine.Parsing;
|
namespace Squirrel.CommandLine.Tests.Commands;
|
||||||
using Squirrel.CommandLine.Commands;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Squirrel.CommandLine.Tests.Commands
|
public abstract class S3CommandTests<T> : BaseCommandTests<T>
|
||||||
|
where T : S3BaseCommand, new()
|
||||||
{
|
{
|
||||||
public abstract class S3CommandTests<T> : BaseCommandTests<T>
|
[Fact]
|
||||||
where T : S3BaseCommand, new()
|
public void Command_WithRequiredEndpointOptions_ParsesValue()
|
||||||
{
|
{
|
||||||
[Fact]
|
S3BaseCommand command = new T();
|
||||||
public void Command_WithRequiredEndpointOptions_ParsesValue()
|
|
||||||
{
|
|
||||||
S3BaseCommand command = new T();
|
|
||||||
|
|
||||||
string cli = $"--keyId \"some key\" --secret \"shhhh\" --endpoint \"http://endpoint\" --bucket \"a-bucket\"";
|
string cli = $"--keyId \"some key\" --secret \"shhhh\" --endpoint \"http://endpoint\" --bucket \"a-bucket\"";
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
|
|
||||||
Assert.Empty(parseResult.Errors);
|
Assert.Empty(parseResult.Errors);
|
||||||
Assert.Equal("some key", command.KeyId);
|
Assert.Equal("some key", command.KeyId);
|
||||||
Assert.Equal("shhhh", command.Secret);
|
Assert.Equal("shhhh", command.Secret);
|
||||||
Assert.Equal("http://endpoint/", command.Endpoint);
|
Assert.Equal("http://endpoint/", command.Endpoint);
|
||||||
Assert.Equal("a-bucket", command.Bucket);
|
Assert.Equal("a-bucket", command.Bucket);
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Command_WithRequiredRegionOptions_ParsesValue()
|
|
||||||
{
|
|
||||||
S3BaseCommand command = new T();
|
|
||||||
|
|
||||||
string cli = $"--keyId \"some key\" --secret \"shhhh\" --region \"us-west-1\" --bucket \"a-bucket\"";
|
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
|
||||||
|
|
||||||
Assert.Empty(parseResult.Errors);
|
|
||||||
Assert.Equal("some key", command.KeyId);
|
|
||||||
Assert.Equal("shhhh", command.Secret);
|
|
||||||
Assert.Equal("us-west-1", command.Region);
|
|
||||||
Assert.Equal("a-bucket", command.Bucket);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Command_WithoutRegionArgumentValue_ShowsError()
|
|
||||||
{
|
|
||||||
S3BaseCommand command = new T();
|
|
||||||
|
|
||||||
string cli = $"--keyId \"some key\" --secret \"shhhh\" --bucket \"a-bucket\" --region \"\"";
|
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
|
||||||
|
|
||||||
Assert.Equal(1, parseResult.Errors.Count);
|
|
||||||
//Assert.Equal(command.Region, parseResult.Errors[0].SymbolResult?.Symbol);
|
|
||||||
Assert.StartsWith("A region value is required", parseResult.Errors[0].Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Command_WithoutRegionAndEndpoint_ShowsError()
|
|
||||||
{
|
|
||||||
S3BaseCommand command = new T();
|
|
||||||
|
|
||||||
string cli = $"--keyId \"some key\" --secret \"shhhh\" --bucket \"a-bucket\"";
|
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
|
||||||
|
|
||||||
Assert.Equal(1, parseResult.Errors.Count);
|
|
||||||
Assert.Equal(command, parseResult.Errors[0].SymbolResult?.Symbol);
|
|
||||||
Assert.StartsWith("At least one of the following options are required '--region' and '--endpoint'", parseResult.Errors[0].Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Command_WithBothRegionAndEndpoint_ShowsError()
|
|
||||||
{
|
|
||||||
S3BaseCommand command = new T();
|
|
||||||
|
|
||||||
string cli = $"--keyId \"some key\" --secret \"shhhh\" --region \"us-west-1\" --endpoint \"http://endpoint\" --bucket \"a-bucket\"";
|
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
|
||||||
|
|
||||||
Assert.Equal(1, parseResult.Errors.Count);
|
|
||||||
Assert.Equal(command, parseResult.Errors[0].SymbolResult?.Symbol);
|
|
||||||
Assert.StartsWith("Cannot use '--region' and '--endpoint' options together", parseResult.Errors[0].Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void PathPrefix_WithPath_ParsesValue()
|
|
||||||
{
|
|
||||||
S3BaseCommand command = new T();
|
|
||||||
|
|
||||||
string cli = GetRequiredDefaultOptions() + $"--pathPrefix \"sub-folder\"";
|
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
|
||||||
|
|
||||||
Assert.Equal("sub-folder", command.PathPrefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string GetRequiredDefaultOptions()
|
|
||||||
{
|
|
||||||
return $"--keyId \"some key\" --secret \"shhhh\" --endpoint \"http://endpoint\" --bucket \"a-bucket\" ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class S3DownloadCommandTests : S3CommandTests<S3DownloadCommand>
|
[Fact]
|
||||||
{ }
|
public void Command_WithRequiredRegionOptions_ParsesValue()
|
||||||
|
|
||||||
public class S3UploadCommandTests : S3CommandTests<S3UploadCommand>
|
|
||||||
{
|
{
|
||||||
public override bool ShouldBeNonEmptyReleaseDir => true;
|
S3BaseCommand command = new T();
|
||||||
|
|
||||||
[Fact]
|
string cli = $"--keyId \"some key\" --secret \"shhhh\" --region \"us-west-1\" --bucket \"a-bucket\"";
|
||||||
public void Overwrite_BareOption_SetsFlag()
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
{
|
|
||||||
var command = new S3UploadCommand();
|
|
||||||
|
|
||||||
string cli = GetRequiredDefaultOptions() + "--overwrite";
|
Assert.Empty(parseResult.Errors);
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
Assert.Equal("some key", command.KeyId);
|
||||||
|
Assert.Equal("shhhh", command.Secret);
|
||||||
|
Assert.Equal("us-west-1", command.Region);
|
||||||
|
Assert.Equal("a-bucket", command.Bucket);
|
||||||
|
}
|
||||||
|
|
||||||
Assert.True(command.Overwrite);
|
[Fact]
|
||||||
}
|
public void Command_WithoutRegionArgumentValue_ShowsError()
|
||||||
|
{
|
||||||
|
S3BaseCommand command = new T();
|
||||||
|
|
||||||
[Fact]
|
string cli = $"--keyId \"some key\" --secret \"shhhh\" --bucket \"a-bucket\" --region \"\"";
|
||||||
public void KeepMaxReleases_WithNumber_ParsesValue()
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
{
|
|
||||||
var command = new S3UploadCommand();
|
|
||||||
|
|
||||||
string cli = GetRequiredDefaultOptions() + "--keepMaxReleases 42";
|
Assert.Equal(1, parseResult.Errors.Count);
|
||||||
ParseResult parseResult = command.ParseAndApply(cli);
|
//Assert.Equal(command.Region, parseResult.Errors[0].SymbolResult?.Symbol);
|
||||||
|
Assert.StartsWith("A region value is required", parseResult.Errors[0].Message);
|
||||||
|
}
|
||||||
|
|
||||||
Assert.Equal(42, command.KeepMaxReleases);
|
[Fact]
|
||||||
}
|
public void Command_WithoutRegionAndEndpoint_ShowsError()
|
||||||
|
{
|
||||||
|
S3BaseCommand command = new T();
|
||||||
|
|
||||||
|
string cli = $"--keyId \"some key\" --secret \"shhhh\" --bucket \"a-bucket\"";
|
||||||
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
|
|
||||||
|
Assert.Equal(1, parseResult.Errors.Count);
|
||||||
|
Assert.StartsWith("At least one of the following options are required '--region' and '--endpoint'", parseResult.Errors[0].Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Command_WithBothRegionAndEndpoint_ShowsError()
|
||||||
|
{
|
||||||
|
S3BaseCommand command = new T();
|
||||||
|
|
||||||
|
string cli = $"--keyId \"some key\" --secret \"shhhh\" --region \"us-west-1\" --endpoint \"http://endpoint\" --bucket \"a-bucket\"";
|
||||||
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
|
|
||||||
|
Assert.Equal(1, parseResult.Errors.Count);
|
||||||
|
Assert.StartsWith("Cannot use '--region' and '--endpoint' options together", parseResult.Errors[0].Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void PathPrefix_WithPath_ParsesValue()
|
||||||
|
{
|
||||||
|
S3BaseCommand command = new T();
|
||||||
|
|
||||||
|
string cli = GetRequiredDefaultOptions() + $"--pathPrefix \"sub-folder\"";
|
||||||
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
|
|
||||||
|
Assert.Equal("sub-folder", command.PathPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string GetRequiredDefaultOptions()
|
||||||
|
{
|
||||||
|
return $"--keyId \"some key\" --secret \"shhhh\" --endpoint \"http://endpoint\" --bucket \"a-bucket\" ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class S3DownloadCommandTests : S3CommandTests<S3DownloadCommand>
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public class S3UploadCommandTests : S3CommandTests<S3UploadCommand>
|
||||||
|
{
|
||||||
|
public override bool ShouldBeNonEmptyReleaseDir => true;
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Overwrite_BareOption_SetsFlag()
|
||||||
|
{
|
||||||
|
var command = new S3UploadCommand();
|
||||||
|
|
||||||
|
string cli = GetRequiredDefaultOptions() + "--overwrite";
|
||||||
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
|
|
||||||
|
Assert.True(command.Overwrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void KeepMaxReleases_WithNumber_ParsesValue()
|
||||||
|
{
|
||||||
|
var command = new S3UploadCommand();
|
||||||
|
|
||||||
|
string cli = GetRequiredDefaultOptions() + "--keepMaxReleases 42";
|
||||||
|
ParseResult parseResult = command.ParseAndApply(cli);
|
||||||
|
|
||||||
|
Assert.Equal(42, command.KeepMaxReleases);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
10
test/Squirrel.CommandLine.Tests/GlobalUsings.cs
Normal file
10
test/Squirrel.CommandLine.Tests/GlobalUsings.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
global using System;
|
||||||
|
global using System.CommandLine;
|
||||||
|
global using System.Collections.Generic;
|
||||||
|
global using System.IO;
|
||||||
|
global using System.Linq;
|
||||||
|
global using System.Threading.Tasks;
|
||||||
|
global using Microsoft.Extensions.Logging;
|
||||||
|
global using Xunit;
|
||||||
|
global using Xunit.Abstractions;
|
||||||
|
global using Squirrel.Csq.Commands;
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Squirrel.CommandLine\Squirrel.CommandLine.csproj" />
|
<ProjectReference Include="..\..\src\Squirrel.Csq\Squirrel.Csq.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,100 +1,98 @@
|
|||||||
using Xunit.Sdk;
|
using Xunit.Sdk;
|
||||||
|
|
||||||
namespace Squirrel.CommandLine.Tests
|
namespace Squirrel.CommandLine.Tests;
|
||||||
|
|
||||||
|
public abstract class TempFileTestBase : IDisposable
|
||||||
{
|
{
|
||||||
|
private readonly Lazy<DirectoryInfo> _WorkingDirectory = new(() => {
|
||||||
|
DirectoryInfo working = new(
|
||||||
|
Path.Combine(Path.GetTempPath(),
|
||||||
|
typeof(TempFileTestBase).Assembly.GetName().Name!,
|
||||||
|
Path.GetRandomFileName()));
|
||||||
|
|
||||||
public abstract class TempFileTestBase : IDisposable
|
if (working.Exists) {
|
||||||
|
working.Delete(recursive: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
working.Create();
|
||||||
|
return working;
|
||||||
|
}, LazyThreadSafetyMode.ExecutionAndPublication);
|
||||||
|
|
||||||
|
private readonly List<FileInfo> _TempFiles = new();
|
||||||
|
private readonly List<DirectoryInfo> _TempDirectories = new();
|
||||||
|
protected DirectoryInfo TempDirectory => _WorkingDirectory.Value;
|
||||||
|
private bool _Disposed;
|
||||||
|
|
||||||
|
public FileInfo CreateTempFile(DirectoryInfo? directory = null, string? name = null)
|
||||||
{
|
{
|
||||||
private readonly Lazy<DirectoryInfo> _WorkingDirectory = new(() => {
|
var tempFile = new FileInfo(GetPath(directory, name));
|
||||||
DirectoryInfo working = new(
|
tempFile.Create().Close();
|
||||||
Path.Combine(Path.GetTempPath(),
|
_TempFiles.Add(tempFile);
|
||||||
typeof(TempFileTestBase).Assembly.GetName().Name!,
|
return tempFile;
|
||||||
Path.GetRandomFileName()));
|
}
|
||||||
|
|
||||||
if (working.Exists) {
|
public DirectoryInfo CreateTempDirectory(DirectoryInfo? parent = null, string? name = null)
|
||||||
working.Delete(recursive: true);
|
{
|
||||||
}
|
var tempDir = new DirectoryInfo(GetPath(parent, name));
|
||||||
|
tempDir.Create();
|
||||||
|
_TempDirectories.Add(tempDir);
|
||||||
|
return tempDir;
|
||||||
|
}
|
||||||
|
|
||||||
working.Create();
|
private string GetPath(DirectoryInfo? parentDirectory, string? name)
|
||||||
return working;
|
{
|
||||||
}, LazyThreadSafetyMode.ExecutionAndPublication);
|
var directory = parentDirectory ?? _WorkingDirectory.Value;
|
||||||
|
var fileName = name ?? Path.GetRandomFileName();
|
||||||
|
return Path.Combine(directory.FullName, fileName);
|
||||||
|
}
|
||||||
|
|
||||||
private readonly List<FileInfo> _TempFiles = new();
|
protected virtual void Dispose(bool disposing)
|
||||||
private readonly List<DirectoryInfo> _TempDirectories = new();
|
{
|
||||||
protected DirectoryInfo TempDirectory => _WorkingDirectory.Value;
|
if (_Disposed || !disposing) {
|
||||||
private bool _Disposed;
|
return;
|
||||||
|
|
||||||
public FileInfo CreateTempFile(DirectoryInfo? directory = null, string? name = null)
|
|
||||||
{
|
|
||||||
var tempFile = new FileInfo(GetPath(directory, name));
|
|
||||||
tempFile.Create().Close();
|
|
||||||
_TempFiles.Add(tempFile);
|
|
||||||
return tempFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DirectoryInfo CreateTempDirectory(DirectoryInfo? parent = null, string? name = null)
|
_Disposed = true;
|
||||||
{
|
|
||||||
var tempDir = new DirectoryInfo(GetPath(parent, name));
|
|
||||||
tempDir.Create();
|
|
||||||
_TempDirectories.Add(tempDir);
|
|
||||||
return tempDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetPath(DirectoryInfo? parentDirectory, string? name)
|
ExceptionAggregator aggregator = new();
|
||||||
{
|
|
||||||
var directory = parentDirectory ?? _WorkingDirectory.Value;
|
|
||||||
var fileName = name ?? Path.GetRandomFileName();
|
|
||||||
return Path.Combine(directory.FullName, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
var items = _TempFiles
|
||||||
{
|
.Cast<FileSystemInfo>()
|
||||||
if (_Disposed || !disposing) {
|
.Concat(_TempDirectories)
|
||||||
return;
|
.Concat(_WorkingDirectory.IsValueCreated ? new[] { _WorkingDirectory.Value } : Enumerable.Empty<DirectoryInfo>());
|
||||||
}
|
|
||||||
|
|
||||||
_Disposed = true;
|
foreach (var fsi in items) {
|
||||||
|
fsi.Refresh();
|
||||||
|
if (!fsi.Exists) return;
|
||||||
|
|
||||||
ExceptionAggregator aggregator = new();
|
Action? action = fsi switch {
|
||||||
|
FileInfo file => () => file.Delete(),
|
||||||
|
DirectoryInfo dir => () => dir.Delete(recursive: true),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
|
||||||
var items = _TempFiles
|
if (action is null) return;
|
||||||
.Cast<FileSystemInfo>()
|
|
||||||
.Concat(_TempDirectories)
|
|
||||||
.Concat(_WorkingDirectory.IsValueCreated ? new[] { _WorkingDirectory.Value } : Enumerable.Empty<DirectoryInfo>());
|
|
||||||
|
|
||||||
foreach (var fsi in items) {
|
aggregator.Run(() => {
|
||||||
fsi.Refresh();
|
for (int i = 0; i < 100; i++) {
|
||||||
if (!fsi.Exists) return;
|
try {
|
||||||
|
action();
|
||||||
Action? action = fsi switch {
|
break;
|
||||||
FileInfo file => () => file.Delete(),
|
} catch {
|
||||||
DirectoryInfo dir => () => dir.Delete(recursive: true),
|
Thread.Sleep(TimeSpan.FromMilliseconds(10));
|
||||||
_ => null,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (action is null) return;
|
|
||||||
|
|
||||||
aggregator.Run(() => {
|
|
||||||
for (int i = 0; i < 100; i++) {
|
|
||||||
try {
|
|
||||||
action();
|
|
||||||
break;
|
|
||||||
} catch {
|
|
||||||
Thread.Sleep(TimeSpan.FromMilliseconds(10));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
if (aggregator.HasExceptions) {
|
|
||||||
throw aggregator.ToException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
if (aggregator.HasExceptions) {
|
||||||
{
|
throw aggregator.ToException();
|
||||||
Dispose(disposing: true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(disposing: true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Squirrel.CommandLine.Tests
|
namespace Squirrel.CommandLine.Tests;
|
||||||
|
|
||||||
|
public class WindowsOnlyFactAttribute : FactAttribute
|
||||||
{
|
{
|
||||||
public class WindowsOnlyFactAttribute : FactAttribute
|
public WindowsOnlyFactAttribute()
|
||||||
{
|
{
|
||||||
public WindowsOnlyFactAttribute()
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
||||||
{
|
Skip = "Only run on Windows";
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
|
||||||
Skip = "Only run on Windows";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Squirrel.CommandLine.Tests
|
namespace Squirrel.CommandLine.Tests;
|
||||||
|
|
||||||
|
public class WindowsOnlyTheoryAttribute : TheoryAttribute
|
||||||
{
|
{
|
||||||
public class WindowsOnlyTheoryAttribute : TheoryAttribute
|
public WindowsOnlyTheoryAttribute()
|
||||||
{
|
{
|
||||||
public WindowsOnlyTheoryAttribute()
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
||||||
{
|
Skip = "Only run on Windows";
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) {
|
|
||||||
Skip = "Only run on Windows";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
347
test/Squirrel.Packaging.Tests/DeltaPackageTests.cs
Normal file
347
test/Squirrel.Packaging.Tests/DeltaPackageTests.cs
Normal file
@@ -0,0 +1,347 @@
|
|||||||
|
//using System;
|
||||||
|
//using System.Collections.Generic;
|
||||||
|
//using System.IO;
|
||||||
|
//using System.Linq;
|
||||||
|
//using System.Threading.Tasks;
|
||||||
|
//using Squirrel.NuGet;
|
||||||
|
//using Squirrel;
|
||||||
|
//using Squirrel.SimpleSplat;
|
||||||
|
//using Squirrel.Tests.TestHelpers;
|
||||||
|
//using Xunit;
|
||||||
|
//using Xunit.Abstractions;
|
||||||
|
//using NuGet.Versioning;
|
||||||
|
//using Squirrel.CommandLine;
|
||||||
|
|
||||||
|
//namespace Squirrel.Tests
|
||||||
|
//{
|
||||||
|
// public class ApplyDeltaPackageTests : TestLoggingBase
|
||||||
|
// {
|
||||||
|
// public ApplyDeltaPackageTests(ITestOutputHelper log) : base(log)
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void ApplyDeltaPackageSmokeTest()
|
||||||
|
// {
|
||||||
|
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0-full.nupkg");
|
||||||
|
// var deltaPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-delta.nupkg");
|
||||||
|
// var expectedPackageFile = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-full.nupkg");
|
||||||
|
// var outFile = Path.GetTempFileName() + ".nupkg";
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// var deltaBuilder = new DeltaPackage();
|
||||||
|
// deltaBuilder.ApplyDeltaPackage(basePackage, deltaPackage, outFile);
|
||||||
|
|
||||||
|
// var result = new ZipPackage(outFile);
|
||||||
|
// var expected = new ZipPackage(expectedPackageFile);
|
||||||
|
|
||||||
|
// result.Id.ShouldEqual(expected.Id);
|
||||||
|
// result.Version.ShouldEqual(expected.Version);
|
||||||
|
|
||||||
|
// this.Log().Info("Expected file list:");
|
||||||
|
// var expectedList = expected.Files.Select(x => x.Path).OrderBy(x => x).ToList();
|
||||||
|
// expectedList.ForEach(x => this.Log().Info(x));
|
||||||
|
|
||||||
|
// this.Log().Info("Actual file list:");
|
||||||
|
// var actualList = result.Files.Select(x => x.Path).OrderBy(x => x).ToList();
|
||||||
|
// actualList.ForEach(x => this.Log().Info(x));
|
||||||
|
|
||||||
|
// Enumerable.Zip(expectedList, actualList, (e, a) => e == a)
|
||||||
|
// .All(x => x != false)
|
||||||
|
// .ShouldBeTrue();
|
||||||
|
// } finally {
|
||||||
|
// if (File.Exists(outFile)) {
|
||||||
|
// File.Delete(outFile);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void ApplyDeltaWithBothBsdiffAndNormalDiffDoesntFail()
|
||||||
|
// {
|
||||||
|
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.1.8-full.nupkg");
|
||||||
|
// var deltaPackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.2.0-delta.nupkg");
|
||||||
|
// var outFile = Path.GetTempFileName() + ".nupkg";
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// var deltaBuilder = new DeltaPackage();
|
||||||
|
// deltaBuilder.ApplyDeltaPackage(basePackage, deltaPackage, outFile);
|
||||||
|
|
||||||
|
// var result = new ZipPackage(outFile);
|
||||||
|
|
||||||
|
// result.Id.ShouldEqual("slack");
|
||||||
|
// result.Version.ShouldEqual(SemanticVersion.Parse("1.2.0"));
|
||||||
|
// } finally {
|
||||||
|
// if (File.Exists(outFile)) {
|
||||||
|
// File.Delete(outFile);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void ApplyMultipleDeltasFast()
|
||||||
|
// {
|
||||||
|
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.287-full.nupkg");
|
||||||
|
// var deltaPackage1 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.288-delta.nupkg");
|
||||||
|
// var deltaPackage2 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.291-delta.nupkg");
|
||||||
|
// var deltaPackage3 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.292-delta.nupkg");
|
||||||
|
|
||||||
|
// using var t1 = Utility.GetTempDirectory(out var appDir);
|
||||||
|
// using var t2 = Utility.GetTempDirectory(out var updateDir);
|
||||||
|
|
||||||
|
// using var um = UpdateManagerTestImpl.FromLocalPackageTempDir(updateDir, "theApp", appDir);
|
||||||
|
// var pkgDir = um.Config.PackagesDir;
|
||||||
|
|
||||||
|
// File.Copy(basePackage, Path.Combine(pkgDir, Path.GetFileName(basePackage)));
|
||||||
|
// File.Copy(deltaPackage1, Path.Combine(pkgDir, Path.GetFileName(deltaPackage1)));
|
||||||
|
// File.Copy(deltaPackage2, Path.Combine(pkgDir, Path.GetFileName(deltaPackage2)));
|
||||||
|
// File.Copy(deltaPackage3, Path.Combine(pkgDir, Path.GetFileName(deltaPackage3)));
|
||||||
|
|
||||||
|
// var baseEntry = ReleaseEntry.GenerateFromFile(basePackage);
|
||||||
|
|
||||||
|
// var toApply = new [] {
|
||||||
|
// ReleaseEntry.GenerateFromFile(deltaPackage1),
|
||||||
|
// ReleaseEntry.GenerateFromFile(deltaPackage2),
|
||||||
|
// ReleaseEntry.GenerateFromFile(deltaPackage3),
|
||||||
|
// };
|
||||||
|
|
||||||
|
// List<int> progress = new List<int>();
|
||||||
|
|
||||||
|
// var newEntry = um.createFullPackagesFromDeltas(toApply, baseEntry, progress.Add);
|
||||||
|
|
||||||
|
// var outFile = Path.Combine(pkgDir, newEntry.Filename);
|
||||||
|
// var result = new ZipPackage(outFile);
|
||||||
|
// result.Id.ShouldEqual("Clowd");
|
||||||
|
// result.Version.ShouldEqual(SemanticVersion.Parse("3.4.292"));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact(Skip = "Rewrite this test, the original uses too many heavyweight fixtures")]
|
||||||
|
// public void ApplyMultipleDeltaPackagesGeneratesCorrectHash()
|
||||||
|
// {
|
||||||
|
// Assert.Fail("Rewrite this test, the original uses too many heavyweight fixtures");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public class CreateDeltaPackageTests : IEnableLogger
|
||||||
|
// {
|
||||||
|
// [Fact]
|
||||||
|
// public void CreateDeltaPackageIntegrationTest()
|
||||||
|
// {
|
||||||
|
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||||
|
// var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||||
|
|
||||||
|
// var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||||
|
// var fixture = new ReleasePackageBuilder(newPackage);
|
||||||
|
|
||||||
|
// var tempFiles = Enumerable.Range(0, 3)
|
||||||
|
// .Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||||
|
// .ToArray();
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||||
|
// fixture.CreateReleasePackage(tempFiles[1]);
|
||||||
|
|
||||||
|
// (new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||||
|
// (new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||||
|
|
||||||
|
// var deltaBuilder = new DeltaPackageBuilder();
|
||||||
|
// deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||||
|
|
||||||
|
// var fullPkg = new ZipPackage(tempFiles[1]);
|
||||||
|
// var deltaPkg = new ZipPackage(tempFiles[2]);
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // Package Checks
|
||||||
|
// //
|
||||||
|
|
||||||
|
// fullPkg.Id.ShouldEqual(deltaPkg.Id);
|
||||||
|
// fullPkg.Version.CompareTo(deltaPkg.Version).ShouldEqual(0);
|
||||||
|
|
||||||
|
// // Delta packages should be smaller than the original!
|
||||||
|
// var fileInfos = tempFiles.Select(x => new FileInfo(x)).ToArray();
|
||||||
|
// this.Log().Info("Base Size: {0}, Current Size: {1}, Delta Size: {2}",
|
||||||
|
// fileInfos[0].Length, fileInfos[1].Length, fileInfos[2].Length);
|
||||||
|
|
||||||
|
// (fileInfos[2].Length - fileInfos[1].Length).ShouldBeLessThan(0);
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // File Checks
|
||||||
|
// ///
|
||||||
|
|
||||||
|
// var deltaPkgFiles = deltaPkg.Files.ToList();
|
||||||
|
// deltaPkgFiles.Count.ShouldBeGreaterThan(0);
|
||||||
|
|
||||||
|
// this.Log().Info("Files in delta package:");
|
||||||
|
// deltaPkgFiles.ForEach(x => this.Log().Info(x.Path));
|
||||||
|
|
||||||
|
// var newFilesAdded = new[] {
|
||||||
|
// "Newtonsoft.Json.dll",
|
||||||
|
// //"Refit.dll",
|
||||||
|
// //"Refit-Portable.dll",
|
||||||
|
// //"Castle.Core.dll",
|
||||||
|
// }.Select(x => x.ToLowerInvariant());
|
||||||
|
|
||||||
|
// // vNext adds a dependency on Refit
|
||||||
|
// newFilesAdded
|
||||||
|
// .All(x => deltaPkgFiles.Any(y => y.Path.ToLowerInvariant().Contains(x)))
|
||||||
|
// .ShouldBeTrue();
|
||||||
|
|
||||||
|
// // All the other files should be diffs and shasums
|
||||||
|
// deltaPkgFiles
|
||||||
|
// .Where(x => !newFilesAdded.Any(y => x.Path.ToLowerInvariant().Contains(y)))
|
||||||
|
// .All(x => x.Path.ToLowerInvariant().EndsWith("bsdiff") || x.Path.ToLowerInvariant().EndsWith("shasum"))
|
||||||
|
// .ShouldBeTrue();
|
||||||
|
|
||||||
|
// // Every .diff file should have a shasum file
|
||||||
|
// deltaPkg.Files.Any(x => x.Path.ToLowerInvariant().EndsWith(".bsdiff")).ShouldBeTrue();
|
||||||
|
// deltaPkg.Files
|
||||||
|
// .Where(x => x.Path.ToLowerInvariant().EndsWith(".bsdiff"))
|
||||||
|
// .ForEach(x => {
|
||||||
|
// var lookingFor = x.Path.Replace(".bsdiff", ".shasum");
|
||||||
|
// this.Log().Info("Looking for corresponding shasum file: {0}", lookingFor);
|
||||||
|
// deltaPkg.Files.Any(y => y.Path == lookingFor).ShouldBeTrue();
|
||||||
|
// });
|
||||||
|
// } finally {
|
||||||
|
// tempFiles.ForEach(File.Delete);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void WhenBasePackageIsNewerThanNewPackageThrowException()
|
||||||
|
// {
|
||||||
|
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||||
|
// var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||||
|
|
||||||
|
// var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||||
|
// var fixture = new ReleasePackageBuilder(newPackage);
|
||||||
|
|
||||||
|
// var tempFiles = Enumerable.Range(0, 3)
|
||||||
|
// .Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||||
|
// .ToArray();
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||||
|
// fixture.CreateReleasePackage(tempFiles[1]);
|
||||||
|
|
||||||
|
// (new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||||
|
// (new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||||
|
|
||||||
|
// Assert.Throws<InvalidOperationException>(() => {
|
||||||
|
// var deltaBuilder = new DeltaPackageBuilder();
|
||||||
|
// deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||||
|
// });
|
||||||
|
// } finally {
|
||||||
|
// tempFiles.ForEach(File.Delete);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void WhenBasePackageReleaseIsNullThrowsException()
|
||||||
|
// {
|
||||||
|
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0.nupkg");
|
||||||
|
// var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nupkg");
|
||||||
|
|
||||||
|
// var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
|
||||||
|
// (new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
|
||||||
|
|
||||||
|
// var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||||
|
// var fixture = new ReleasePackageBuilder(newPackage);
|
||||||
|
|
||||||
|
// var tempFile = Path.GetTempPath() + Guid.NewGuid() + ".nupkg";
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// Assert.Throws<ArgumentException>(() => {
|
||||||
|
// var deltaBuilder = new DeltaPackageBuilder();
|
||||||
|
// deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFile);
|
||||||
|
// });
|
||||||
|
// } finally {
|
||||||
|
// File.Delete(tempFile);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void WhenBasePackageDoesNotExistThrowException()
|
||||||
|
// {
|
||||||
|
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||||
|
// var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||||
|
|
||||||
|
// var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||||
|
// var fixture = new ReleasePackageBuilder(newPackage);
|
||||||
|
|
||||||
|
// var tempFiles = Enumerable.Range(0, 3)
|
||||||
|
// .Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||||
|
// .ToArray();
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||||
|
// fixture.CreateReleasePackage(tempFiles[1]);
|
||||||
|
|
||||||
|
// (new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||||
|
// (new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||||
|
|
||||||
|
// // NOW WATCH AS THE FILE DISAPPEARS
|
||||||
|
// File.Delete(baseFixture.ReleasePackageFile);
|
||||||
|
|
||||||
|
// Assert.Throws<FileNotFoundException>(() => {
|
||||||
|
// var deltaBuilder = new DeltaPackageBuilder();
|
||||||
|
// deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||||
|
// });
|
||||||
|
// } finally {
|
||||||
|
// tempFiles.ForEach(File.Delete);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void WhenNewPackageDoesNotExistThrowException()
|
||||||
|
// {
|
||||||
|
// var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||||
|
// var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
||||||
|
|
||||||
|
// var baseFixture = new ReleasePackageBuilder(basePackage);
|
||||||
|
// var fixture = new ReleasePackageBuilder(newPackage);
|
||||||
|
|
||||||
|
// var tempFiles = Enumerable.Range(0, 3)
|
||||||
|
// .Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
||||||
|
// .ToArray();
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// baseFixture.CreateReleasePackage(tempFiles[0]);
|
||||||
|
// fixture.CreateReleasePackage(tempFiles[1]);
|
||||||
|
|
||||||
|
// (new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||||
|
// (new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
||||||
|
|
||||||
|
// // NOW WATCH AS THE FILE DISAPPEARS
|
||||||
|
// File.Delete(fixture.ReleasePackageFile);
|
||||||
|
|
||||||
|
// Assert.Throws<FileNotFoundException>(() => {
|
||||||
|
// var deltaBuilder = new DeltaPackageBuilder();
|
||||||
|
// deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
||||||
|
// });
|
||||||
|
// } finally {
|
||||||
|
// tempFiles.ForEach(File.Delete);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void HandleBsDiffWithoutExtraData()
|
||||||
|
// {
|
||||||
|
// var baseFileData = new byte[] { 1, 1, 1, 1 };
|
||||||
|
// var newFileData = new byte[] { 2, 1, 1, 1 };
|
||||||
|
|
||||||
|
// byte[] patchData;
|
||||||
|
|
||||||
|
// using (var patchOut = new MemoryStream()) {
|
||||||
|
// Bsdiff.BinaryPatchUtility.Create(baseFileData, newFileData, patchOut);
|
||||||
|
// patchData = patchOut.ToArray();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// using (var toPatch = new MemoryStream(baseFileData))
|
||||||
|
// using (var patched = new MemoryStream()) {
|
||||||
|
// Bsdiff.BinaryPatchUtility.Apply(toPatch, () => new MemoryStream(patchData), patched);
|
||||||
|
|
||||||
|
// Assert.Equal(newFileData, patched.ToArray());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
@@ -4,9 +4,9 @@ using Squirrel.Packaging;
|
|||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using Xunit.Sdk;
|
using Xunit.Sdk;
|
||||||
|
|
||||||
[assembly: Xunit.TestFramework("Squirrel.Integration.Tests.TestsInit", "Squirrel.Integration.Tests")]
|
[assembly: Xunit.TestFramework("Squirrel.Packaging.Tests.TestsInit", "Squirrel.Packaging.Tests")]
|
||||||
|
|
||||||
namespace Squirrel.Integration.Tests
|
namespace Squirrel.Packaging.Tests
|
||||||
{
|
{
|
||||||
public class TestsInit : XunitTestFramework
|
public class TestsInit : XunitTestFramework
|
||||||
{
|
{
|
||||||
178
test/Squirrel.Packaging.Tests/ReleasePackageTests.cs
Normal file
178
test/Squirrel.Packaging.Tests/ReleasePackageTests.cs
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
//using System.Runtime.Versioning;
|
||||||
|
//using Squirrel.MarkdownSharp;
|
||||||
|
//using Squirrel;
|
||||||
|
//using Squirrel.Tests.TestHelpers;
|
||||||
|
//using System;
|
||||||
|
//using System.Collections.Generic;
|
||||||
|
//using System.IO;
|
||||||
|
//using System.Linq;
|
||||||
|
//using System.Reflection;
|
||||||
|
//using System.Xml.Linq;
|
||||||
|
//using Squirrel.SimpleSplat;
|
||||||
|
//using Xunit;
|
||||||
|
//using Squirrel.NuGet;
|
||||||
|
//using Xunit.Abstractions;
|
||||||
|
//using NuGet.Versioning;
|
||||||
|
//using Squirrel.CommandLine;
|
||||||
|
|
||||||
|
//namespace Squirrel.Tests
|
||||||
|
//{
|
||||||
|
// public class CreateReleasePackageTests : TestLoggingBase
|
||||||
|
// {
|
||||||
|
// public CreateReleasePackageTests(ITestOutputHelper log) : base(log)
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Theory]
|
||||||
|
// [InlineData("1.2.3")]
|
||||||
|
// [InlineData("1.2.3-alpha13")]
|
||||||
|
// [InlineData("1.2.3-alpha135")]
|
||||||
|
// [InlineData("0.0.1")]
|
||||||
|
// [InlineData("1.299656.3-alpha")]
|
||||||
|
// public void SemanticVersionParsesValidVersion(string ver)
|
||||||
|
// {
|
||||||
|
// NugetUtil.ThrowIfVersionNotSemverCompliant(ver);
|
||||||
|
// Assert.True(SemanticVersion.TryParse(ver, out var _));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Theory]
|
||||||
|
// [InlineData("")]
|
||||||
|
// [InlineData("1")]
|
||||||
|
// [InlineData("0")]
|
||||||
|
// [InlineData("1.2.3.4")]
|
||||||
|
// [InlineData("1.2.3.4-alpha")]
|
||||||
|
// [InlineData("0.0.0.0")]
|
||||||
|
// [InlineData("0.0.0")]
|
||||||
|
// [InlineData("0.0")]
|
||||||
|
// [InlineData("0.0.0-alpha")]
|
||||||
|
// public void SemanticVersionThrowsInvalidVersion(string ver)
|
||||||
|
// {
|
||||||
|
// Assert.ThrowsAny<Exception>(() => NugetUtil.ThrowIfVersionNotSemverCompliant(ver));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void ReleasePackageIntegrationTest()
|
||||||
|
// {
|
||||||
|
// var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
||||||
|
// var outputPackage = Path.GetTempFileName() + ".nupkg";
|
||||||
|
|
||||||
|
// var fixture = new ReleasePackageBuilder(inputPackage);
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// fixture.CreateReleasePackage(outputPackage);
|
||||||
|
|
||||||
|
// this.Log().Info("Resulting package is at {0}", outputPackage);
|
||||||
|
// var pkg = new ZipPackage(outputPackage);
|
||||||
|
|
||||||
|
// int refs = pkg.FrameworkAssemblies.Count();
|
||||||
|
// this.Log().Info("Found {0} refs", refs);
|
||||||
|
// refs.ShouldEqual(0);
|
||||||
|
|
||||||
|
// this.Log().Info("Files in release package:");
|
||||||
|
|
||||||
|
// List<ZipPackageFile> files = pkg.Files.ToList();
|
||||||
|
// files.ForEach(x => this.Log().Info(x.Path));
|
||||||
|
|
||||||
|
// List<string> nonDesktopPaths = new[] { "sl", "winrt", "netcore", "win8", "windows8", "MonoAndroid", "MonoTouch", "MonoMac", "wp", }
|
||||||
|
// .Select(x => @"lib\" + x)
|
||||||
|
// .ToList();
|
||||||
|
|
||||||
|
// files.Any(x => nonDesktopPaths.Any(y => x.Path.ToLowerInvariant().Contains(y.ToLowerInvariant()))).ShouldBeFalse();
|
||||||
|
// files.Any(x => x.Path.ToLowerInvariant().EndsWith(@".xml")).ShouldBeFalse();
|
||||||
|
// } finally {
|
||||||
|
// File.Delete(outputPackage);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void CanLoadPackageWhichHasNoDependencies()
|
||||||
|
// {
|
||||||
|
// var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.NoDependencies.1.0.0.0.nupkg");
|
||||||
|
// var outputPackage = Path.GetTempFileName() + ".nupkg";
|
||||||
|
// var fixture = new ReleasePackageBuilder(inputPackage);
|
||||||
|
// try {
|
||||||
|
// fixture.CreateReleasePackage(outputPackage);
|
||||||
|
// } finally {
|
||||||
|
// File.Delete(outputPackage);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void ThrowsIfLoadsPackageWithDependencies()
|
||||||
|
// {
|
||||||
|
// var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectDependsOnJsonDotNet.1.0.nupkg");
|
||||||
|
// var outputPackage = Path.GetTempFileName() + ".nupkg";
|
||||||
|
// var fixture = new ReleasePackageBuilder(inputPackage);
|
||||||
|
// try {
|
||||||
|
// Assert.Throws<InvalidOperationException>(() => fixture.CreateReleasePackage(outputPackage));
|
||||||
|
// } finally {
|
||||||
|
// if (File.Exists(outputPackage))
|
||||||
|
// File.Delete(outputPackage);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void SpecFileMarkdownRenderingTest()
|
||||||
|
// {
|
||||||
|
// var dontcare = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nupkg");
|
||||||
|
// var inputSpec = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nuspec");
|
||||||
|
// var fixture = new ReleasePackageBuilder(dontcare);
|
||||||
|
|
||||||
|
// var targetFile = Path.GetTempFileName();
|
||||||
|
// File.Copy(inputSpec, targetFile, true);
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// var processor = new Func<string, string>(input =>
|
||||||
|
// (new Markdown()).Transform(input));
|
||||||
|
|
||||||
|
// // NB: For No Reason At All, renderReleaseNotesMarkdown is
|
||||||
|
// // invulnerable to ExposedObject. Whyyyyyyyyy
|
||||||
|
// var renderMinfo = fixture.GetType().GetMethod("renderReleaseNotesMarkdown",
|
||||||
|
// BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
// renderMinfo.Invoke(fixture, new object[] { targetFile, processor });
|
||||||
|
|
||||||
|
// var mani = NuspecManifest.ParseFromFile(targetFile);
|
||||||
|
// this.Log().Info("HTML Text:\n{0}", mani.ReleaseNotesHtml);
|
||||||
|
|
||||||
|
// mani.ReleaseNotes.Contains("## Release Notes").ShouldBeTrue();
|
||||||
|
// mani.ReleaseNotesHtml.Contains("## Release Notes").ShouldBeFalse();
|
||||||
|
// mani.ReleaseNotesHtml.Contains("<h2>Release Notes").ShouldBeTrue();
|
||||||
|
// } finally {
|
||||||
|
// File.Delete(targetFile);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void ContentFilesAreIncludedInCreatedPackage()
|
||||||
|
// {
|
||||||
|
// var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectWithContent.1.0.0.0-beta.nupkg");
|
||||||
|
// var outputPackage = Path.GetTempFileName() + ".zip";
|
||||||
|
// var fixture = new ReleasePackageBuilder(inputPackage);
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// fixture.CreateReleasePackage(outputPackage);
|
||||||
|
|
||||||
|
// this.Log().Info("Resulting package is at {0}", outputPackage);
|
||||||
|
// var pkg = new ZipPackage(outputPackage);
|
||||||
|
|
||||||
|
// int refs = pkg.FrameworkAssemblies.Count();
|
||||||
|
// this.Log().Info("Found {0} refs", refs);
|
||||||
|
// refs.ShouldEqual(0);
|
||||||
|
|
||||||
|
// this.Log().Info("Files in release package:");
|
||||||
|
|
||||||
|
// var contentFiles = pkg.Files.Where(f => f.IsContentFile()).ToArray();
|
||||||
|
// Assert.Equal(2, contentFiles.Count());
|
||||||
|
|
||||||
|
// var contentFilePaths = contentFiles.Select(f => f.EffectivePath);
|
||||||
|
|
||||||
|
// Assert.Contains("some-words.txt", contentFilePaths);
|
||||||
|
// Assert.Contains("dir\\item-in-subdirectory.txt", contentFilePaths);
|
||||||
|
|
||||||
|
// Assert.Equal(1, pkg.Files.Where(f => f.IsLibFile()).Count());
|
||||||
|
// } finally {
|
||||||
|
// File.Delete(outputPackage);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
@@ -5,7 +5,7 @@ using Squirrel.Compression;
|
|||||||
using Squirrel.Packaging;
|
using Squirrel.Packaging;
|
||||||
using Squirrel.Packaging.Windows.Commands;
|
using Squirrel.Packaging.Windows.Commands;
|
||||||
|
|
||||||
namespace Squirrel.Integration.Tests;
|
namespace Squirrel.Packaging.Tests;
|
||||||
|
|
||||||
public class WindowsPackTests
|
public class WindowsPackTests
|
||||||
{
|
{
|
||||||
@@ -1,527 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using NuGet.Versioning;
|
|
||||||
using Squirrel.NuGet;
|
|
||||||
using Squirrel.Tests.TestHelpers;
|
|
||||||
using Xunit;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace Squirrel.Tests
|
|
||||||
{
|
|
||||||
public class ApplyReleasesTests : TestLoggingBase
|
|
||||||
{
|
|
||||||
public ApplyReleasesTests(ITestOutputHelper log) : base(log)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public const string APP_ID = "theFakeApp";
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task CleanInstallRunsSquirrelAwareAppsWithInstallFlag()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
|
||||||
|
|
||||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir);
|
|
||||||
await fixture.FullInstall();
|
|
||||||
|
|
||||||
// NB: We execute the Squirrel-aware apps, so we need to give
|
|
||||||
// them a minute to settle or else the using statement will
|
|
||||||
// try to blow away a running process
|
|
||||||
await Task.Delay(1000);
|
|
||||||
|
|
||||||
Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "current", "args2.txt")));
|
|
||||||
Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "current", "args.txt")));
|
|
||||||
|
|
||||||
var text = File.ReadAllText(Path.Combine(tempDir, APP_ID, "current", "args.txt"), Encoding.UTF8);
|
|
||||||
Assert.Contains("firstrun", text);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task UpgradeRunsSquirrelAwareAppsWithUpgradeFlag()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
|
||||||
|
|
||||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
|
||||||
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
|
||||||
await fixture.FullInstall();
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(1000);
|
|
||||||
|
|
||||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
|
||||||
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
|
||||||
await fixture.UpdateApp();
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(1000);
|
|
||||||
|
|
||||||
Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args2.txt")));
|
|
||||||
Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args.txt")));
|
|
||||||
|
|
||||||
var text = File.ReadAllText(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args.txt"), Encoding.UTF8);
|
|
||||||
Assert.Contains("updated", text);
|
|
||||||
Assert.Contains("0.2.0", text);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task RunningUpgradeAppTwiceDoesntCrash()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
|
||||||
|
|
||||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
|
||||||
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
|
||||||
await fixture.FullInstall();
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(1000);
|
|
||||||
|
|
||||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
|
||||||
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
|
||||||
await fixture.UpdateApp();
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(1000);
|
|
||||||
|
|
||||||
// NB: The 2nd time we won't have any updates to apply. We should just do nothing!
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
|
||||||
await fixture.UpdateApp();
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task FullUninstallRemovesAllVersions()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
|
||||||
|
|
||||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
|
||||||
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
|
||||||
await fixture.FullInstall();
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(1000);
|
|
||||||
|
|
||||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
|
||||||
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
|
||||||
await fixture.UpdateApp();
|
|
||||||
}
|
|
||||||
|
|
||||||
await Task.Delay(1000);
|
|
||||||
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
|
||||||
await fixture.FullUninstall();
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "app-0.1.0", "args.txt")));
|
|
||||||
Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "app-0.2.0", "args.txt")));
|
|
||||||
Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, ".dead")));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task CanInstallAndUpdatePackageWithDotsInId()
|
|
||||||
{
|
|
||||||
string tempDir;
|
|
||||||
string remotePkgDir;
|
|
||||||
const string pkgName = "Squirrel.Installed.App";
|
|
||||||
|
|
||||||
using (Utility.GetTempDirectory(out tempDir))
|
|
||||||
using (Utility.GetTempDirectory(out remotePkgDir)) {
|
|
||||||
// install 0.1.0
|
|
||||||
IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir, "SquirrelInstalledAppWithDots.nuspec");
|
|
||||||
var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
|
|
||||||
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
|
|
||||||
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
|
||||||
await fixture.FullInstall();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "app-0.1.0")));
|
|
||||||
Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "current")));
|
|
||||||
|
|
||||||
var info = new AppDescWindows(Path.Combine(tempDir, pkgName), pkgName);
|
|
||||||
|
|
||||||
var version = info.GetVersions().Single();
|
|
||||||
Assert.True(version.IsCurrent);
|
|
||||||
Assert.Equal(new SemanticVersion(0, 1, 0), version.Manifest.Version);
|
|
||||||
|
|
||||||
await Task.Delay(1000);
|
|
||||||
Assert.True(File.ReadAllText(Path.Combine(version.DirectoryPath, "args.txt")).Contains("--squirrel-firstrun"));
|
|
||||||
|
|
||||||
// update top 0.2.0
|
|
||||||
IntegrationTestHelper.CreateFakeInstalledApp("0.2.0", remotePkgDir, "SquirrelInstalledAppWithDots.nuspec");
|
|
||||||
pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
|
|
||||||
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
|
|
||||||
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
|
||||||
await fixture.UpdateApp();
|
|
||||||
}
|
|
||||||
|
|
||||||
info.UpdateAndRetrieveCurrentFolder(false);
|
|
||||||
|
|
||||||
var versions = info.GetVersions().ToArray();
|
|
||||||
Assert.Equal(2, versions.Count());
|
|
||||||
Assert.Equal(new SemanticVersion(0, 2, 0), versions.Single(s => s.IsCurrent).Version);
|
|
||||||
|
|
||||||
//Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "app-0.2.0")));
|
|
||||||
await Task.Delay(1000);
|
|
||||||
|
|
||||||
// uninstall
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
|
||||||
await fixture.FullUninstall();
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.False(File.Exists(Path.Combine(tempDir, pkgName, "app-0.1.0", "args.txt")));
|
|
||||||
Assert.False(File.Exists(Path.Combine(tempDir, pkgName, "app-0.2.0", "args.txt")));
|
|
||||||
Assert.True(File.Exists(Path.Combine(tempDir, pkgName, ".dead")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void WhenNoNewReleasesAreAvailableTheListIsEmpty()
|
|
||||||
{
|
|
||||||
using var _ = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
|
|
||||||
var appDir = Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
|
||||||
var packages = Path.Combine(appDir.FullName, "packages");
|
|
||||||
Directory.CreateDirectory(packages);
|
|
||||||
|
|
||||||
var package = "Squirrel.Core.1.0.0.0-full.nupkg";
|
|
||||||
File.Copy(IntegrationTestHelper.GetPath("fixtures", package), Path.Combine(packages, package));
|
|
||||||
|
|
||||||
var aGivenPackage = Path.Combine(packages, package);
|
|
||||||
var baseEntry = ReleaseEntry.GenerateFromFile(aGivenPackage);
|
|
||||||
|
|
||||||
var updateInfo = UpdateInfo.Create(baseEntry, new[] { baseEntry }, "dontcare");
|
|
||||||
|
|
||||||
Assert.Empty(updateInfo.ReleasesToApply);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ThrowsWhenOnlyDeltaReleasesAreAvailable()
|
|
||||||
{
|
|
||||||
string tempDir;
|
|
||||||
using (Utility.GetTempDirectory(out tempDir)) {
|
|
||||||
var appDir = Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
|
||||||
var packages = Path.Combine(appDir.FullName, "packages");
|
|
||||||
Directory.CreateDirectory(packages);
|
|
||||||
|
|
||||||
var baseFile = "Squirrel.Core.1.0.0.0-full.nupkg";
|
|
||||||
File.Copy(IntegrationTestHelper.GetPath("fixtures", baseFile),
|
|
||||||
Path.Combine(packages, baseFile));
|
|
||||||
var basePackage = Path.Combine(packages, baseFile);
|
|
||||||
var baseEntry = ReleaseEntry.GenerateFromFile(basePackage);
|
|
||||||
|
|
||||||
var deltaFile = "Squirrel.Core.1.1.0.0-delta.nupkg";
|
|
||||||
File.Copy(IntegrationTestHelper.GetPath("fixtures", deltaFile),
|
|
||||||
Path.Combine(packages, deltaFile));
|
|
||||||
var deltaPackage = Path.Combine(packages, deltaFile);
|
|
||||||
var deltaEntry = ReleaseEntry.GenerateFromFile(deltaPackage);
|
|
||||||
|
|
||||||
Assert.Throws<Exception>(
|
|
||||||
() => UpdateInfo.Create(baseEntry, new[] { deltaEntry }, "dontcare"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task ApplyReleasesWithOneReleaseFile()
|
|
||||||
{
|
|
||||||
string tempDir;
|
|
||||||
|
|
||||||
using (Utility.GetTempDirectory(out tempDir)) {
|
|
||||||
string appDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
string packagesDir = Path.Combine(appDir, "packages");
|
|
||||||
Directory.CreateDirectory(packagesDir);
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
|
||||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
|
||||||
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
|
||||||
|
|
||||||
var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.0.0.0-full.nupkg"));
|
|
||||||
var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
|
||||||
|
|
||||||
var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
|
||||||
updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
|
||||||
|
|
||||||
var progress = new List<int>();
|
|
||||||
|
|
||||||
await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
|
||||||
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
|
||||||
|
|
||||||
progress
|
|
||||||
.Aggregate(0, (acc, x) => {
|
|
||||||
(x >= acc).ShouldBeTrue();
|
|
||||||
return x;
|
|
||||||
})
|
|
||||||
.ShouldEqual(100);
|
|
||||||
|
|
||||||
var filesToFind = new[] {
|
|
||||||
new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
|
||||||
new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
|
||||||
};
|
|
||||||
|
|
||||||
filesToFind.ForEach(x => {
|
|
||||||
var path = Path.Combine(tempDir, APP_ID, "staging", "app-1.1.0.0", x.Name);
|
|
||||||
this.Log().Info("Looking for {0}", path);
|
|
||||||
File.Exists(path).ShouldBeTrue();
|
|
||||||
|
|
||||||
var vi = FileVersionInfo.GetVersionInfo(path);
|
|
||||||
var verInfo = new Version(vi.FileVersion ?? "1.0.0.0");
|
|
||||||
x.Version.ShouldEqual(verInfo);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task ApplyReleaseWhichRemovesAFile()
|
|
||||||
{
|
|
||||||
string tempDir;
|
|
||||||
|
|
||||||
using (Utility.GetTempDirectory(out tempDir)) {
|
|
||||||
string appDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
string packagesDir = Path.Combine(appDir, "packages");
|
|
||||||
Directory.CreateDirectory(packagesDir);
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
|
||||||
"Squirrel.Core.1.2.0.0-full.nupkg",
|
|
||||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
|
||||||
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
|
||||||
|
|
||||||
var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
|
||||||
var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.2.0.0-full.nupkg"));
|
|
||||||
|
|
||||||
var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
|
||||||
updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
|
||||||
|
|
||||||
var progress = new List<int>();
|
|
||||||
await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
|
||||||
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
|
||||||
|
|
||||||
progress
|
|
||||||
.Aggregate(0, (acc, x) => {
|
|
||||||
(x >= acc).ShouldBeTrue();
|
|
||||||
return x;
|
|
||||||
})
|
|
||||||
.ShouldEqual(100);
|
|
||||||
|
|
||||||
var rootDirectory = Path.Combine(tempDir, APP_ID, "staging", "app-1.2.0.0");
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
|
||||||
new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
|
||||||
}.ForEach(x => {
|
|
||||||
var path = Path.Combine(rootDirectory, x.Name);
|
|
||||||
this.Log().Info("Looking for {0}", path);
|
|
||||||
File.Exists(path).ShouldBeTrue();
|
|
||||||
});
|
|
||||||
|
|
||||||
var removedFile = Path.Combine("sub", "Ionic.Zip.dll");
|
|
||||||
var deployedPath = Path.Combine(rootDirectory, removedFile);
|
|
||||||
File.Exists(deployedPath).ShouldBeFalse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task ApplyReleaseWhichMovesAFileToADifferentDirectory()
|
|
||||||
{
|
|
||||||
string tempDir;
|
|
||||||
|
|
||||||
using (Utility.GetTempDirectory(out tempDir)) {
|
|
||||||
string appDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
string packagesDir = Path.Combine(appDir, "packages");
|
|
||||||
Directory.CreateDirectory(packagesDir);
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
|
||||||
"Squirrel.Core.1.3.0.0-full.nupkg",
|
|
||||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
|
||||||
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
|
||||||
|
|
||||||
var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
|
||||||
var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.3.0.0-full.nupkg"));
|
|
||||||
|
|
||||||
var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
|
||||||
updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
|
||||||
|
|
||||||
var progress = new List<int>();
|
|
||||||
await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
|
||||||
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
|
||||||
|
|
||||||
progress
|
|
||||||
.Aggregate(0, (acc, x) => {
|
|
||||||
(x >= acc).ShouldBeTrue();
|
|
||||||
return x;
|
|
||||||
})
|
|
||||||
.ShouldEqual(100);
|
|
||||||
|
|
||||||
var rootDirectory = Path.Combine(tempDir, APP_ID, "staging", "app-1.3.0.0");
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
|
||||||
new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
|
||||||
}.ForEach(x => {
|
|
||||||
var path = Path.Combine(rootDirectory, x.Name);
|
|
||||||
this.Log().Info("Looking for {0}", path);
|
|
||||||
File.Exists(path).ShouldBeTrue();
|
|
||||||
});
|
|
||||||
|
|
||||||
var oldFile = Path.Combine(rootDirectory, "sub", "Ionic.Zip.dll");
|
|
||||||
File.Exists(oldFile).ShouldBeFalse();
|
|
||||||
|
|
||||||
var newFile = Path.Combine(rootDirectory, "other", "Ionic.Zip.dll");
|
|
||||||
File.Exists(newFile).ShouldBeTrue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task ApplyReleasesWithDeltaReleases()
|
|
||||||
{
|
|
||||||
string tempDir;
|
|
||||||
|
|
||||||
using (Utility.GetTempDirectory(out tempDir)) {
|
|
||||||
string appDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
string packagesDir = Path.Combine(appDir, "packages");
|
|
||||||
Directory.CreateDirectory(packagesDir);
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-delta.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
|
||||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
|
||||||
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
|
||||||
|
|
||||||
var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.0.0.0-full.nupkg"));
|
|
||||||
var deltaEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-delta.nupkg"));
|
|
||||||
var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
|
||||||
|
|
||||||
var updateInfo = UpdateInfo.Create(baseEntry, new[] { deltaEntry, latestFullEntry }, packagesDir);
|
|
||||||
updateInfo.ReleasesToApply.Contains(deltaEntry).ShouldBeTrue();
|
|
||||||
|
|
||||||
var progress = new List<int>();
|
|
||||||
|
|
||||||
await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
|
||||||
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
|
||||||
|
|
||||||
// TODO: this is failing intermittently, not sure why but is not a big deal atm
|
|
||||||
// progress
|
|
||||||
// .Aggregate(0, (acc, x) => { (x >= acc).ShouldBeTrue(); return x; })
|
|
||||||
// .ShouldEqual(100);
|
|
||||||
|
|
||||||
var filesToFind = new[] {
|
|
||||||
new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
|
||||||
new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
|
||||||
};
|
|
||||||
|
|
||||||
filesToFind.ForEach(x => {
|
|
||||||
var path = Path.Combine(tempDir, APP_ID, "staging", "app-1.1.0.0", x.Name);
|
|
||||||
this.Log().Info("Looking for {0}", path);
|
|
||||||
File.Exists(path).ShouldBeTrue();
|
|
||||||
|
|
||||||
var vi = FileVersionInfo.GetVersionInfo(path);
|
|
||||||
var verInfo = new Version(vi.FileVersion ?? "1.0.0.0");
|
|
||||||
x.Version.ShouldEqual(verInfo);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task CreateFullPackagesFromDeltaSmokeTest()
|
|
||||||
{
|
|
||||||
string tempDir;
|
|
||||||
using (Utility.GetTempDirectory(out tempDir)) {
|
|
||||||
string appDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
string packagesDir = Path.Combine(appDir, "packages");
|
|
||||||
Directory.CreateDirectory(packagesDir);
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-delta.nupkg"
|
|
||||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(tempDir, APP_ID, "packages", x)));
|
|
||||||
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
|
||||||
|
|
||||||
var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(tempDir, APP_ID, "packages", "Squirrel.Core.1.0.0.0-full.nupkg"));
|
|
||||||
var deltaEntry = ReleaseEntry.GenerateFromFile(Path.Combine(tempDir, APP_ID, "packages", "Squirrel.Core.1.1.0.0-delta.nupkg"));
|
|
||||||
|
|
||||||
var result = fixture.createFullPackagesFromDeltas(new[] { deltaEntry }, baseEntry, null);
|
|
||||||
|
|
||||||
var zp = new ZipPackage(Path.Combine(tempDir, APP_ID, "packages", result.Filename));
|
|
||||||
zp.Version.ToString().ShouldEqual("1.1.0.0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task CreateShortcutsRoundTrip()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
|
||||||
|
|
||||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir);
|
|
||||||
await fixture.FullInstall();
|
|
||||||
|
|
||||||
fixture.CreateShortcutsForExecutable("SquirrelAwareApp.exe",
|
|
||||||
ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup | ShortcutLocation.AppRoot, false, null, null);
|
|
||||||
|
|
||||||
Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "PublishSingleFileAwareApp.lnk")));
|
|
||||||
|
|
||||||
// NB: COM is Weird.
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
fixture.RemoveShortcutsForExecutable("SquirrelAwareApp.exe",
|
|
||||||
ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup | ShortcutLocation.AppRoot);
|
|
||||||
|
|
||||||
// NB: Squirrel-Aware first-run might still be running, slow
|
|
||||||
// our roll before blowing away the temp path
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
//[Fact]
|
|
||||||
//public async Task GetShortcutsSmokeTest()
|
|
||||||
//{
|
|
||||||
// string remotePkgPath;
|
|
||||||
// string path;
|
|
||||||
|
|
||||||
// using (Utility.WithTempDirectory(out path)) {
|
|
||||||
// using (Utility.WithTempDirectory(out remotePkgPath))
|
|
||||||
// using (var mgr = new UpdateManager(remotePkgPath, APP_ID, path)) {
|
|
||||||
// IntegrationTestHelper.CreateFakeInstalledApp("1.0.0.1", remotePkgPath);
|
|
||||||
// await mgr.FullInstall();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var fixture = new ApplyReleasesImpl(Path.Combine(path, APP_ID));
|
|
||||||
// var result = fixture.GetShortcutsForExecutable("SquirrelAwareApp.exe", ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup, null);
|
|
||||||
|
|
||||||
// Assert.Equal(3, result.Keys.Count);
|
|
||||||
|
|
||||||
// // NB: Squirrel-Aware first-run might still be running, slow
|
|
||||||
// // our roll before blowing away the temp path
|
|
||||||
// Thread.Sleep(1000);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Web;
|
|
||||||
using Squirrel.Tests.TestHelpers;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Squirrel.Tests
|
|
||||||
{
|
|
||||||
public class CheckForUpdateTests
|
|
||||||
{
|
|
||||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
|
||||||
public void NewReleasesShouldBeDetected()
|
|
||||||
{
|
|
||||||
Assert.Fail("Rewrite this to be an integration test");
|
|
||||||
/*
|
|
||||||
string localReleasesFile = Path.Combine(".", "theApp", "packages", "RELEASES");
|
|
||||||
|
|
||||||
var fileInfo = new Mock<FileInfoBase>();
|
|
||||||
fileInfo.Setup(x => x.OpenRead())
|
|
||||||
.Returns(File.OpenRead(IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOh")));
|
|
||||||
|
|
||||||
var fs = new Mock<IFileSystemFactory>();
|
|
||||||
fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
|
||||||
|
|
||||||
var urlDownloader = new Mock<IUrlDownloader>();
|
|
||||||
var dlPath = IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOne");
|
|
||||||
urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
|
||||||
.Returns(Observable.Return(File.ReadAllText(dlPath, Encoding.UTF8)));
|
|
||||||
|
|
||||||
var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
|
||||||
var result = default(UpdateInfo);
|
|
||||||
|
|
||||||
using (fixture) {
|
|
||||||
result = fixture.CheckForUpdate().First();
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.NotNull(result);
|
|
||||||
Assert.Equal(1, result.ReleasesToApply.Single().Version.Major);
|
|
||||||
Assert.Equal(1, result.ReleasesToApply.Single().Version.Minor);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
|
||||||
public void CorruptedReleaseFileMeansWeStartFromScratch()
|
|
||||||
{
|
|
||||||
Assert.Fail("Rewrite this to be an integration test");
|
|
||||||
|
|
||||||
/*
|
|
||||||
string localPackagesDir = Path.Combine(".", "theApp", "packages");
|
|
||||||
string localReleasesFile = Path.Combine(localPackagesDir, "RELEASES");
|
|
||||||
|
|
||||||
var fileInfo = new Mock<FileInfoBase>();
|
|
||||||
fileInfo.Setup(x => x.Exists).Returns(true);
|
|
||||||
fileInfo.Setup(x => x.OpenRead())
|
|
||||||
.Returns(new MemoryStream(Encoding.UTF8.GetBytes("lol this isn't right")));
|
|
||||||
|
|
||||||
var dirInfo = new Mock<DirectoryInfoBase>();
|
|
||||||
dirInfo.Setup(x => x.Exists).Returns(true);
|
|
||||||
|
|
||||||
var fs = new Mock<IFileSystemFactory>();
|
|
||||||
fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
|
||||||
fs.Setup(x => x.CreateDirectoryRecursive(localPackagesDir)).Verifiable();
|
|
||||||
fs.Setup(x => x.DeleteDirectoryRecursive(localPackagesDir)).Verifiable();
|
|
||||||
fs.Setup(x => x.GetDirectoryInfo(localPackagesDir)).Returns(dirInfo.Object);
|
|
||||||
|
|
||||||
var urlDownloader = new Mock<IUrlDownloader>();
|
|
||||||
var dlPath = IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOne");
|
|
||||||
urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
|
||||||
.Returns(Observable.Return(File.ReadAllText(dlPath, Encoding.UTF8)));
|
|
||||||
|
|
||||||
var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
|
||||||
using (fixture) {
|
|
||||||
fixture.CheckForUpdate().First();
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.Verify(x => x.CreateDirectoryRecursive(localPackagesDir), Times.Once());
|
|
||||||
fs.Verify(x => x.DeleteDirectoryRecursive(localPackagesDir), Times.Once());
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
|
||||||
public void CorruptRemoteFileShouldThrowOnCheck()
|
|
||||||
{
|
|
||||||
Assert.Fail("Rewrite this to be an integration test");
|
|
||||||
|
|
||||||
/*
|
|
||||||
string localPackagesDir = Path.Combine(".", "theApp", "packages");
|
|
||||||
string localReleasesFile = Path.Combine(localPackagesDir, "RELEASES");
|
|
||||||
|
|
||||||
var fileInfo = new Mock<FileInfoBase>();
|
|
||||||
fileInfo.Setup(x => x.Exists).Returns(false);
|
|
||||||
|
|
||||||
var dirInfo = new Mock<DirectoryInfoBase>();
|
|
||||||
dirInfo.Setup(x => x.Exists).Returns(true);
|
|
||||||
|
|
||||||
var fs = new Mock<IFileSystemFactory>();
|
|
||||||
fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
|
||||||
fs.Setup(x => x.CreateDirectoryRecursive(localPackagesDir)).Verifiable();
|
|
||||||
fs.Setup(x => x.DeleteDirectoryRecursive(localPackagesDir)).Verifiable();
|
|
||||||
fs.Setup(x => x.GetDirectoryInfo(localPackagesDir)).Returns(dirInfo.Object);
|
|
||||||
|
|
||||||
var urlDownloader = new Mock<IUrlDownloader>();
|
|
||||||
urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
|
||||||
.Returns(Observable.Return("lol this isn't right"));
|
|
||||||
|
|
||||||
var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
|
||||||
|
|
||||||
using (fixture) {
|
|
||||||
Assert.Throws<Exception>(() => fixture.CheckForUpdate().First());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(Skip = "TODO")]
|
|
||||||
public void IfLocalVersionGreaterThanRemoteWeRollback()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(Skip = "TODO")]
|
|
||||||
public void IfLocalAndRemoteAreEqualThenDoNothing()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(@"94689fede03fed7ab59c24337673a27837f0c3ec MyCoolApp-1.0.nupkg 1004502", "MyCoolApp", null)]
|
|
||||||
[InlineData(@"0000000000000000000000000000000000000000 https://www.test.org/Folder/MyCoolApp-1.2-delta.nupkg?query=param 1231953", "MyCoolApp", "https://www.test.org/Folder")]
|
|
||||||
public async Task WebSourceRequestsExpectedUrls(string releaseEntry, string releaseName, string baseUrl)
|
|
||||||
{
|
|
||||||
baseUrl = baseUrl ?? "https://example.com/files";
|
|
||||||
var dl = new FakeDownloader();
|
|
||||||
var source = new Sources.SimpleWebSource("https://example.com/files", dl);
|
|
||||||
|
|
||||||
dl.MockedResponseBytes = Encoding.UTF8.GetBytes(releaseEntry);
|
|
||||||
var releases = await source.GetReleaseFeed(null, null);
|
|
||||||
Assert.True(releases.Count() == 1);
|
|
||||||
Assert.Equal(releaseName, releases[0].PackageName);
|
|
||||||
Assert.Equal("https://example.com/files/RELEASES", new Uri(dl.LastUrl).GetLeftPart(UriPartial.Path));
|
|
||||||
|
|
||||||
await source.DownloadReleaseEntry(releases[0], "test", null);
|
|
||||||
Assert.Equal(baseUrl + "/" + releases[0].Filename, new Uri(dl.LastUrl).GetLeftPart(UriPartial.Path));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("http://example.com", "MyPackage.nupkg", "http://example.com/MyPackage.nupkg")]
|
|
||||||
[InlineData("http://example.com?auth=hello", "MyPackage.nupkg", "http://example.com/MyPackage.nupkg?auth=hello")]
|
|
||||||
[InlineData("http://example.com?auth=hello", "https://my.packages.domain/MyPackage-1.0.0.nupkg", "https://my.packages.domain/MyPackage-1.0.0.nupkg")]
|
|
||||||
public async Task SimpleWebSourcePreservesQueryParametersAndAbsoluteReleaseUri(string baseUri, string releaseUri, string expectedPackageUrl)
|
|
||||||
{
|
|
||||||
var dl = new FakeDownloader();
|
|
||||||
var source = new Sources.SimpleWebSource(baseUri, dl);
|
|
||||||
var baseKvp = HttpUtility.ParseQueryString(new Uri(baseUri).Query);
|
|
||||||
var baseDict = baseKvp.AllKeys.Where(k => k != null).ToDictionary(k => k, k => baseKvp[k]);
|
|
||||||
|
|
||||||
var releaseEntry = $"94689fede03fed7ab59c24337673a27837f0c3ec {releaseUri} 1004502";
|
|
||||||
dl.MockedResponseBytes = Encoding.UTF8.GetBytes(releaseEntry);
|
|
||||||
|
|
||||||
var releases = await source.GetReleaseFeed();
|
|
||||||
var expected = new Uri(baseUri).GetLeftPart(UriPartial.Path).TrimEnd('/') + "/RELEASES";
|
|
||||||
Assert.StartsWith(expected, dl.LastUrl);
|
|
||||||
|
|
||||||
// check that each query parameter in base url is in the releases string
|
|
||||||
var releasesUri = new Uri(dl.LastUrl);
|
|
||||||
var releasesKvp = HttpUtility.ParseQueryString(releasesUri.Query);
|
|
||||||
var releasesDict = releasesKvp.AllKeys.Where(k => k != null).ToDictionary(k => k, k => releasesKvp[k]);
|
|
||||||
foreach (var kvp in baseDict) {
|
|
||||||
Assert.Equal(releasesDict[kvp.Key], kvp.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
await source.DownloadReleaseEntry(releases[0], "test", null);
|
|
||||||
Assert.Equal(expectedPackageUrl, dl.LastUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,347 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Squirrel.NuGet;
|
|
||||||
using Squirrel;
|
|
||||||
using Squirrel.SimpleSplat;
|
|
||||||
using Squirrel.Tests.TestHelpers;
|
|
||||||
using Xunit;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
using NuGet.Versioning;
|
|
||||||
using Squirrel.CommandLine;
|
|
||||||
|
|
||||||
namespace Squirrel.Tests
|
|
||||||
{
|
|
||||||
public class ApplyDeltaPackageTests : TestLoggingBase
|
|
||||||
{
|
|
||||||
public ApplyDeltaPackageTests(ITestOutputHelper log) : base(log)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ApplyDeltaPackageSmokeTest()
|
|
||||||
{
|
|
||||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0-full.nupkg");
|
|
||||||
var deltaPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-delta.nupkg");
|
|
||||||
var expectedPackageFile = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0-full.nupkg");
|
|
||||||
var outFile = Path.GetTempFileName() + ".nupkg";
|
|
||||||
|
|
||||||
try {
|
|
||||||
var deltaBuilder = new DeltaPackage();
|
|
||||||
deltaBuilder.ApplyDeltaPackage(basePackage, deltaPackage, outFile);
|
|
||||||
|
|
||||||
var result = new ZipPackage(outFile);
|
|
||||||
var expected = new ZipPackage(expectedPackageFile);
|
|
||||||
|
|
||||||
result.Id.ShouldEqual(expected.Id);
|
|
||||||
result.Version.ShouldEqual(expected.Version);
|
|
||||||
|
|
||||||
this.Log().Info("Expected file list:");
|
|
||||||
var expectedList = expected.Files.Select(x => x.Path).OrderBy(x => x).ToList();
|
|
||||||
expectedList.ForEach(x => this.Log().Info(x));
|
|
||||||
|
|
||||||
this.Log().Info("Actual file list:");
|
|
||||||
var actualList = result.Files.Select(x => x.Path).OrderBy(x => x).ToList();
|
|
||||||
actualList.ForEach(x => this.Log().Info(x));
|
|
||||||
|
|
||||||
Enumerable.Zip(expectedList, actualList, (e, a) => e == a)
|
|
||||||
.All(x => x != false)
|
|
||||||
.ShouldBeTrue();
|
|
||||||
} finally {
|
|
||||||
if (File.Exists(outFile)) {
|
|
||||||
File.Delete(outFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ApplyDeltaWithBothBsdiffAndNormalDiffDoesntFail()
|
|
||||||
{
|
|
||||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.1.8-full.nupkg");
|
|
||||||
var deltaPackage = IntegrationTestHelper.GetPath("fixtures", "slack-1.2.0-delta.nupkg");
|
|
||||||
var outFile = Path.GetTempFileName() + ".nupkg";
|
|
||||||
|
|
||||||
try {
|
|
||||||
var deltaBuilder = new DeltaPackage();
|
|
||||||
deltaBuilder.ApplyDeltaPackage(basePackage, deltaPackage, outFile);
|
|
||||||
|
|
||||||
var result = new ZipPackage(outFile);
|
|
||||||
|
|
||||||
result.Id.ShouldEqual("slack");
|
|
||||||
result.Version.ShouldEqual(SemanticVersion.Parse("1.2.0"));
|
|
||||||
} finally {
|
|
||||||
if (File.Exists(outFile)) {
|
|
||||||
File.Delete(outFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ApplyMultipleDeltasFast()
|
|
||||||
{
|
|
||||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.287-full.nupkg");
|
|
||||||
var deltaPackage1 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.288-delta.nupkg");
|
|
||||||
var deltaPackage2 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.291-delta.nupkg");
|
|
||||||
var deltaPackage3 = IntegrationTestHelper.GetPath("fixtures", "Clowd-3.4.292-delta.nupkg");
|
|
||||||
|
|
||||||
using var t1 = Utility.GetTempDirectory(out var appDir);
|
|
||||||
using var t2 = Utility.GetTempDirectory(out var updateDir);
|
|
||||||
|
|
||||||
using var um = UpdateManagerTestImpl.FromLocalPackageTempDir(updateDir, "theApp", appDir);
|
|
||||||
var pkgDir = um.Config.PackagesDir;
|
|
||||||
|
|
||||||
File.Copy(basePackage, Path.Combine(pkgDir, Path.GetFileName(basePackage)));
|
|
||||||
File.Copy(deltaPackage1, Path.Combine(pkgDir, Path.GetFileName(deltaPackage1)));
|
|
||||||
File.Copy(deltaPackage2, Path.Combine(pkgDir, Path.GetFileName(deltaPackage2)));
|
|
||||||
File.Copy(deltaPackage3, Path.Combine(pkgDir, Path.GetFileName(deltaPackage3)));
|
|
||||||
|
|
||||||
var baseEntry = ReleaseEntry.GenerateFromFile(basePackage);
|
|
||||||
|
|
||||||
var toApply = new [] {
|
|
||||||
ReleaseEntry.GenerateFromFile(deltaPackage1),
|
|
||||||
ReleaseEntry.GenerateFromFile(deltaPackage2),
|
|
||||||
ReleaseEntry.GenerateFromFile(deltaPackage3),
|
|
||||||
};
|
|
||||||
|
|
||||||
List<int> progress = new List<int>();
|
|
||||||
|
|
||||||
var newEntry = um.createFullPackagesFromDeltas(toApply, baseEntry, progress.Add);
|
|
||||||
|
|
||||||
var outFile = Path.Combine(pkgDir, newEntry.Filename);
|
|
||||||
var result = new ZipPackage(outFile);
|
|
||||||
result.Id.ShouldEqual("Clowd");
|
|
||||||
result.Version.ShouldEqual(SemanticVersion.Parse("3.4.292"));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(Skip = "Rewrite this test, the original uses too many heavyweight fixtures")]
|
|
||||||
public void ApplyMultipleDeltaPackagesGeneratesCorrectHash()
|
|
||||||
{
|
|
||||||
Assert.Fail("Rewrite this test, the original uses too many heavyweight fixtures");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CreateDeltaPackageTests : IEnableLogger
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void CreateDeltaPackageIntegrationTest()
|
|
||||||
{
|
|
||||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
|
||||||
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
|
||||||
|
|
||||||
var baseFixture = new ReleasePackageBuilder(basePackage);
|
|
||||||
var fixture = new ReleasePackageBuilder(newPackage);
|
|
||||||
|
|
||||||
var tempFiles = Enumerable.Range(0, 3)
|
|
||||||
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
try {
|
|
||||||
baseFixture.CreateReleasePackage(tempFiles[0]);
|
|
||||||
fixture.CreateReleasePackage(tempFiles[1]);
|
|
||||||
|
|
||||||
(new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
|
||||||
(new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
|
||||||
|
|
||||||
var deltaBuilder = new DeltaPackageBuilder();
|
|
||||||
deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
|
||||||
|
|
||||||
var fullPkg = new ZipPackage(tempFiles[1]);
|
|
||||||
var deltaPkg = new ZipPackage(tempFiles[2]);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Package Checks
|
|
||||||
//
|
|
||||||
|
|
||||||
fullPkg.Id.ShouldEqual(deltaPkg.Id);
|
|
||||||
fullPkg.Version.CompareTo(deltaPkg.Version).ShouldEqual(0);
|
|
||||||
|
|
||||||
// Delta packages should be smaller than the original!
|
|
||||||
var fileInfos = tempFiles.Select(x => new FileInfo(x)).ToArray();
|
|
||||||
this.Log().Info("Base Size: {0}, Current Size: {1}, Delta Size: {2}",
|
|
||||||
fileInfos[0].Length, fileInfos[1].Length, fileInfos[2].Length);
|
|
||||||
|
|
||||||
(fileInfos[2].Length - fileInfos[1].Length).ShouldBeLessThan(0);
|
|
||||||
|
|
||||||
//
|
|
||||||
// File Checks
|
|
||||||
///
|
|
||||||
|
|
||||||
var deltaPkgFiles = deltaPkg.Files.ToList();
|
|
||||||
deltaPkgFiles.Count.ShouldBeGreaterThan(0);
|
|
||||||
|
|
||||||
this.Log().Info("Files in delta package:");
|
|
||||||
deltaPkgFiles.ForEach(x => this.Log().Info(x.Path));
|
|
||||||
|
|
||||||
var newFilesAdded = new[] {
|
|
||||||
"Newtonsoft.Json.dll",
|
|
||||||
//"Refit.dll",
|
|
||||||
//"Refit-Portable.dll",
|
|
||||||
//"Castle.Core.dll",
|
|
||||||
}.Select(x => x.ToLowerInvariant());
|
|
||||||
|
|
||||||
// vNext adds a dependency on Refit
|
|
||||||
newFilesAdded
|
|
||||||
.All(x => deltaPkgFiles.Any(y => y.Path.ToLowerInvariant().Contains(x)))
|
|
||||||
.ShouldBeTrue();
|
|
||||||
|
|
||||||
// All the other files should be diffs and shasums
|
|
||||||
deltaPkgFiles
|
|
||||||
.Where(x => !newFilesAdded.Any(y => x.Path.ToLowerInvariant().Contains(y)))
|
|
||||||
.All(x => x.Path.ToLowerInvariant().EndsWith("bsdiff") || x.Path.ToLowerInvariant().EndsWith("shasum"))
|
|
||||||
.ShouldBeTrue();
|
|
||||||
|
|
||||||
// Every .diff file should have a shasum file
|
|
||||||
deltaPkg.Files.Any(x => x.Path.ToLowerInvariant().EndsWith(".bsdiff")).ShouldBeTrue();
|
|
||||||
deltaPkg.Files
|
|
||||||
.Where(x => x.Path.ToLowerInvariant().EndsWith(".bsdiff"))
|
|
||||||
.ForEach(x => {
|
|
||||||
var lookingFor = x.Path.Replace(".bsdiff", ".shasum");
|
|
||||||
this.Log().Info("Looking for corresponding shasum file: {0}", lookingFor);
|
|
||||||
deltaPkg.Files.Any(y => y.Path == lookingFor).ShouldBeTrue();
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
tempFiles.ForEach(File.Delete);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void WhenBasePackageIsNewerThanNewPackageThrowException()
|
|
||||||
{
|
|
||||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
|
||||||
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
|
||||||
|
|
||||||
var baseFixture = new ReleasePackageBuilder(basePackage);
|
|
||||||
var fixture = new ReleasePackageBuilder(newPackage);
|
|
||||||
|
|
||||||
var tempFiles = Enumerable.Range(0, 3)
|
|
||||||
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
try {
|
|
||||||
baseFixture.CreateReleasePackage(tempFiles[0]);
|
|
||||||
fixture.CreateReleasePackage(tempFiles[1]);
|
|
||||||
|
|
||||||
(new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
|
||||||
(new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
|
||||||
|
|
||||||
Assert.Throws<InvalidOperationException>(() => {
|
|
||||||
var deltaBuilder = new DeltaPackageBuilder();
|
|
||||||
deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
tempFiles.ForEach(File.Delete);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void WhenBasePackageReleaseIsNullThrowsException()
|
|
||||||
{
|
|
||||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.0.0.0.nupkg");
|
|
||||||
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nupkg");
|
|
||||||
|
|
||||||
var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages");
|
|
||||||
(new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue();
|
|
||||||
|
|
||||||
var baseFixture = new ReleasePackageBuilder(basePackage);
|
|
||||||
var fixture = new ReleasePackageBuilder(newPackage);
|
|
||||||
|
|
||||||
var tempFile = Path.GetTempPath() + Guid.NewGuid() + ".nupkg";
|
|
||||||
|
|
||||||
try {
|
|
||||||
Assert.Throws<ArgumentException>(() => {
|
|
||||||
var deltaBuilder = new DeltaPackageBuilder();
|
|
||||||
deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFile);
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
File.Delete(tempFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void WhenBasePackageDoesNotExistThrowException()
|
|
||||||
{
|
|
||||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
|
||||||
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
|
||||||
|
|
||||||
var baseFixture = new ReleasePackageBuilder(basePackage);
|
|
||||||
var fixture = new ReleasePackageBuilder(newPackage);
|
|
||||||
|
|
||||||
var tempFiles = Enumerable.Range(0, 3)
|
|
||||||
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
try {
|
|
||||||
baseFixture.CreateReleasePackage(tempFiles[0]);
|
|
||||||
fixture.CreateReleasePackage(tempFiles[1]);
|
|
||||||
|
|
||||||
(new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
|
||||||
(new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
|
||||||
|
|
||||||
// NOW WATCH AS THE FILE DISAPPEARS
|
|
||||||
File.Delete(baseFixture.ReleasePackageFile);
|
|
||||||
|
|
||||||
Assert.Throws<FileNotFoundException>(() => {
|
|
||||||
var deltaBuilder = new DeltaPackageBuilder();
|
|
||||||
deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
tempFiles.ForEach(File.Delete);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void WhenNewPackageDoesNotExistThrowException()
|
|
||||||
{
|
|
||||||
var basePackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
|
||||||
var newPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.2.0-pre.nupkg");
|
|
||||||
|
|
||||||
var baseFixture = new ReleasePackageBuilder(basePackage);
|
|
||||||
var fixture = new ReleasePackageBuilder(newPackage);
|
|
||||||
|
|
||||||
var tempFiles = Enumerable.Range(0, 3)
|
|
||||||
.Select(_ => Path.GetTempPath() + Guid.NewGuid().ToString() + ".nupkg")
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
try {
|
|
||||||
baseFixture.CreateReleasePackage(tempFiles[0]);
|
|
||||||
fixture.CreateReleasePackage(tempFiles[1]);
|
|
||||||
|
|
||||||
(new FileInfo(baseFixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
|
||||||
(new FileInfo(fixture.ReleasePackageFile)).Exists.ShouldBeTrue();
|
|
||||||
|
|
||||||
// NOW WATCH AS THE FILE DISAPPEARS
|
|
||||||
File.Delete(fixture.ReleasePackageFile);
|
|
||||||
|
|
||||||
Assert.Throws<FileNotFoundException>(() => {
|
|
||||||
var deltaBuilder = new DeltaPackageBuilder();
|
|
||||||
deltaBuilder.CreateDeltaPackage(baseFixture, fixture, tempFiles[2]);
|
|
||||||
});
|
|
||||||
} finally {
|
|
||||||
tempFiles.ForEach(File.Delete);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void HandleBsDiffWithoutExtraData()
|
|
||||||
{
|
|
||||||
var baseFileData = new byte[] { 1, 1, 1, 1 };
|
|
||||||
var newFileData = new byte[] { 2, 1, 1, 1 };
|
|
||||||
|
|
||||||
byte[] patchData;
|
|
||||||
|
|
||||||
using (var patchOut = new MemoryStream()) {
|
|
||||||
Bsdiff.BinaryPatchUtility.Create(baseFileData, newFileData, patchOut);
|
|
||||||
patchData = patchOut.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
using (var toPatch = new MemoryStream(baseFileData))
|
|
||||||
using (var patched = new MemoryStream()) {
|
|
||||||
Bsdiff.BinaryPatchUtility.Apply(toPatch, () => new MemoryStream(patchData), patched);
|
|
||||||
|
|
||||||
Assert.Equal(newFileData, patched.ToArray());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Squirrel.SimpleSplat;
|
|
||||||
using Squirrel.Tests.TestHelpers;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Squirrel.Tests
|
|
||||||
{
|
|
||||||
public class DownloadReleasesTests
|
|
||||||
{
|
|
||||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
|
||||||
public void ChecksumShouldFailIfFilesAreMissing()
|
|
||||||
{
|
|
||||||
Assert.Fail("Rewrite this to be an integration test");
|
|
||||||
|
|
||||||
/*
|
|
||||||
var filename = "Squirrel.Core.1.0.0.0.nupkg";
|
|
||||||
var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
|
|
||||||
var fs = new Mock<IFileSystemFactory>();
|
|
||||||
var urlDownloader = new Mock<IUrlDownloader>();
|
|
||||||
|
|
||||||
ReleaseEntry entry;
|
|
||||||
using (var f = File.OpenRead(nuGetPkg)) {
|
|
||||||
entry = ReleaseEntry.GenerateFromFile(f, filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
var fileInfo = new Mock<FileInfoBase>();
|
|
||||||
fileInfo.Setup(x => x.OpenRead()).Returns(File.OpenRead(nuGetPkg));
|
|
||||||
fileInfo.Setup(x => x.Exists).Returns(false);
|
|
||||||
|
|
||||||
fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
|
|
||||||
|
|
||||||
var fixture = ExposedObject.From(
|
|
||||||
new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object));
|
|
||||||
|
|
||||||
bool shouldDie = true;
|
|
||||||
try {
|
|
||||||
// NB: We can't use Assert.Throws here because the binder
|
|
||||||
// will try to pick the wrong method
|
|
||||||
fixture.checksumPackage(entry);
|
|
||||||
} catch (Exception) {
|
|
||||||
shouldDie = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldDie.ShouldBeFalse();
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
|
||||||
public void ChecksumShouldFailIfFilesAreBogus()
|
|
||||||
{
|
|
||||||
Assert.Fail("Rewrite this to be an integration test");
|
|
||||||
|
|
||||||
/*
|
|
||||||
var filename = "Squirrel.Core.1.0.0.0.nupkg";
|
|
||||||
var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
|
|
||||||
var fs = new Mock<IFileSystemFactory>();
|
|
||||||
var urlDownloader = new Mock<IUrlDownloader>();
|
|
||||||
|
|
||||||
ReleaseEntry entry;
|
|
||||||
using (var f = File.OpenRead(nuGetPkg)) {
|
|
||||||
entry = ReleaseEntry.GenerateFromFile(f, filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
var fileInfo = new Mock<FileInfoBase>();
|
|
||||||
fileInfo.Setup(x => x.OpenRead()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("Lol broken")));
|
|
||||||
fileInfo.Setup(x => x.Exists).Returns(true);
|
|
||||||
fileInfo.Setup(x => x.Length).Returns(new FileInfo(nuGetPkg).Length);
|
|
||||||
fileInfo.Setup(x => x.Delete()).Verifiable();
|
|
||||||
|
|
||||||
fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
|
|
||||||
|
|
||||||
var fixture = ExposedObject.From(
|
|
||||||
new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object));
|
|
||||||
|
|
||||||
bool shouldDie = true;
|
|
||||||
try {
|
|
||||||
fixture.checksumPackage(entry);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
this.Log().InfoException("Checksum failure", ex);
|
|
||||||
shouldDie = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldDie.ShouldBeFalse();
|
|
||||||
fileInfo.Verify(x => x.Delete(), Times.Once());
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
|
||||||
public async Task DownloadReleasesFromHttpServerIntegrationTest()
|
|
||||||
{
|
|
||||||
Assert.Fail("Rewrite this to not use the SampleUpdatingApp");
|
|
||||||
|
|
||||||
/*
|
|
||||||
string tempDir = null;
|
|
||||||
|
|
||||||
var updateDir = new DirectoryInfo(IntegrationTestHelper.GetPath("..", "SampleUpdatingApp", "SampleReleasesFolder"));
|
|
||||||
|
|
||||||
IDisposable disp;
|
|
||||||
try {
|
|
||||||
var httpServer = new StaticHttpServer(30405, updateDir.FullName);
|
|
||||||
disp = httpServer.Start();
|
|
||||||
} catch (HttpListenerException) {
|
|
||||||
Assert.False(true, @"Windows sucks, go run 'netsh http add urlacl url=http://+:30405/ user=MYMACHINE\MyUser");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var entriesToDownload = updateDir.GetFiles("*.nupkg")
|
|
||||||
.Select(x => ReleaseEntry.GenerateFromFile(x.FullName))
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
entriesToDownload.Count().ShouldBeGreaterThan(0);
|
|
||||||
|
|
||||||
using (disp)
|
|
||||||
using (Utility.WithTempDirectory(out tempDir)) {
|
|
||||||
// NB: This is normally done by CheckForUpdates, but since
|
|
||||||
// we're skipping that in the test we have to do it ourselves
|
|
||||||
Directory.CreateDirectory(Path.Combine(tempDir, "SampleUpdatingApp", "packages"));
|
|
||||||
|
|
||||||
var fixture = new UpdateManager("http://localhost:30405", "SampleUpdatingApp", tempDir);
|
|
||||||
using (fixture) {
|
|
||||||
var progress = new List<int>();
|
|
||||||
await fixture.DownloadReleases(entriesToDownload, progress.Add);
|
|
||||||
|
|
||||||
progress
|
|
||||||
.Aggregate(0, (acc, x) => { x.ShouldBeGreaterThan(acc); return x; })
|
|
||||||
.ShouldEqual(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
entriesToDownload.ForEach(x => {
|
|
||||||
this.Log().Info("Looking for {0}", x.Filename);
|
|
||||||
var actualFile = Path.Combine(tempDir, "SampleUpdatingApp", "packages", x.Filename);
|
|
||||||
File.Exists(actualFile).ShouldBeTrue();
|
|
||||||
|
|
||||||
var actualEntry = ReleaseEntry.GenerateFromFile(actualFile);
|
|
||||||
actualEntry.SHA1.ShouldEqual(x.SHA1);
|
|
||||||
actualEntry.Version.ShouldEqual(x.Version);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact(Skip = "Rewrite this to be an integration test")]
|
|
||||||
public async Task DownloadReleasesFromFileDirectoryIntegrationTest()
|
|
||||||
{
|
|
||||||
Assert.Fail("Rewrite this to not use the SampleUpdatingApp");
|
|
||||||
|
|
||||||
/*
|
|
||||||
string tempDir = null;
|
|
||||||
|
|
||||||
var updateDir = new DirectoryInfo(IntegrationTestHelper.GetPath("..", "SampleUpdatingApp", "SampleReleasesFolder"));
|
|
||||||
|
|
||||||
var entriesToDownload = updateDir.GetFiles("*.nupkg")
|
|
||||||
.Select(x => ReleaseEntry.GenerateFromFile(x.FullName))
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
entriesToDownload.Count().ShouldBeGreaterThan(0);
|
|
||||||
|
|
||||||
using (Utility.WithTempDirectory(out tempDir)) {
|
|
||||||
// NB: This is normally done by CheckForUpdates, but since
|
|
||||||
// we're skipping that in the test we have to do it ourselves
|
|
||||||
Directory.CreateDirectory(Path.Combine(tempDir, "SampleUpdatingApp", "packages"));
|
|
||||||
|
|
||||||
var fixture = new UpdateManager(updateDir.FullName, "SampleUpdatingApp", tempDir);
|
|
||||||
using (fixture) {
|
|
||||||
var progress = new List<int>();
|
|
||||||
|
|
||||||
await fixture.DownloadReleases(entriesToDownload, progress.Add);
|
|
||||||
this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
|
||||||
|
|
||||||
progress
|
|
||||||
.Aggregate(0, (acc, x) => { x.ShouldBeGreaterThan(acc); return x; })
|
|
||||||
.ShouldEqual(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
entriesToDownload.ForEach(x => {
|
|
||||||
this.Log().Info("Looking for {0}", x.Filename);
|
|
||||||
var actualFile = Path.Combine(tempDir, "SampleUpdatingApp", "packages", x.Filename);
|
|
||||||
File.Exists(actualFile).ShouldBeTrue();
|
|
||||||
|
|
||||||
var actualEntry = ReleaseEntry.GenerateFromFile(actualFile);
|
|
||||||
actualEntry.SHA1.ShouldEqual(x.SHA1);
|
|
||||||
actualEntry.Version.ShouldEqual(x.Version);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
|
||||||
using Squirrel.CommandLine;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
using Xunit.Sdk;
|
|
||||||
|
|
||||||
[assembly: Xunit.TestFramework("Squirrel.Tests.TestsInit", "Squirrel.Tests")]
|
|
||||||
|
|
||||||
namespace Squirrel.Tests
|
|
||||||
{
|
|
||||||
public class TestsInit : XunitTestFramework
|
|
||||||
{
|
|
||||||
public TestsInit(IMessageSink messageSink)
|
|
||||||
: base(messageSink)
|
|
||||||
{
|
|
||||||
// Place initialization code here
|
|
||||||
var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location.Replace("file:///", ""));
|
|
||||||
HelperFile.AddSearchPath(Path.Combine(baseDir, "..", "..", "..", "..", "..", "vendor"));
|
|
||||||
HelperFile.AddSearchPath(Path.Combine(baseDir, "..", "..", "..", "..", "..", "vendor", "7zip"));
|
|
||||||
HelperFile.AddSearchPath(Path.Combine(baseDir, "..", "..", "..", "..", "..", "vendor", "wix"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,6 @@ using System.Linq;
|
|||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Squirrel.SimpleSplat;
|
|
||||||
|
|
||||||
namespace Squirrel.Tests.Legacy
|
namespace Squirrel.Tests.Legacy
|
||||||
{
|
{
|
||||||
@@ -25,7 +24,7 @@ namespace Squirrel.Tests.Legacy
|
|||||||
}
|
}
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class ReleaseEntry : IEnableLogger, IReleaseEntry
|
public class ReleaseEntry : IReleaseEntry
|
||||||
{
|
{
|
||||||
[DataMember] public string SHA1 { get; protected set; }
|
[DataMember] public string SHA1 { get; protected set; }
|
||||||
[DataMember] public string BaseUrl { get; protected set; }
|
[DataMember] public string BaseUrl { get; protected set; }
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
[assembly: CollectionBehavior(MaxParallelThreads=1, DisableTestParallelization=true)]
|
|
||||||
[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]
|
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
using Squirrel.CommandLine;
|
|
||||||
using Squirrel.Tests.TestHelpers;
|
using Squirrel.Tests.TestHelpers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@@ -190,88 +189,88 @@ namespace Squirrel.Tests
|
|||||||
ReleaseEntry.ParseReleaseEntry(entryAsString);
|
ReleaseEntry.ParseReleaseEntry(entryAsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
//[Fact]
|
||||||
public void GetLatestReleaseWithNullCollectionReturnsNull()
|
//public void GetLatestReleaseWithNullCollectionReturnsNull()
|
||||||
{
|
//{
|
||||||
Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
// Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
||||||
null, null, null, null));
|
// null, null, null, null));
|
||||||
}
|
//}
|
||||||
|
|
||||||
[Fact]
|
//[Fact]
|
||||||
public void GetLatestReleaseWithEmptyCollectionReturnsNull()
|
//public void GetLatestReleaseWithEmptyCollectionReturnsNull()
|
||||||
{
|
//{
|
||||||
Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
// Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
||||||
Enumerable.Empty<ReleaseEntry>(), null, null, null));
|
// Enumerable.Empty<ReleaseEntry>(), null, null, null));
|
||||||
}
|
//}
|
||||||
|
|
||||||
[Fact]
|
//[Fact]
|
||||||
public void WhenCurrentReleaseMatchesLastReleaseReturnNull()
|
//public void WhenCurrentReleaseMatchesLastReleaseReturnNull()
|
||||||
{
|
//{
|
||||||
var package = new ReleasePackageBuilder("Espera-1.7.6-beta.nupkg");
|
// var package = new ReleasePackageBuilder("Espera-1.7.6-beta.nupkg");
|
||||||
|
|
||||||
var releaseEntries = new[] {
|
// var releaseEntries = new[] {
|
||||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg"))
|
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg"))
|
||||||
};
|
// };
|
||||||
Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
// Assert.Null(ReleasePackageBuilder.GetPreviousRelease(
|
||||||
releaseEntries, package, @"C:\temp\somefolder", null));
|
// releaseEntries, package, @"C:\temp\somefolder", null));
|
||||||
}
|
//}
|
||||||
|
|
||||||
[Fact]
|
//[Fact]
|
||||||
public void WhenMultipleReleaseMatchesReturnEarlierResult()
|
//public void WhenMultipleReleaseMatchesReturnEarlierResult()
|
||||||
{
|
//{
|
||||||
var expected = SemanticVersion.Parse("1.7.5-beta");
|
// var expected = SemanticVersion.Parse("1.7.5-beta");
|
||||||
var package = new ReleasePackageBuilder("Espera-1.7.6-beta.nupkg");
|
// var package = new ReleasePackageBuilder("Espera-1.7.6-beta.nupkg");
|
||||||
|
|
||||||
var releaseEntries = new[] {
|
// var releaseEntries = new[] {
|
||||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg")),
|
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg")),
|
||||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg"))
|
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg"))
|
||||||
};
|
// };
|
||||||
|
|
||||||
var actual = ReleasePackageBuilder.GetPreviousRelease(
|
// var actual = ReleasePackageBuilder.GetPreviousRelease(
|
||||||
releaseEntries,
|
// releaseEntries,
|
||||||
package,
|
// package,
|
||||||
@"C:\temp\", null);
|
// @"C:\temp\", null);
|
||||||
|
|
||||||
Assert.Equal(expected, actual.Version);
|
// Assert.Equal(expected, actual.Version);
|
||||||
}
|
//}
|
||||||
|
|
||||||
[Fact]
|
//[Fact]
|
||||||
public void WhenMultipleReleasesFoundReturnPreviousVersion()
|
//public void WhenMultipleReleasesFoundReturnPreviousVersion()
|
||||||
{
|
//{
|
||||||
var expected = SemanticVersion.Parse("1.7.6-beta");
|
// var expected = SemanticVersion.Parse("1.7.6-beta");
|
||||||
var input = new ReleasePackageBuilder("Espera-1.7.7-beta.nupkg");
|
// var input = new ReleasePackageBuilder("Espera-1.7.7-beta.nupkg");
|
||||||
|
|
||||||
var releaseEntries = new[] {
|
// var releaseEntries = new[] {
|
||||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg")),
|
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg")),
|
||||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg"))
|
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg"))
|
||||||
};
|
// };
|
||||||
|
|
||||||
var actual = ReleasePackageBuilder.GetPreviousRelease(
|
// var actual = ReleasePackageBuilder.GetPreviousRelease(
|
||||||
releaseEntries,
|
// releaseEntries,
|
||||||
input,
|
// input,
|
||||||
@"C:\temp\", null);
|
// @"C:\temp\", null);
|
||||||
|
|
||||||
Assert.Equal(expected, actual.Version);
|
// Assert.Equal(expected, actual.Version);
|
||||||
}
|
//}
|
||||||
|
|
||||||
[Fact]
|
//[Fact]
|
||||||
public void WhenMultipleReleasesFoundInOtherOrderReturnPreviousVersion()
|
//public void WhenMultipleReleasesFoundInOtherOrderReturnPreviousVersion()
|
||||||
{
|
//{
|
||||||
var expected = SemanticVersion.Parse("1.7.6-beta");
|
// var expected = SemanticVersion.Parse("1.7.6-beta");
|
||||||
var input = new ReleasePackageBuilder("Espera-1.7.7-beta.nupkg");
|
// var input = new ReleasePackageBuilder("Espera-1.7.7-beta.nupkg");
|
||||||
|
|
||||||
var releaseEntries = new[] {
|
// var releaseEntries = new[] {
|
||||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg")),
|
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.5-beta.nupkg")),
|
||||||
ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg"))
|
// ReleaseEntry.ParseReleaseEntry(MockReleaseEntry("Espera-1.7.6-beta.nupkg"))
|
||||||
};
|
// };
|
||||||
|
|
||||||
var actual = ReleasePackageBuilder.GetPreviousRelease(
|
// var actual = ReleasePackageBuilder.GetPreviousRelease(
|
||||||
releaseEntries,
|
// releaseEntries,
|
||||||
input,
|
// input,
|
||||||
@"C:\temp\", null);
|
// @"C:\temp\", null);
|
||||||
|
|
||||||
Assert.Equal(expected, actual.Version);
|
// Assert.Equal(expected, actual.Version);
|
||||||
}
|
//}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WhenReleasesAreOutOfOrderSortByVersion()
|
public void WhenReleasesAreOutOfOrderSortByVersion()
|
||||||
|
|||||||
@@ -1,178 +0,0 @@
|
|||||||
using System.Runtime.Versioning;
|
|
||||||
using Squirrel.MarkdownSharp;
|
|
||||||
using Squirrel;
|
|
||||||
using Squirrel.Tests.TestHelpers;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
using Squirrel.SimpleSplat;
|
|
||||||
using Xunit;
|
|
||||||
using Squirrel.NuGet;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
using NuGet.Versioning;
|
|
||||||
using Squirrel.CommandLine;
|
|
||||||
|
|
||||||
namespace Squirrel.Tests
|
|
||||||
{
|
|
||||||
public class CreateReleasePackageTests : TestLoggingBase
|
|
||||||
{
|
|
||||||
public CreateReleasePackageTests(ITestOutputHelper log) : base(log)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("1.2.3")]
|
|
||||||
[InlineData("1.2.3-alpha13")]
|
|
||||||
[InlineData("1.2.3-alpha135")]
|
|
||||||
[InlineData("0.0.1")]
|
|
||||||
[InlineData("1.299656.3-alpha")]
|
|
||||||
public void SemanticVersionParsesValidVersion(string ver)
|
|
||||||
{
|
|
||||||
NugetUtil.ThrowIfVersionNotSemverCompliant(ver);
|
|
||||||
Assert.True(SemanticVersion.TryParse(ver, out var _));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData("")]
|
|
||||||
[InlineData("1")]
|
|
||||||
[InlineData("0")]
|
|
||||||
[InlineData("1.2.3.4")]
|
|
||||||
[InlineData("1.2.3.4-alpha")]
|
|
||||||
[InlineData("0.0.0.0")]
|
|
||||||
[InlineData("0.0.0")]
|
|
||||||
[InlineData("0.0")]
|
|
||||||
[InlineData("0.0.0-alpha")]
|
|
||||||
public void SemanticVersionThrowsInvalidVersion(string ver)
|
|
||||||
{
|
|
||||||
Assert.ThrowsAny<Exception>(() => NugetUtil.ThrowIfVersionNotSemverCompliant(ver));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ReleasePackageIntegrationTest()
|
|
||||||
{
|
|
||||||
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Tests.0.1.0-pre.nupkg");
|
|
||||||
var outputPackage = Path.GetTempFileName() + ".nupkg";
|
|
||||||
|
|
||||||
var fixture = new ReleasePackageBuilder(inputPackage);
|
|
||||||
|
|
||||||
try {
|
|
||||||
fixture.CreateReleasePackage(outputPackage);
|
|
||||||
|
|
||||||
this.Log().Info("Resulting package is at {0}", outputPackage);
|
|
||||||
var pkg = new ZipPackage(outputPackage);
|
|
||||||
|
|
||||||
int refs = pkg.FrameworkAssemblies.Count();
|
|
||||||
this.Log().Info("Found {0} refs", refs);
|
|
||||||
refs.ShouldEqual(0);
|
|
||||||
|
|
||||||
this.Log().Info("Files in release package:");
|
|
||||||
|
|
||||||
List<ZipPackageFile> files = pkg.Files.ToList();
|
|
||||||
files.ForEach(x => this.Log().Info(x.Path));
|
|
||||||
|
|
||||||
List<string> nonDesktopPaths = new[] { "sl", "winrt", "netcore", "win8", "windows8", "MonoAndroid", "MonoTouch", "MonoMac", "wp", }
|
|
||||||
.Select(x => @"lib\" + x)
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
files.Any(x => nonDesktopPaths.Any(y => x.Path.ToLowerInvariant().Contains(y.ToLowerInvariant()))).ShouldBeFalse();
|
|
||||||
files.Any(x => x.Path.ToLowerInvariant().EndsWith(@".xml")).ShouldBeFalse();
|
|
||||||
} finally {
|
|
||||||
File.Delete(outputPackage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CanLoadPackageWhichHasNoDependencies()
|
|
||||||
{
|
|
||||||
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.NoDependencies.1.0.0.0.nupkg");
|
|
||||||
var outputPackage = Path.GetTempFileName() + ".nupkg";
|
|
||||||
var fixture = new ReleasePackageBuilder(inputPackage);
|
|
||||||
try {
|
|
||||||
fixture.CreateReleasePackage(outputPackage);
|
|
||||||
} finally {
|
|
||||||
File.Delete(outputPackage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ThrowsIfLoadsPackageWithDependencies()
|
|
||||||
{
|
|
||||||
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectDependsOnJsonDotNet.1.0.nupkg");
|
|
||||||
var outputPackage = Path.GetTempFileName() + ".nupkg";
|
|
||||||
var fixture = new ReleasePackageBuilder(inputPackage);
|
|
||||||
try {
|
|
||||||
Assert.Throws<InvalidOperationException>(() => fixture.CreateReleasePackage(outputPackage));
|
|
||||||
} finally {
|
|
||||||
if (File.Exists(outputPackage))
|
|
||||||
File.Delete(outputPackage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SpecFileMarkdownRenderingTest()
|
|
||||||
{
|
|
||||||
var dontcare = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nupkg");
|
|
||||||
var inputSpec = IntegrationTestHelper.GetPath("fixtures", "Squirrel.Core.1.1.0.0.nuspec");
|
|
||||||
var fixture = new ReleasePackageBuilder(dontcare);
|
|
||||||
|
|
||||||
var targetFile = Path.GetTempFileName();
|
|
||||||
File.Copy(inputSpec, targetFile, true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
var processor = new Func<string, string>(input =>
|
|
||||||
(new Markdown()).Transform(input));
|
|
||||||
|
|
||||||
// NB: For No Reason At All, renderReleaseNotesMarkdown is
|
|
||||||
// invulnerable to ExposedObject. Whyyyyyyyyy
|
|
||||||
var renderMinfo = fixture.GetType().GetMethod("renderReleaseNotesMarkdown",
|
|
||||||
BindingFlags.NonPublic | BindingFlags.Instance);
|
|
||||||
renderMinfo.Invoke(fixture, new object[] { targetFile, processor });
|
|
||||||
|
|
||||||
var mani = NuspecManifest.ParseFromFile(targetFile);
|
|
||||||
this.Log().Info("HTML Text:\n{0}", mani.ReleaseNotesHtml);
|
|
||||||
|
|
||||||
mani.ReleaseNotes.Contains("## Release Notes").ShouldBeTrue();
|
|
||||||
mani.ReleaseNotesHtml.Contains("## Release Notes").ShouldBeFalse();
|
|
||||||
mani.ReleaseNotesHtml.Contains("<h2>Release Notes").ShouldBeTrue();
|
|
||||||
} finally {
|
|
||||||
File.Delete(targetFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void ContentFilesAreIncludedInCreatedPackage()
|
|
||||||
{
|
|
||||||
var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectWithContent.1.0.0.0-beta.nupkg");
|
|
||||||
var outputPackage = Path.GetTempFileName() + ".zip";
|
|
||||||
var fixture = new ReleasePackageBuilder(inputPackage);
|
|
||||||
|
|
||||||
try {
|
|
||||||
fixture.CreateReleasePackage(outputPackage);
|
|
||||||
|
|
||||||
this.Log().Info("Resulting package is at {0}", outputPackage);
|
|
||||||
var pkg = new ZipPackage(outputPackage);
|
|
||||||
|
|
||||||
int refs = pkg.FrameworkAssemblies.Count();
|
|
||||||
this.Log().Info("Found {0} refs", refs);
|
|
||||||
refs.ShouldEqual(0);
|
|
||||||
|
|
||||||
this.Log().Info("Files in release package:");
|
|
||||||
|
|
||||||
var contentFiles = pkg.Files.Where(f => f.IsContentFile()).ToArray();
|
|
||||||
Assert.Equal(2, contentFiles.Count());
|
|
||||||
|
|
||||||
var contentFilePaths = contentFiles.Select(f => f.EffectivePath);
|
|
||||||
|
|
||||||
Assert.Contains("some-words.txt", contentFilePaths);
|
|
||||||
Assert.Contains("dir\\item-in-subdirectory.txt", contentFilePaths);
|
|
||||||
|
|
||||||
Assert.Equal(1, pkg.Files.Where(f => f.IsLibFile()).Count());
|
|
||||||
} finally {
|
|
||||||
File.Delete(outputPackage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,13 +7,11 @@ namespace Squirrel.Tests
|
|||||||
{
|
{
|
||||||
public class RuntimeTests
|
public class RuntimeTests
|
||||||
{
|
{
|
||||||
// we are upgrading net6 to a minimum version of 6.0.2 to work
|
|
||||||
// around a dotnet SDK bug right now.
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("net6", "net6.0.2-x64-desktop")]
|
[InlineData("net6", "net6-x64-desktop")]
|
||||||
[InlineData("net6.0", "net6.0.2-x64-desktop")]
|
[InlineData("net6.0", "net6-x64-desktop")]
|
||||||
[InlineData("net6-x64", "net6.0.2-x64-desktop")]
|
[InlineData("net6-x64", "net6-x64-desktop")]
|
||||||
[InlineData("net6-x86", "net6.0.2-x86-desktop")]
|
[InlineData("net6-x86", "net6-x86-desktop")]
|
||||||
[InlineData("net3.1", "netcoreapp3.1-x64-desktop")]
|
[InlineData("net3.1", "netcoreapp3.1-x64-desktop")]
|
||||||
[InlineData("netcoreapp3.1", "netcoreapp3.1-x64-desktop")]
|
[InlineData("netcoreapp3.1", "netcoreapp3.1-x64-desktop")]
|
||||||
[InlineData("net3.1-x86", "netcoreapp3.1-x86-desktop")]
|
[InlineData("net3.1-x86", "netcoreapp3.1-x86-desktop")]
|
||||||
@@ -21,7 +19,7 @@ namespace Squirrel.Tests
|
|||||||
[InlineData("net6.0.2-x86", "net6.0.2-x86-desktop")]
|
[InlineData("net6.0.2-x86", "net6.0.2-x86-desktop")]
|
||||||
[InlineData("net6.0.1-x86", "net6.0.1-x86-desktop")]
|
[InlineData("net6.0.1-x86", "net6.0.1-x86-desktop")]
|
||||||
[InlineData("net6.0.0", "net6-x64-desktop")]
|
[InlineData("net6.0.0", "net6-x64-desktop")]
|
||||||
[InlineData("net6.0-x64-desktop", "net6.0.2-x64-desktop")]
|
[InlineData("net6.0-x64-desktop", "net6-x64-desktop")]
|
||||||
[InlineData("net7.0-x64-runtime", "net7-x64-runtime")]
|
[InlineData("net7.0-x64-runtime", "net7-x64-runtime")]
|
||||||
[InlineData("net7.0-x64-asp", "net7-x64-asp")]
|
[InlineData("net7.0-x64-asp", "net7-x64-asp")]
|
||||||
[InlineData("net7.0-desktop", "net7-x64-desktop")]
|
[InlineData("net7.0-desktop", "net7-x64-desktop")]
|
||||||
|
|||||||
@@ -20,10 +20,12 @@
|
|||||||
<PackageReference Include="xunit" Version="2.6.3" />
|
<PackageReference Include="xunit" Version="2.6.3" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5" PrivateAssets="All" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5" PrivateAssets="All" />
|
||||||
<PackageReference Include="System.IO.Packaging" Version="8.0.0" />
|
<PackageReference Include="System.IO.Packaging" Version="8.0.0" />
|
||||||
|
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
|
||||||
|
<PackageReference Include="Divergic.Logging.Xunit" Version="4.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\Squirrel.CommandLine\Squirrel.CommandLine.csproj" />
|
<ProjectReference Include="..\..\src\Squirrel\Squirrel.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Squirrel.Tests.TestHelpers;
|
|
||||||
using Xunit;
|
|
||||||
|
|
||||||
namespace Squirrel.Tests
|
|
||||||
{
|
|
||||||
public class SquirrelAwareExecutableDetectorTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public void AtomShellShouldBeSquirrelAware()
|
|
||||||
{
|
|
||||||
var target = IntegrationTestHelper.GetPath("fixtures", "atom.exe");
|
|
||||||
|
|
||||||
Assert.True(File.Exists(target));
|
|
||||||
Assert.True(SquirrelAwareExecutableDetector.GetSquirrelAwareVersion(target) == 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SquirrelAwareViaLanguageNeutralVersionBlock()
|
|
||||||
{
|
|
||||||
var target = IntegrationTestHelper.GetPath("fixtures", "SquirrelAwareTweakedNetCoreApp.exe");
|
|
||||||
Assert.True(File.Exists(target));
|
|
||||||
|
|
||||||
var ret = SquirrelAwareExecutableDetector.GetSquirrelAwareVersion(target);
|
|
||||||
Assert.Equal(1, ret.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void NotSquirrelAwareTestAppShouldNotBeSquirrelAware()
|
|
||||||
{
|
|
||||||
var target = IntegrationTestHelper.GetPath("fixtures", "NotSquirrelAwareApp.exe");
|
|
||||||
Assert.True(File.Exists(target));
|
|
||||||
|
|
||||||
Assert.Null(SquirrelAwareExecutableDetector.GetSquirrelAwareVersion(target));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void SquirrelAwareViaManifest()
|
|
||||||
{
|
|
||||||
var target = IntegrationTestHelper.GetPath("fixtures", "PublishSingleFileAwareApp.exe");
|
|
||||||
Assert.True(File.Exists(target));
|
|
||||||
|
|
||||||
var ret = SquirrelAwareExecutableDetector.GetSquirrelAwareVersion(target);
|
|
||||||
Assert.Equal(1, ret);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,10 +5,8 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Squirrel;
|
using Squirrel;
|
||||||
using Squirrel.SimpleSplat;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Squirrel.CommandLine;
|
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
|
||||||
namespace Squirrel.Tests.TestHelpers
|
namespace Squirrel.Tests.TestHelpers
|
||||||
@@ -70,42 +68,42 @@ namespace Squirrel.Tests.TestHelpers
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string CreateFakeInstalledApp(string version, string outputDir, string nuspecFile = null)
|
//public static string CreateFakeInstalledApp(string version, string outputDir, string nuspecFile = null)
|
||||||
{
|
//{
|
||||||
string targetDir;
|
// string targetDir;
|
||||||
|
|
||||||
nuspecFile = nuspecFile ?? "SquirrelInstalledApp.nuspec";
|
|
||||||
|
|
||||||
using (var clearTemp = Utility.GetTempDirectory(out targetDir)) {
|
// nuspecFile = nuspecFile ?? "SquirrelInstalledApp.nuspec";
|
||||||
var nuspec = File.ReadAllText(IntegrationTestHelper.GetPath("fixtures", nuspecFile), Encoding.UTF8);
|
|
||||||
var nuspecPath = Path.Combine(targetDir, nuspecFile);
|
|
||||||
|
|
||||||
File.WriteAllText(nuspecPath, nuspec.Replace("0.1.0", version), Encoding.UTF8);
|
// using (var clearTemp = Utility.GetTempDirectory(out targetDir)) {
|
||||||
|
// var nuspec = File.ReadAllText(IntegrationTestHelper.GetPath("fixtures", nuspecFile), Encoding.UTF8);
|
||||||
|
// var nuspecPath = Path.Combine(targetDir, nuspecFile);
|
||||||
|
|
||||||
File.Copy(
|
// File.WriteAllText(nuspecPath, nuspec.Replace("0.1.0", version), Encoding.UTF8);
|
||||||
IntegrationTestHelper.GetPath("fixtures", "PublishSingleFileAwareApp.exe"),
|
|
||||||
Path.Combine(targetDir, "SquirrelAwareApp.exe"));
|
|
||||||
File.Copy(
|
|
||||||
IntegrationTestHelper.GetPath("fixtures", "NotSquirrelAwareApp.exe"),
|
|
||||||
Path.Combine(targetDir, "NotSquirrelAwareApp.exe"));
|
|
||||||
|
|
||||||
new NugetConsole().Pack(nuspecPath, targetDir, targetDir);
|
// File.Copy(
|
||||||
|
// IntegrationTestHelper.GetPath("fixtures", "PublishSingleFileAwareApp.exe"),
|
||||||
|
// Path.Combine(targetDir, "SquirrelAwareApp.exe"));
|
||||||
|
// File.Copy(
|
||||||
|
// IntegrationTestHelper.GetPath("fixtures", "NotSquirrelAwareApp.exe"),
|
||||||
|
// Path.Combine(targetDir, "NotSquirrelAwareApp.exe"));
|
||||||
|
|
||||||
var di = new DirectoryInfo(targetDir);
|
// new NugetConsole().Pack(nuspecPath, targetDir, targetDir);
|
||||||
var pkg = di.EnumerateFiles("*.nupkg").First();
|
|
||||||
|
|
||||||
var targetPkgFile = Path.Combine(outputDir, pkg.Name);
|
// var di = new DirectoryInfo(targetDir);
|
||||||
File.Copy(pkg.FullName, targetPkgFile);
|
// var pkg = di.EnumerateFiles("*.nupkg").First();
|
||||||
return targetPkgFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void CreateNewVersionInPackageDir(string version, string outputDir, string nuspecFile = null)
|
// var targetPkgFile = Path.Combine(outputDir, pkg.Name);
|
||||||
{
|
// File.Copy(pkg.FullName, targetPkgFile);
|
||||||
var pkgFile = CreateFakeInstalledApp(version, outputDir, nuspecFile);
|
// return targetPkgFile;
|
||||||
var pkgs = ReleaseEntry.BuildReleasesFile(outputDir);
|
// }
|
||||||
ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(outputDir, "RELEASES"));
|
//}
|
||||||
}
|
|
||||||
|
//public static void CreateNewVersionInPackageDir(string version, string outputDir, string nuspecFile = null)
|
||||||
|
//{
|
||||||
|
// var pkgFile = CreateFakeInstalledApp(version, outputDir, nuspecFile);
|
||||||
|
// var pkgs = ReleaseEntry.BuildReleasesFile(outputDir);
|
||||||
|
// ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(outputDir, "RELEASES"));
|
||||||
|
//}
|
||||||
|
|
||||||
public static IDisposable WithFakeInstallDirectory(out string path)
|
public static IDisposable WithFakeInstallDirectory(out string path)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Squirrel.SimpleSplat;
|
|
||||||
using Xunit.Abstractions;
|
|
||||||
|
|
||||||
namespace Squirrel.Tests
|
|
||||||
{
|
|
||||||
public interface ITestLogging
|
|
||||||
{
|
|
||||||
IFullLogger Log();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TestLogger : ILogger
|
|
||||||
{
|
|
||||||
public LogLevel Level { get; set; }
|
|
||||||
public ITestOutputHelper OutputHelper { get; }
|
|
||||||
|
|
||||||
public TestLogger(ITestOutputHelper outputHelper)
|
|
||||||
{
|
|
||||||
OutputHelper = outputHelper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Write([Localizable(false)] string message, LogLevel logLevel)
|
|
||||||
{
|
|
||||||
OutputHelper.WriteLine(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class TestLoggingBase : ITestLogging
|
|
||||||
{
|
|
||||||
public ITestOutputHelper OutputHelper { get; }
|
|
||||||
public IFullLogger Logger { get; }
|
|
||||||
|
|
||||||
public TestLoggingBase(ITestOutputHelper log)
|
|
||||||
{
|
|
||||||
OutputHelper = log;
|
|
||||||
Logger = new WrappingFullLogger(new TestLogger(OutputHelper), typeof(TestLogger));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IFullLogger Log()
|
|
||||||
{
|
|
||||||
return Logger;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Squirrel.Sources;
|
|
||||||
|
|
||||||
namespace Squirrel.Tests.TestHelpers
|
|
||||||
{
|
|
||||||
class UpdateManagerTestImpl : UpdateManager
|
|
||||||
{
|
|
||||||
protected UpdateManagerTestImpl(IUpdateSource source, AppDesc config) : base(source, config)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UpdateManagerTestImpl FromLocalPackageTempDir(string updatePackageDir, string appId, string installTempDir)
|
|
||||||
{
|
|
||||||
var di = String.IsNullOrWhiteSpace(updatePackageDir) ? null : new DirectoryInfo(updatePackageDir);
|
|
||||||
return FromLocalPackageTempDir(di, appId, installTempDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UpdateManagerTestImpl FromLocalPackageTempDir(DirectoryInfo updatePackageDir, string appId, string installTempDir)
|
|
||||||
{
|
|
||||||
var appPath = Path.Combine(installTempDir, appId);
|
|
||||||
Directory.CreateDirectory(appPath);
|
|
||||||
var desc = new AppDescWindows(appPath, appId);
|
|
||||||
return new UpdateManagerTestImpl(new SimpleFileSource(updatePackageDir), desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UpdateManagerTestImpl FromFakeWebSource(string packageUrl, string appId, string installTempDir, IFileDownloader downloader = null)
|
|
||||||
{
|
|
||||||
var appPath = Path.Combine(installTempDir, appId);
|
|
||||||
Directory.CreateDirectory(appPath);
|
|
||||||
var desc = new AppDescWindows(appPath, appId);
|
|
||||||
return new UpdateManagerTestImpl(new SimpleWebSource(packageUrl, downloader), desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<string> ApplyReleasesPublic(UpdateInfo updateInfo, bool silentInstall, bool attemptingFullInstall, Action<int> progress = null)
|
|
||||||
{
|
|
||||||
return this.ApplyReleases(updateInfo, silentInstall, attemptingFullInstall, progress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
527
test/Squirrel.Tests/UpdateManager/ApplyReleasesTests.cs
Normal file
527
test/Squirrel.Tests/UpdateManager/ApplyReleasesTests.cs
Normal file
@@ -0,0 +1,527 @@
|
|||||||
|
//using System;
|
||||||
|
//using System.Collections.Generic;
|
||||||
|
//using System.Diagnostics;
|
||||||
|
//using System.IO;
|
||||||
|
//using System.Linq;
|
||||||
|
//using System.Reflection;
|
||||||
|
//using System.Text;
|
||||||
|
//using System.Threading;
|
||||||
|
//using System.Threading.Tasks;
|
||||||
|
//using NuGet.Versioning;
|
||||||
|
//using Squirrel.NuGet;
|
||||||
|
//using Squirrel.Tests.TestHelpers;
|
||||||
|
//using Xunit;
|
||||||
|
//using Xunit.Abstractions;
|
||||||
|
|
||||||
|
//namespace Squirrel.Tests
|
||||||
|
//{
|
||||||
|
// public class ApplyReleasesTests : TestLoggingBase
|
||||||
|
// {
|
||||||
|
// public ApplyReleasesTests(ITestOutputHelper log) : base(log)
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public const string APP_ID = "theFakeApp";
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task CleanInstallRunsSquirrelAwareAppsWithInstallFlag()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||||
|
|
||||||
|
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir);
|
||||||
|
// await fixture.FullInstall();
|
||||||
|
|
||||||
|
// // NB: We execute the Squirrel-aware apps, so we need to give
|
||||||
|
// // them a minute to settle or else the using statement will
|
||||||
|
// // try to blow away a running process
|
||||||
|
// await Task.Delay(1000);
|
||||||
|
|
||||||
|
// Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "current", "args2.txt")));
|
||||||
|
// Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "current", "args.txt")));
|
||||||
|
|
||||||
|
// var text = File.ReadAllText(Path.Combine(tempDir, APP_ID, "current", "args.txt"), Encoding.UTF8);
|
||||||
|
// Assert.Contains("firstrun", text);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task UpgradeRunsSquirrelAwareAppsWithUpgradeFlag()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||||
|
|
||||||
|
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||||
|
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||||
|
// await fixture.FullInstall();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// await Task.Delay(1000);
|
||||||
|
|
||||||
|
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
||||||
|
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||||
|
// await fixture.UpdateApp();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// await Task.Delay(1000);
|
||||||
|
|
||||||
|
// Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args2.txt")));
|
||||||
|
// Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args.txt")));
|
||||||
|
|
||||||
|
// var text = File.ReadAllText(Path.Combine(tempDir, APP_ID, "staging", "app-0.2.0", "args.txt"), Encoding.UTF8);
|
||||||
|
// Assert.Contains("updated", text);
|
||||||
|
// Assert.Contains("0.2.0", text);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task RunningUpgradeAppTwiceDoesntCrash()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||||
|
|
||||||
|
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||||
|
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||||
|
// await fixture.FullInstall();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// await Task.Delay(1000);
|
||||||
|
|
||||||
|
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
||||||
|
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||||
|
// await fixture.UpdateApp();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// await Task.Delay(1000);
|
||||||
|
|
||||||
|
// // NB: The 2nd time we won't have any updates to apply. We should just do nothing!
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||||
|
// await fixture.UpdateApp();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// await Task.Delay(1000);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task FullUninstallRemovesAllVersions()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||||
|
|
||||||
|
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||||
|
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||||
|
// await fixture.FullInstall();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// await Task.Delay(1000);
|
||||||
|
|
||||||
|
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.2.0", remotePkgDir);
|
||||||
|
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||||
|
// await fixture.UpdateApp();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// await Task.Delay(1000);
|
||||||
|
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir)) {
|
||||||
|
// await fixture.FullUninstall();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "app-0.1.0", "args.txt")));
|
||||||
|
// Assert.False(File.Exists(Path.Combine(tempDir, APP_ID, "app-0.2.0", "args.txt")));
|
||||||
|
// Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, ".dead")));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task CanInstallAndUpdatePackageWithDotsInId()
|
||||||
|
// {
|
||||||
|
// string tempDir;
|
||||||
|
// string remotePkgDir;
|
||||||
|
// const string pkgName = "Squirrel.Installed.App";
|
||||||
|
|
||||||
|
// using (Utility.GetTempDirectory(out tempDir))
|
||||||
|
// using (Utility.GetTempDirectory(out remotePkgDir)) {
|
||||||
|
// // install 0.1.0
|
||||||
|
// IntegrationTestHelper.CreateFakeInstalledApp("0.1.0", remotePkgDir, "SquirrelInstalledAppWithDots.nuspec");
|
||||||
|
// var pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
|
||||||
|
// ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
|
||||||
|
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
||||||
|
// await fixture.FullInstall();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "app-0.1.0")));
|
||||||
|
// Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "current")));
|
||||||
|
|
||||||
|
// var info = new AppDescWindows(Path.Combine(tempDir, pkgName), pkgName);
|
||||||
|
|
||||||
|
// var version = info.GetVersions().Single();
|
||||||
|
// Assert.True(version.IsCurrent);
|
||||||
|
// Assert.Equal(new SemanticVersion(0, 1, 0), version.Manifest.Version);
|
||||||
|
|
||||||
|
// await Task.Delay(1000);
|
||||||
|
// Assert.True(File.ReadAllText(Path.Combine(version.DirectoryPath, "args.txt")).Contains("--squirrel-firstrun"));
|
||||||
|
|
||||||
|
// // update top 0.2.0
|
||||||
|
// IntegrationTestHelper.CreateFakeInstalledApp("0.2.0", remotePkgDir, "SquirrelInstalledAppWithDots.nuspec");
|
||||||
|
// pkgs = ReleaseEntry.BuildReleasesFile(remotePkgDir);
|
||||||
|
// ReleaseEntry.WriteReleaseFile(pkgs, Path.Combine(remotePkgDir, "RELEASES"));
|
||||||
|
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
||||||
|
// await fixture.UpdateApp();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// info.UpdateAndRetrieveCurrentFolder(false);
|
||||||
|
|
||||||
|
// var versions = info.GetVersions().ToArray();
|
||||||
|
// Assert.Equal(2, versions.Count());
|
||||||
|
// Assert.Equal(new SemanticVersion(0, 2, 0), versions.Single(s => s.IsCurrent).Version);
|
||||||
|
|
||||||
|
// //Assert.True(Directory.Exists(Path.Combine(tempDir, pkgName, "app-0.2.0")));
|
||||||
|
// await Task.Delay(1000);
|
||||||
|
|
||||||
|
// // uninstall
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, pkgName, tempDir)) {
|
||||||
|
// await fixture.FullUninstall();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Assert.False(File.Exists(Path.Combine(tempDir, pkgName, "app-0.1.0", "args.txt")));
|
||||||
|
// Assert.False(File.Exists(Path.Combine(tempDir, pkgName, "app-0.2.0", "args.txt")));
|
||||||
|
// Assert.True(File.Exists(Path.Combine(tempDir, pkgName, ".dead")));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void WhenNoNewReleasesAreAvailableTheListIsEmpty()
|
||||||
|
// {
|
||||||
|
// using var _ = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
|
||||||
|
// var appDir = Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
||||||
|
// var packages = Path.Combine(appDir.FullName, "packages");
|
||||||
|
// Directory.CreateDirectory(packages);
|
||||||
|
|
||||||
|
// var package = "Squirrel.Core.1.0.0.0-full.nupkg";
|
||||||
|
// File.Copy(IntegrationTestHelper.GetPath("fixtures", package), Path.Combine(packages, package));
|
||||||
|
|
||||||
|
// var aGivenPackage = Path.Combine(packages, package);
|
||||||
|
// var baseEntry = ReleaseEntry.GenerateFromFile(aGivenPackage);
|
||||||
|
|
||||||
|
// var updateInfo = UpdateInfo.Create(baseEntry, new[] { baseEntry }, "dontcare");
|
||||||
|
|
||||||
|
// Assert.Empty(updateInfo.ReleasesToApply);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void ThrowsWhenOnlyDeltaReleasesAreAvailable()
|
||||||
|
// {
|
||||||
|
// string tempDir;
|
||||||
|
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||||
|
// var appDir = Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
||||||
|
// var packages = Path.Combine(appDir.FullName, "packages");
|
||||||
|
// Directory.CreateDirectory(packages);
|
||||||
|
|
||||||
|
// var baseFile = "Squirrel.Core.1.0.0.0-full.nupkg";
|
||||||
|
// File.Copy(IntegrationTestHelper.GetPath("fixtures", baseFile),
|
||||||
|
// Path.Combine(packages, baseFile));
|
||||||
|
// var basePackage = Path.Combine(packages, baseFile);
|
||||||
|
// var baseEntry = ReleaseEntry.GenerateFromFile(basePackage);
|
||||||
|
|
||||||
|
// var deltaFile = "Squirrel.Core.1.1.0.0-delta.nupkg";
|
||||||
|
// File.Copy(IntegrationTestHelper.GetPath("fixtures", deltaFile),
|
||||||
|
// Path.Combine(packages, deltaFile));
|
||||||
|
// var deltaPackage = Path.Combine(packages, deltaFile);
|
||||||
|
// var deltaEntry = ReleaseEntry.GenerateFromFile(deltaPackage);
|
||||||
|
|
||||||
|
// Assert.Throws<Exception>(
|
||||||
|
// () => UpdateInfo.Create(baseEntry, new[] { deltaEntry }, "dontcare"));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task ApplyReleasesWithOneReleaseFile()
|
||||||
|
// {
|
||||||
|
// string tempDir;
|
||||||
|
|
||||||
|
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||||
|
// string appDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
// string packagesDir = Path.Combine(appDir, "packages");
|
||||||
|
// Directory.CreateDirectory(packagesDir);
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||||
|
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||||
|
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||||
|
|
||||||
|
// var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.0.0.0-full.nupkg"));
|
||||||
|
// var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||||
|
|
||||||
|
// var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
||||||
|
// updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var progress = new List<int>();
|
||||||
|
|
||||||
|
// await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||||
|
// this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||||
|
|
||||||
|
// progress
|
||||||
|
// .Aggregate(0, (acc, x) => {
|
||||||
|
// (x >= acc).ShouldBeTrue();
|
||||||
|
// return x;
|
||||||
|
// })
|
||||||
|
// .ShouldEqual(100);
|
||||||
|
|
||||||
|
// var filesToFind = new[] {
|
||||||
|
// new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||||
|
// new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||||
|
// };
|
||||||
|
|
||||||
|
// filesToFind.ForEach(x => {
|
||||||
|
// var path = Path.Combine(tempDir, APP_ID, "staging", "app-1.1.0.0", x.Name);
|
||||||
|
// this.Log().Info("Looking for {0}", path);
|
||||||
|
// File.Exists(path).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var vi = FileVersionInfo.GetVersionInfo(path);
|
||||||
|
// var verInfo = new Version(vi.FileVersion ?? "1.0.0.0");
|
||||||
|
// x.Version.ShouldEqual(verInfo);
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task ApplyReleaseWhichRemovesAFile()
|
||||||
|
// {
|
||||||
|
// string tempDir;
|
||||||
|
|
||||||
|
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||||
|
// string appDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
// string packagesDir = Path.Combine(appDir, "packages");
|
||||||
|
// Directory.CreateDirectory(packagesDir);
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||||
|
// "Squirrel.Core.1.2.0.0-full.nupkg",
|
||||||
|
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||||
|
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||||
|
|
||||||
|
// var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||||
|
// var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.2.0.0-full.nupkg"));
|
||||||
|
|
||||||
|
// var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
||||||
|
// updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var progress = new List<int>();
|
||||||
|
// await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||||
|
// this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||||
|
|
||||||
|
// progress
|
||||||
|
// .Aggregate(0, (acc, x) => {
|
||||||
|
// (x >= acc).ShouldBeTrue();
|
||||||
|
// return x;
|
||||||
|
// })
|
||||||
|
// .ShouldEqual(100);
|
||||||
|
|
||||||
|
// var rootDirectory = Path.Combine(tempDir, APP_ID, "staging", "app-1.2.0.0");
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||||
|
// new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||||
|
// }.ForEach(x => {
|
||||||
|
// var path = Path.Combine(rootDirectory, x.Name);
|
||||||
|
// this.Log().Info("Looking for {0}", path);
|
||||||
|
// File.Exists(path).ShouldBeTrue();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// var removedFile = Path.Combine("sub", "Ionic.Zip.dll");
|
||||||
|
// var deployedPath = Path.Combine(rootDirectory, removedFile);
|
||||||
|
// File.Exists(deployedPath).ShouldBeFalse();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task ApplyReleaseWhichMovesAFileToADifferentDirectory()
|
||||||
|
// {
|
||||||
|
// string tempDir;
|
||||||
|
|
||||||
|
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||||
|
// string appDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
// string packagesDir = Path.Combine(appDir, "packages");
|
||||||
|
// Directory.CreateDirectory(packagesDir);
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||||
|
// "Squirrel.Core.1.3.0.0-full.nupkg",
|
||||||
|
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||||
|
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||||
|
|
||||||
|
// var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||||
|
// var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.3.0.0-full.nupkg"));
|
||||||
|
|
||||||
|
// var updateInfo = UpdateInfo.Create(baseEntry, new[] { latestFullEntry }, packagesDir);
|
||||||
|
// updateInfo.ReleasesToApply.Contains(latestFullEntry).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var progress = new List<int>();
|
||||||
|
// await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||||
|
// this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||||
|
|
||||||
|
// progress
|
||||||
|
// .Aggregate(0, (acc, x) => {
|
||||||
|
// (x >= acc).ShouldBeTrue();
|
||||||
|
// return x;
|
||||||
|
// })
|
||||||
|
// .ShouldEqual(100);
|
||||||
|
|
||||||
|
// var rootDirectory = Path.Combine(tempDir, APP_ID, "staging", "app-1.3.0.0");
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||||
|
// new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||||
|
// }.ForEach(x => {
|
||||||
|
// var path = Path.Combine(rootDirectory, x.Name);
|
||||||
|
// this.Log().Info("Looking for {0}", path);
|
||||||
|
// File.Exists(path).ShouldBeTrue();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// var oldFile = Path.Combine(rootDirectory, "sub", "Ionic.Zip.dll");
|
||||||
|
// File.Exists(oldFile).ShouldBeFalse();
|
||||||
|
|
||||||
|
// var newFile = Path.Combine(rootDirectory, "other", "Ionic.Zip.dll");
|
||||||
|
// File.Exists(newFile).ShouldBeTrue();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task ApplyReleasesWithDeltaReleases()
|
||||||
|
// {
|
||||||
|
// string tempDir;
|
||||||
|
|
||||||
|
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||||
|
// string appDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
// string packagesDir = Path.Combine(appDir, "packages");
|
||||||
|
// Directory.CreateDirectory(packagesDir);
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||||
|
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(packagesDir, x)));
|
||||||
|
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||||
|
|
||||||
|
// var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.0.0.0-full.nupkg"));
|
||||||
|
// var deltaEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-delta.nupkg"));
|
||||||
|
// var latestFullEntry = ReleaseEntry.GenerateFromFile(Path.Combine(packagesDir, "Squirrel.Core.1.1.0.0-full.nupkg"));
|
||||||
|
|
||||||
|
// var updateInfo = UpdateInfo.Create(baseEntry, new[] { deltaEntry, latestFullEntry }, packagesDir);
|
||||||
|
// updateInfo.ReleasesToApply.Contains(deltaEntry).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var progress = new List<int>();
|
||||||
|
|
||||||
|
// await fixture.ApplyReleasesPublic(updateInfo, false, false, progress.Add);
|
||||||
|
// this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||||
|
|
||||||
|
// // TODO: this is failing intermittently, not sure why but is not a big deal atm
|
||||||
|
// // progress
|
||||||
|
// // .Aggregate(0, (acc, x) => { (x >= acc).ShouldBeTrue(); return x; })
|
||||||
|
// // .ShouldEqual(100);
|
||||||
|
|
||||||
|
// var filesToFind = new[] {
|
||||||
|
// new { Name = "NLog.dll", Version = new Version("2.0.0.0") },
|
||||||
|
// new { Name = "NSync.Core.dll", Version = new Version("1.1.0.0") },
|
||||||
|
// };
|
||||||
|
|
||||||
|
// filesToFind.ForEach(x => {
|
||||||
|
// var path = Path.Combine(tempDir, APP_ID, "staging", "app-1.1.0.0", x.Name);
|
||||||
|
// this.Log().Info("Looking for {0}", path);
|
||||||
|
// File.Exists(path).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var vi = FileVersionInfo.GetVersionInfo(path);
|
||||||
|
// var verInfo = new Version(vi.FileVersion ?? "1.0.0.0");
|
||||||
|
// x.Version.ShouldEqual(verInfo);
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task CreateFullPackagesFromDeltaSmokeTest()
|
||||||
|
// {
|
||||||
|
// string tempDir;
|
||||||
|
// using (Utility.GetTempDirectory(out tempDir)) {
|
||||||
|
// string appDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
// string packagesDir = Path.Combine(appDir, "packages");
|
||||||
|
// Directory.CreateDirectory(packagesDir);
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-delta.nupkg"
|
||||||
|
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(tempDir, APP_ID, "packages", x)));
|
||||||
|
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir("", APP_ID, tempDir);
|
||||||
|
|
||||||
|
// var baseEntry = ReleaseEntry.GenerateFromFile(Path.Combine(tempDir, APP_ID, "packages", "Squirrel.Core.1.0.0.0-full.nupkg"));
|
||||||
|
// var deltaEntry = ReleaseEntry.GenerateFromFile(Path.Combine(tempDir, APP_ID, "packages", "Squirrel.Core.1.1.0.0-delta.nupkg"));
|
||||||
|
|
||||||
|
// var result = fixture.createFullPackagesFromDeltas(new[] { deltaEntry }, baseEntry, null);
|
||||||
|
|
||||||
|
// var zp = new ZipPackage(Path.Combine(tempDir, APP_ID, "packages", result.Filename));
|
||||||
|
// zp.Version.ToString().ShouldEqual("1.1.0.0");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task CreateShortcutsRoundTrip()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||||
|
|
||||||
|
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, tempDir);
|
||||||
|
// await fixture.FullInstall();
|
||||||
|
|
||||||
|
// fixture.CreateShortcutsForExecutable("SquirrelAwareApp.exe",
|
||||||
|
// ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup | ShortcutLocation.AppRoot, false, null, null);
|
||||||
|
|
||||||
|
// Assert.True(File.Exists(Path.Combine(tempDir, APP_ID, "PublishSingleFileAwareApp.lnk")));
|
||||||
|
|
||||||
|
// // NB: COM is Weird.
|
||||||
|
// Thread.Sleep(1000);
|
||||||
|
// fixture.RemoveShortcutsForExecutable("SquirrelAwareApp.exe",
|
||||||
|
// ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup | ShortcutLocation.AppRoot);
|
||||||
|
|
||||||
|
// // NB: Squirrel-Aware first-run might still be running, slow
|
||||||
|
// // our roll before blowing away the temp path
|
||||||
|
// Thread.Sleep(1000);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //[Fact]
|
||||||
|
// //public async Task GetShortcutsSmokeTest()
|
||||||
|
// //{
|
||||||
|
// // string remotePkgPath;
|
||||||
|
// // string path;
|
||||||
|
|
||||||
|
// // using (Utility.WithTempDirectory(out path)) {
|
||||||
|
// // using (Utility.WithTempDirectory(out remotePkgPath))
|
||||||
|
// // using (var mgr = new UpdateManager(remotePkgPath, APP_ID, path)) {
|
||||||
|
// // IntegrationTestHelper.CreateFakeInstalledApp("1.0.0.1", remotePkgPath);
|
||||||
|
// // await mgr.FullInstall();
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// // var fixture = new ApplyReleasesImpl(Path.Combine(path, APP_ID));
|
||||||
|
// // var result = fixture.GetShortcutsForExecutable("SquirrelAwareApp.exe", ShortcutLocation.Desktop | ShortcutLocation.StartMenu | ShortcutLocation.Startup, null);
|
||||||
|
|
||||||
|
// // Assert.Equal(3, result.Keys.Count);
|
||||||
|
|
||||||
|
// // // NB: Squirrel-Aware first-run might still be running, slow
|
||||||
|
// // // our roll before blowing away the temp path
|
||||||
|
// // Thread.Sleep(1000);
|
||||||
|
// // }
|
||||||
|
// //}
|
||||||
|
// }
|
||||||
|
//}
|
||||||
178
test/Squirrel.Tests/UpdateManager/CheckForUpdateTests.cs
Normal file
178
test/Squirrel.Tests/UpdateManager/CheckForUpdateTests.cs
Normal file
@@ -0,0 +1,178 @@
|
|||||||
|
//using System;
|
||||||
|
//using System.IO;
|
||||||
|
//using System.Linq;
|
||||||
|
//using System.Text;
|
||||||
|
//using System.Threading.Tasks;
|
||||||
|
//using System.Web;
|
||||||
|
//using Squirrel.Tests.TestHelpers;
|
||||||
|
//using Xunit;
|
||||||
|
|
||||||
|
//namespace Squirrel.Tests
|
||||||
|
//{
|
||||||
|
// public class CheckForUpdateTests
|
||||||
|
// {
|
||||||
|
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||||
|
// public void NewReleasesShouldBeDetected()
|
||||||
|
// {
|
||||||
|
// Assert.Fail("Rewrite this to be an integration test");
|
||||||
|
// /*
|
||||||
|
// string localReleasesFile = Path.Combine(".", "theApp", "packages", "RELEASES");
|
||||||
|
|
||||||
|
// var fileInfo = new Mock<FileInfoBase>();
|
||||||
|
// fileInfo.Setup(x => x.OpenRead())
|
||||||
|
// .Returns(File.OpenRead(IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOh")));
|
||||||
|
|
||||||
|
// var fs = new Mock<IFileSystemFactory>();
|
||||||
|
// fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
||||||
|
|
||||||
|
// var urlDownloader = new Mock<IUrlDownloader>();
|
||||||
|
// var dlPath = IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOne");
|
||||||
|
// urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
||||||
|
// .Returns(Observable.Return(File.ReadAllText(dlPath, Encoding.UTF8)));
|
||||||
|
|
||||||
|
// var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
||||||
|
// var result = default(UpdateInfo);
|
||||||
|
|
||||||
|
// using (fixture) {
|
||||||
|
// result = fixture.CheckForUpdate().First();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Assert.NotNull(result);
|
||||||
|
// Assert.Equal(1, result.ReleasesToApply.Single().Version.Major);
|
||||||
|
// Assert.Equal(1, result.ReleasesToApply.Single().Version.Minor);
|
||||||
|
// */
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||||
|
// public void CorruptedReleaseFileMeansWeStartFromScratch()
|
||||||
|
// {
|
||||||
|
// Assert.Fail("Rewrite this to be an integration test");
|
||||||
|
|
||||||
|
// /*
|
||||||
|
// string localPackagesDir = Path.Combine(".", "theApp", "packages");
|
||||||
|
// string localReleasesFile = Path.Combine(localPackagesDir, "RELEASES");
|
||||||
|
|
||||||
|
// var fileInfo = new Mock<FileInfoBase>();
|
||||||
|
// fileInfo.Setup(x => x.Exists).Returns(true);
|
||||||
|
// fileInfo.Setup(x => x.OpenRead())
|
||||||
|
// .Returns(new MemoryStream(Encoding.UTF8.GetBytes("lol this isn't right")));
|
||||||
|
|
||||||
|
// var dirInfo = new Mock<DirectoryInfoBase>();
|
||||||
|
// dirInfo.Setup(x => x.Exists).Returns(true);
|
||||||
|
|
||||||
|
// var fs = new Mock<IFileSystemFactory>();
|
||||||
|
// fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
||||||
|
// fs.Setup(x => x.CreateDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||||
|
// fs.Setup(x => x.DeleteDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||||
|
// fs.Setup(x => x.GetDirectoryInfo(localPackagesDir)).Returns(dirInfo.Object);
|
||||||
|
|
||||||
|
// var urlDownloader = new Mock<IUrlDownloader>();
|
||||||
|
// var dlPath = IntegrationTestHelper.GetPath("fixtures", "RELEASES-OnePointOne");
|
||||||
|
// urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
||||||
|
// .Returns(Observable.Return(File.ReadAllText(dlPath, Encoding.UTF8)));
|
||||||
|
|
||||||
|
// var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
||||||
|
// using (fixture) {
|
||||||
|
// fixture.CheckForUpdate().First();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fs.Verify(x => x.CreateDirectoryRecursive(localPackagesDir), Times.Once());
|
||||||
|
// fs.Verify(x => x.DeleteDirectoryRecursive(localPackagesDir), Times.Once());
|
||||||
|
// */
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||||
|
// public void CorruptRemoteFileShouldThrowOnCheck()
|
||||||
|
// {
|
||||||
|
// Assert.Fail("Rewrite this to be an integration test");
|
||||||
|
|
||||||
|
// /*
|
||||||
|
// string localPackagesDir = Path.Combine(".", "theApp", "packages");
|
||||||
|
// string localReleasesFile = Path.Combine(localPackagesDir, "RELEASES");
|
||||||
|
|
||||||
|
// var fileInfo = new Mock<FileInfoBase>();
|
||||||
|
// fileInfo.Setup(x => x.Exists).Returns(false);
|
||||||
|
|
||||||
|
// var dirInfo = new Mock<DirectoryInfoBase>();
|
||||||
|
// dirInfo.Setup(x => x.Exists).Returns(true);
|
||||||
|
|
||||||
|
// var fs = new Mock<IFileSystemFactory>();
|
||||||
|
// fs.Setup(x => x.GetFileInfo(localReleasesFile)).Returns(fileInfo.Object);
|
||||||
|
// fs.Setup(x => x.CreateDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||||
|
// fs.Setup(x => x.DeleteDirectoryRecursive(localPackagesDir)).Verifiable();
|
||||||
|
// fs.Setup(x => x.GetDirectoryInfo(localPackagesDir)).Returns(dirInfo.Object);
|
||||||
|
|
||||||
|
// var urlDownloader = new Mock<IUrlDownloader>();
|
||||||
|
// urlDownloader.Setup(x => x.DownloadUrl(It.IsAny<string>(), It.IsAny<IObserver<int>>()))
|
||||||
|
// .Returns(Observable.Return("lol this isn't right"));
|
||||||
|
|
||||||
|
// var fixture = new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object);
|
||||||
|
|
||||||
|
// using (fixture) {
|
||||||
|
// Assert.Throws<Exception>(() => fixture.CheckForUpdate().First());
|
||||||
|
// }
|
||||||
|
// */
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact(Skip = "TODO")]
|
||||||
|
// public void IfLocalVersionGreaterThanRemoteWeRollback()
|
||||||
|
// {
|
||||||
|
// throw new NotImplementedException();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact(Skip = "TODO")]
|
||||||
|
// public void IfLocalAndRemoteAreEqualThenDoNothing()
|
||||||
|
// {
|
||||||
|
// throw new NotImplementedException();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Theory]
|
||||||
|
// [InlineData(@"94689fede03fed7ab59c24337673a27837f0c3ec MyCoolApp-1.0.nupkg 1004502", "MyCoolApp", null)]
|
||||||
|
// [InlineData(@"0000000000000000000000000000000000000000 https://www.test.org/Folder/MyCoolApp-1.2-delta.nupkg?query=param 1231953", "MyCoolApp", "https://www.test.org/Folder")]
|
||||||
|
// public async Task WebSourceRequestsExpectedUrls(string releaseEntry, string releaseName, string baseUrl)
|
||||||
|
// {
|
||||||
|
// baseUrl = baseUrl ?? "https://example.com/files";
|
||||||
|
// var dl = new FakeDownloader();
|
||||||
|
// var source = new Sources.SimpleWebSource("https://example.com/files", dl);
|
||||||
|
|
||||||
|
// dl.MockedResponseBytes = Encoding.UTF8.GetBytes(releaseEntry);
|
||||||
|
// var releases = await source.GetReleaseFeed(null, null);
|
||||||
|
// Assert.True(releases.Count() == 1);
|
||||||
|
// Assert.Equal(releaseName, releases[0].PackageName);
|
||||||
|
// Assert.Equal("https://example.com/files/RELEASES", new Uri(dl.LastUrl).GetLeftPart(UriPartial.Path));
|
||||||
|
|
||||||
|
// await source.DownloadReleaseEntry(releases[0], "test", null);
|
||||||
|
// Assert.Equal(baseUrl + "/" + releases[0].Filename, new Uri(dl.LastUrl).GetLeftPart(UriPartial.Path));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Theory]
|
||||||
|
// [InlineData("http://example.com", "MyPackage.nupkg", "http://example.com/MyPackage.nupkg")]
|
||||||
|
// [InlineData("http://example.com?auth=hello", "MyPackage.nupkg", "http://example.com/MyPackage.nupkg?auth=hello")]
|
||||||
|
// [InlineData("http://example.com?auth=hello", "https://my.packages.domain/MyPackage-1.0.0.nupkg", "https://my.packages.domain/MyPackage-1.0.0.nupkg")]
|
||||||
|
// public async Task SimpleWebSourcePreservesQueryParametersAndAbsoluteReleaseUri(string baseUri, string releaseUri, string expectedPackageUrl)
|
||||||
|
// {
|
||||||
|
// var dl = new FakeDownloader();
|
||||||
|
// var source = new Sources.SimpleWebSource(baseUri, dl);
|
||||||
|
// var baseKvp = HttpUtility.ParseQueryString(new Uri(baseUri).Query);
|
||||||
|
// var baseDict = baseKvp.AllKeys.Where(k => k != null).ToDictionary(k => k, k => baseKvp[k]);
|
||||||
|
|
||||||
|
// var releaseEntry = $"94689fede03fed7ab59c24337673a27837f0c3ec {releaseUri} 1004502";
|
||||||
|
// dl.MockedResponseBytes = Encoding.UTF8.GetBytes(releaseEntry);
|
||||||
|
|
||||||
|
// var releases = await source.GetReleaseFeed();
|
||||||
|
// var expected = new Uri(baseUri).GetLeftPart(UriPartial.Path).TrimEnd('/') + "/RELEASES";
|
||||||
|
// Assert.StartsWith(expected, dl.LastUrl);
|
||||||
|
|
||||||
|
// // check that each query parameter in base url is in the releases string
|
||||||
|
// var releasesUri = new Uri(dl.LastUrl);
|
||||||
|
// var releasesKvp = HttpUtility.ParseQueryString(releasesUri.Query);
|
||||||
|
// var releasesDict = releasesKvp.AllKeys.Where(k => k != null).ToDictionary(k => k, k => releasesKvp[k]);
|
||||||
|
// foreach (var kvp in baseDict) {
|
||||||
|
// Assert.Equal(releasesDict[kvp.Key], kvp.Value);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// await source.DownloadReleaseEntry(releases[0], "test", null);
|
||||||
|
// Assert.Equal(expectedPackageUrl, dl.LastUrl);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
194
test/Squirrel.Tests/UpdateManager/DownloadReleasesTests.cs
Normal file
194
test/Squirrel.Tests/UpdateManager/DownloadReleasesTests.cs
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
//using System;
|
||||||
|
//using System.Collections.Generic;
|
||||||
|
//using System.IO;
|
||||||
|
//using System.Linq;
|
||||||
|
//using System.Net;
|
||||||
|
//using System.Text;
|
||||||
|
//using System.Threading.Tasks;
|
||||||
|
//using Squirrel.SimpleSplat;
|
||||||
|
//using Squirrel.Tests.TestHelpers;
|
||||||
|
//using Xunit;
|
||||||
|
|
||||||
|
//namespace Squirrel.Tests
|
||||||
|
//{
|
||||||
|
// public class DownloadReleasesTests
|
||||||
|
// {
|
||||||
|
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||||
|
// public void ChecksumShouldFailIfFilesAreMissing()
|
||||||
|
// {
|
||||||
|
// Assert.Fail("Rewrite this to be an integration test");
|
||||||
|
|
||||||
|
// /*
|
||||||
|
// var filename = "Squirrel.Core.1.0.0.0.nupkg";
|
||||||
|
// var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
|
||||||
|
// var fs = new Mock<IFileSystemFactory>();
|
||||||
|
// var urlDownloader = new Mock<IUrlDownloader>();
|
||||||
|
|
||||||
|
// ReleaseEntry entry;
|
||||||
|
// using (var f = File.OpenRead(nuGetPkg)) {
|
||||||
|
// entry = ReleaseEntry.GenerateFromFile(f, filename);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var fileInfo = new Mock<FileInfoBase>();
|
||||||
|
// fileInfo.Setup(x => x.OpenRead()).Returns(File.OpenRead(nuGetPkg));
|
||||||
|
// fileInfo.Setup(x => x.Exists).Returns(false);
|
||||||
|
|
||||||
|
// fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
|
||||||
|
|
||||||
|
// var fixture = ExposedObject.From(
|
||||||
|
// new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object));
|
||||||
|
|
||||||
|
// bool shouldDie = true;
|
||||||
|
// try {
|
||||||
|
// // NB: We can't use Assert.Throws here because the binder
|
||||||
|
// // will try to pick the wrong method
|
||||||
|
// fixture.checksumPackage(entry);
|
||||||
|
// } catch (Exception) {
|
||||||
|
// shouldDie = false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// shouldDie.ShouldBeFalse();
|
||||||
|
// */
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||||
|
// public void ChecksumShouldFailIfFilesAreBogus()
|
||||||
|
// {
|
||||||
|
// Assert.Fail("Rewrite this to be an integration test");
|
||||||
|
|
||||||
|
// /*
|
||||||
|
// var filename = "Squirrel.Core.1.0.0.0.nupkg";
|
||||||
|
// var nuGetPkg = IntegrationTestHelper.GetPath("fixtures", filename);
|
||||||
|
// var fs = new Mock<IFileSystemFactory>();
|
||||||
|
// var urlDownloader = new Mock<IUrlDownloader>();
|
||||||
|
|
||||||
|
// ReleaseEntry entry;
|
||||||
|
// using (var f = File.OpenRead(nuGetPkg)) {
|
||||||
|
// entry = ReleaseEntry.GenerateFromFile(f, filename);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var fileInfo = new Mock<FileInfoBase>();
|
||||||
|
// fileInfo.Setup(x => x.OpenRead()).Returns(new MemoryStream(Encoding.UTF8.GetBytes("Lol broken")));
|
||||||
|
// fileInfo.Setup(x => x.Exists).Returns(true);
|
||||||
|
// fileInfo.Setup(x => x.Length).Returns(new FileInfo(nuGetPkg).Length);
|
||||||
|
// fileInfo.Setup(x => x.Delete()).Verifiable();
|
||||||
|
|
||||||
|
// fs.Setup(x => x.GetFileInfo(Path.Combine(".", "theApp", "packages", filename))).Returns(fileInfo.Object);
|
||||||
|
|
||||||
|
// var fixture = ExposedObject.From(
|
||||||
|
// new UpdateManager("http://lol", "theApp", ".", fs.Object, urlDownloader.Object));
|
||||||
|
|
||||||
|
// bool shouldDie = true;
|
||||||
|
// try {
|
||||||
|
// fixture.checksumPackage(entry);
|
||||||
|
// } catch (Exception ex) {
|
||||||
|
// this.Log().InfoException("Checksum failure", ex);
|
||||||
|
// shouldDie = false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// shouldDie.ShouldBeFalse();
|
||||||
|
// fileInfo.Verify(x => x.Delete(), Times.Once());
|
||||||
|
// */
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||||
|
// public async Task DownloadReleasesFromHttpServerIntegrationTest()
|
||||||
|
// {
|
||||||
|
// Assert.Fail("Rewrite this to not use the SampleUpdatingApp");
|
||||||
|
|
||||||
|
// /*
|
||||||
|
// string tempDir = null;
|
||||||
|
|
||||||
|
// var updateDir = new DirectoryInfo(IntegrationTestHelper.GetPath("..", "SampleUpdatingApp", "SampleReleasesFolder"));
|
||||||
|
|
||||||
|
// IDisposable disp;
|
||||||
|
// try {
|
||||||
|
// var httpServer = new StaticHttpServer(30405, updateDir.FullName);
|
||||||
|
// disp = httpServer.Start();
|
||||||
|
// } catch (HttpListenerException) {
|
||||||
|
// Assert.False(true, @"Windows sucks, go run 'netsh http add urlacl url=http://+:30405/ user=MYMACHINE\MyUser");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var entriesToDownload = updateDir.GetFiles("*.nupkg")
|
||||||
|
// .Select(x => ReleaseEntry.GenerateFromFile(x.FullName))
|
||||||
|
// .ToArray();
|
||||||
|
|
||||||
|
// entriesToDownload.Count().ShouldBeGreaterThan(0);
|
||||||
|
|
||||||
|
// using (disp)
|
||||||
|
// using (Utility.WithTempDirectory(out tempDir)) {
|
||||||
|
// // NB: This is normally done by CheckForUpdates, but since
|
||||||
|
// // we're skipping that in the test we have to do it ourselves
|
||||||
|
// Directory.CreateDirectory(Path.Combine(tempDir, "SampleUpdatingApp", "packages"));
|
||||||
|
|
||||||
|
// var fixture = new UpdateManager("http://localhost:30405", "SampleUpdatingApp", tempDir);
|
||||||
|
// using (fixture) {
|
||||||
|
// var progress = new List<int>();
|
||||||
|
// await fixture.DownloadReleases(entriesToDownload, progress.Add);
|
||||||
|
|
||||||
|
// progress
|
||||||
|
// .Aggregate(0, (acc, x) => { x.ShouldBeGreaterThan(acc); return x; })
|
||||||
|
// .ShouldEqual(100);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// entriesToDownload.ForEach(x => {
|
||||||
|
// this.Log().Info("Looking for {0}", x.Filename);
|
||||||
|
// var actualFile = Path.Combine(tempDir, "SampleUpdatingApp", "packages", x.Filename);
|
||||||
|
// File.Exists(actualFile).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var actualEntry = ReleaseEntry.GenerateFromFile(actualFile);
|
||||||
|
// actualEntry.SHA1.ShouldEqual(x.SHA1);
|
||||||
|
// actualEntry.Version.ShouldEqual(x.Version);
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// */
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact(Skip = "Rewrite this to be an integration test")]
|
||||||
|
// public async Task DownloadReleasesFromFileDirectoryIntegrationTest()
|
||||||
|
// {
|
||||||
|
// Assert.Fail("Rewrite this to not use the SampleUpdatingApp");
|
||||||
|
|
||||||
|
// /*
|
||||||
|
// string tempDir = null;
|
||||||
|
|
||||||
|
// var updateDir = new DirectoryInfo(IntegrationTestHelper.GetPath("..", "SampleUpdatingApp", "SampleReleasesFolder"));
|
||||||
|
|
||||||
|
// var entriesToDownload = updateDir.GetFiles("*.nupkg")
|
||||||
|
// .Select(x => ReleaseEntry.GenerateFromFile(x.FullName))
|
||||||
|
// .ToArray();
|
||||||
|
|
||||||
|
// entriesToDownload.Count().ShouldBeGreaterThan(0);
|
||||||
|
|
||||||
|
// using (Utility.WithTempDirectory(out tempDir)) {
|
||||||
|
// // NB: This is normally done by CheckForUpdates, but since
|
||||||
|
// // we're skipping that in the test we have to do it ourselves
|
||||||
|
// Directory.CreateDirectory(Path.Combine(tempDir, "SampleUpdatingApp", "packages"));
|
||||||
|
|
||||||
|
// var fixture = new UpdateManager(updateDir.FullName, "SampleUpdatingApp", tempDir);
|
||||||
|
// using (fixture) {
|
||||||
|
// var progress = new List<int>();
|
||||||
|
|
||||||
|
// await fixture.DownloadReleases(entriesToDownload, progress.Add);
|
||||||
|
// this.Log().Info("Progress: [{0}]", String.Join(",", progress));
|
||||||
|
|
||||||
|
// progress
|
||||||
|
// .Aggregate(0, (acc, x) => { x.ShouldBeGreaterThan(acc); return x; })
|
||||||
|
// .ShouldEqual(100);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// entriesToDownload.ForEach(x => {
|
||||||
|
// this.Log().Info("Looking for {0}", x.Filename);
|
||||||
|
// var actualFile = Path.Combine(tempDir, "SampleUpdatingApp", "packages", x.Filename);
|
||||||
|
// File.Exists(actualFile).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var actualEntry = ReleaseEntry.GenerateFromFile(actualFile);
|
||||||
|
// actualEntry.SHA1.ShouldEqual(x.SHA1);
|
||||||
|
// actualEntry.Version.ShouldEqual(x.Version);
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// */
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
367
test/Squirrel.Tests/UpdateManager/UpdateManagerTests.cs
Normal file
367
test/Squirrel.Tests/UpdateManager/UpdateManagerTests.cs
Normal file
@@ -0,0 +1,367 @@
|
|||||||
|
//using System;
|
||||||
|
//using System.Collections.Generic;
|
||||||
|
//using System.IO;
|
||||||
|
//using System.Linq;
|
||||||
|
//using System.Text;
|
||||||
|
//using System.Threading;
|
||||||
|
//using System.Threading.Tasks;
|
||||||
|
//using Microsoft.Win32;
|
||||||
|
//using Squirrel;
|
||||||
|
//using Squirrel.Tests.TestHelpers;
|
||||||
|
//using Xunit;
|
||||||
|
//using System.Net;
|
||||||
|
//using Squirrel.NuGet;
|
||||||
|
//using System.Net.Http;
|
||||||
|
//using NuGet.Versioning;
|
||||||
|
//using Squirrel.Sources;
|
||||||
|
|
||||||
|
//namespace Squirrel.Tests
|
||||||
|
//{
|
||||||
|
// public class UpdateManagerTests
|
||||||
|
// {
|
||||||
|
// public const string APP_ID = "theFakeApp";
|
||||||
|
|
||||||
|
// public class CreateUninstallerRegKeyTests
|
||||||
|
// {
|
||||||
|
// [Fact]
|
||||||
|
// public async Task CallingMethodTwiceShouldUpdateInstaller()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var path);
|
||||||
|
// using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
||||||
|
|
||||||
|
// IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, path))
|
||||||
|
// await fixture.FullInstall();
|
||||||
|
|
||||||
|
// using (var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, path)) {
|
||||||
|
// await mgr.CreateUninstallerRegistryEntry();
|
||||||
|
// var regKey = await mgr.CreateUninstallerRegistryEntry();
|
||||||
|
|
||||||
|
// Assert.False(String.IsNullOrWhiteSpace((string) regKey.GetValue("DisplayName")));
|
||||||
|
|
||||||
|
// mgr.RemoveUninstallerRegistryEntry();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // NB: Squirrel-Aware first-run might still be running, slow
|
||||||
|
// // our roll before blowing away the temp path
|
||||||
|
// Thread.Sleep(1000);
|
||||||
|
|
||||||
|
// var key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default)
|
||||||
|
// .OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
|
||||||
|
// using (key) {
|
||||||
|
// Assert.False(key.GetSubKeyNames().Contains(APP_ID));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public class UpdateLocalReleasesTests
|
||||||
|
// {
|
||||||
|
// [Fact]
|
||||||
|
// public async Task UpdateLocalReleasesSmokeTest()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
|
||||||
|
// var appDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
// var packageDir = Directory.CreateDirectory(Path.Combine(appDir, "packages"));
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||||
|
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(tempDir, APP_ID, "packages", x)));
|
||||||
|
|
||||||
|
// var info = new AppDescWindows(appDir, APP_ID);
|
||||||
|
// ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||||
|
|
||||||
|
// var releasePath = Path.Combine(packageDir.FullName, "RELEASES");
|
||||||
|
// File.Exists(releasePath).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
||||||
|
// entries.Count().ShouldEqual(3);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task InitialInstallSmokeTest()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
|
||||||
|
// var remotePackageDir = Directory.CreateDirectory(Path.Combine(tempDir, "remotePackages"));
|
||||||
|
// var localAppDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||||
|
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(remotePackageDir.FullName, x)));
|
||||||
|
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackageDir.FullName, APP_ID, tempDir);
|
||||||
|
// await fixture.FullInstall();
|
||||||
|
|
||||||
|
// var releasePath = Path.Combine(localAppDir, "packages", "RELEASES");
|
||||||
|
// File.Exists(releasePath).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
||||||
|
// entries.Count().ShouldEqual(1);
|
||||||
|
|
||||||
|
// Assert.True(File.Exists(Path.Combine(localAppDir, "current", "ReactiveUI.dll")));
|
||||||
|
// Assert.True(File.Exists(Path.Combine(localAppDir, "current", "NSync.Core.dll")));
|
||||||
|
|
||||||
|
// var manifest = NuspecManifest.ParseFromFile(Path.Combine(localAppDir, "current", Utility.SpecVersionFileName));
|
||||||
|
// Assert.Equal(new NuGetVersion(1, 0, 0, 0), manifest.Version);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task SpecialCharactersInitialInstallTest()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
|
||||||
|
// var remotePackageDir = Directory.CreateDirectory(Path.Combine(tempDir, "remotePackages"));
|
||||||
|
// var localAppDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "SpecialCharacters-0.1.0-full.nupkg",
|
||||||
|
// }.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(remotePackageDir.FullName, x)));
|
||||||
|
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackageDir.FullName, APP_ID, tempDir);
|
||||||
|
// await fixture.FullInstall();
|
||||||
|
|
||||||
|
// var releasePath = Path.Combine(localAppDir, "packages", "RELEASES");
|
||||||
|
// File.Exists(releasePath).ShouldBeTrue();
|
||||||
|
|
||||||
|
// var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
||||||
|
// entries.Count().ShouldEqual(1);
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "file space name.txt"
|
||||||
|
// }.ForEach(x => File.Exists(Path.Combine(localAppDir, "current", x)).ShouldBeTrue());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task WhenBothFilesAreInSyncNoUpdatesAreApplied()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
|
||||||
|
// var appDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
// var localPackages = Path.Combine(appDir, "packages");
|
||||||
|
// var remotePackages = Path.Combine(tempDir, "releases");
|
||||||
|
// Directory.CreateDirectory(localPackages);
|
||||||
|
// Directory.CreateDirectory(remotePackages);
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||||
|
// }.ForEach(x => {
|
||||||
|
// var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||||
|
// File.Copy(path, Path.Combine(localPackages, x));
|
||||||
|
// File.Copy(path, Path.Combine(remotePackages, x));
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // sync both release files
|
||||||
|
// var info = new AppDescWindows(appDir, APP_ID);
|
||||||
|
// ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||||
|
// ReleaseEntry.BuildReleasesFile(remotePackages);
|
||||||
|
|
||||||
|
// // check for an update
|
||||||
|
// using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
||||||
|
// UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
||||||
|
|
||||||
|
// Assert.NotNull(updateInfo);
|
||||||
|
// Assert.Empty(updateInfo.ReleasesToApply);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task WhenRemoteReleasesDoNotHaveDeltasNoUpdatesAreApplied()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
|
||||||
|
// var appDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
// var localPackages = Path.Combine(appDir, "packages");
|
||||||
|
// var remotePackages = Path.Combine(tempDir, "releases");
|
||||||
|
// Directory.CreateDirectory(localPackages);
|
||||||
|
// Directory.CreateDirectory(remotePackages);
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||||
|
// }.ForEach(x => {
|
||||||
|
// var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||||
|
// File.Copy(path, Path.Combine(localPackages, x));
|
||||||
|
// });
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||||
|
// }.ForEach(x => {
|
||||||
|
// var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||||
|
// File.Copy(path, Path.Combine(remotePackages, x));
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // sync both release files
|
||||||
|
// var info = new AppDescWindows(appDir, APP_ID);
|
||||||
|
// ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||||
|
// ReleaseEntry.BuildReleasesFile(remotePackages);
|
||||||
|
|
||||||
|
// using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
||||||
|
// UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
||||||
|
|
||||||
|
// Assert.NotNull(updateInfo);
|
||||||
|
// Assert.Empty(updateInfo.ReleasesToApply);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task WhenTwoRemoteUpdatesAreAvailableChoosesDeltaVersion()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
|
||||||
|
// var appDir = Path.Combine(tempDir, APP_ID);
|
||||||
|
// var localPackages = Path.Combine(appDir, "packages");
|
||||||
|
// var remotePackages = Path.Combine(tempDir, "releases");
|
||||||
|
// Directory.CreateDirectory(localPackages);
|
||||||
|
// Directory.CreateDirectory(remotePackages);
|
||||||
|
|
||||||
|
// new[] { "Squirrel.Core.1.0.0.0-full.nupkg", }.ForEach(x => {
|
||||||
|
// var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||||
|
// File.Copy(path, Path.Combine(localPackages, x));
|
||||||
|
// });
|
||||||
|
|
||||||
|
// new[] {
|
||||||
|
// "Squirrel.Core.1.0.0.0-full.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-delta.nupkg",
|
||||||
|
// "Squirrel.Core.1.1.0.0-full.nupkg",
|
||||||
|
// }.ForEach(x => {
|
||||||
|
// var path = IntegrationTestHelper.GetPath("fixtures", x);
|
||||||
|
// File.Copy(path, Path.Combine(remotePackages, x));
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // sync both release files
|
||||||
|
// var info = new AppDescWindows(appDir, APP_ID);
|
||||||
|
// ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
||||||
|
// ReleaseEntry.BuildReleasesFile(remotePackages);
|
||||||
|
|
||||||
|
// using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
||||||
|
// UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
||||||
|
|
||||||
|
// Assert.True(updateInfo.ReleasesToApply.First().IsDelta);
|
||||||
|
|
||||||
|
// updateInfo = await mgr.CheckForUpdate(ignoreDeltaUpdates: true);
|
||||||
|
// Assert.False(updateInfo.ReleasesToApply.First().IsDelta);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task WhenFolderDoesNotExistThrowHelpfulError()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
// var directory = Path.Combine(tempDir, "missing-folder");
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
||||||
|
// await Assert.ThrowsAsync<Exception>(() => fixture.CheckForUpdate());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task WhenReleasesFileDoesntExistThrowACustomError()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
// var directory = Path.Combine(tempDir, "folder");
|
||||||
|
// Directory.CreateDirectory(directory);
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
||||||
|
// await Assert.ThrowsAsync<Exception>(() => fixture.CheckForUpdate());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task WhenReleasesFileIsBlankThrowAnException()
|
||||||
|
// {
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
// var directory = Path.Combine(tempDir, "folder");
|
||||||
|
// Directory.CreateDirectory(directory);
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
||||||
|
// File.WriteAllText(Path.Combine(directory, "RELEASES"), "");
|
||||||
|
// await Assert.ThrowsAsync(typeof(Exception), () => fixture.CheckForUpdate());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public async Task WhenUrlResultsInWebExceptionWeShouldThrow()
|
||||||
|
// {
|
||||||
|
// // This should result in a WebException (which gets caught) unless you can actually access http://lol
|
||||||
|
// using var _1 = Utility.GetTempDirectory(out var tempDir);
|
||||||
|
// using var fixture = UpdateManagerTestImpl.FromFakeWebSource("http://lol", APP_ID, tempDir);
|
||||||
|
// await Assert.ThrowsAsync(typeof(HttpRequestException), () => fixture.CheckForUpdate());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void IsInstalledHandlesInvalidDirectoryStructure()
|
||||||
|
// {
|
||||||
|
// using (Utility.GetTempDirectory(out var tempDir)) {
|
||||||
|
// Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
||||||
|
// Directory.CreateDirectory(Path.Combine(tempDir, APP_ID, "app-1.0.1"));
|
||||||
|
// Directory.CreateDirectory(Path.Combine(tempDir, APP_ID, "wrongDir"));
|
||||||
|
// File.WriteAllText(Path.Combine(tempDir, APP_ID, "Update.exe"), "1");
|
||||||
|
// using (var fixture = UpdateManagerTestImpl.FromFakeWebSource("http://lol", APP_ID, tempDir)) {
|
||||||
|
// Assert.Null(new AppDescWindows(Path.Combine(tempDir, "app.exe")).CurrentlyInstalledVersion);
|
||||||
|
// Assert.Null(new AppDescWindows(Path.Combine(tempDir, APP_ID, "app.exe")).CurrentlyInstalledVersion);
|
||||||
|
// Assert.Null(new AppDescWindows(Path.Combine(tempDir, APP_ID, "wrongDir", "app.exe")).CurrentlyInstalledVersion);
|
||||||
|
// Assert.Equal(new SemanticVersion(1, 0, 9),
|
||||||
|
// new AppDescWindows(Path.Combine(tempDir, APP_ID, "app-1.0.9", "app.exe")).CurrentlyInstalledVersion);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void CurrentlyInstalledVersionDoesNotThrow()
|
||||||
|
// {
|
||||||
|
// using var fixture = new UpdateManager();
|
||||||
|
// Assert.Null(fixture.CurrentlyInstalledVersion());
|
||||||
|
// Assert.False(fixture.IsInstalledApp);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Theory]
|
||||||
|
// [InlineData(0, 0, 25, 0)]
|
||||||
|
// [InlineData(12, 0, 25, 3)]
|
||||||
|
// [InlineData(55, 0, 25, 13)]
|
||||||
|
// [InlineData(100, 0, 25, 25)]
|
||||||
|
// [InlineData(0, 25, 50, 25)]
|
||||||
|
// [InlineData(12, 25, 50, 28)]
|
||||||
|
// [InlineData(55, 25, 50, 38)]
|
||||||
|
// [InlineData(100, 25, 50, 50)]
|
||||||
|
// public void CalculatesPercentageCorrectly(int percentageOfCurrentStep, int stepStartPercentage, int stepEndPercentage, int expectedPercentage)
|
||||||
|
// {
|
||||||
|
// var percentage = Utility.CalculateProgress(percentageOfCurrentStep, stepStartPercentage, stepEndPercentage);
|
||||||
|
|
||||||
|
// Assert.Equal(expectedPercentage, percentage);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// [Fact]
|
||||||
|
// public void CalculatesPercentageCorrectlyForUpdateExe()
|
||||||
|
// {
|
||||||
|
// // Note: this mimicks the update.exe progress reporting of multiple steps
|
||||||
|
|
||||||
|
// var progress = new List<int>();
|
||||||
|
|
||||||
|
// // 3 % (3 stages), check for updates
|
||||||
|
// foreach (var step in new[] { 0, 33, 66, 100 }) {
|
||||||
|
// progress.Add(Utility.CalculateProgress(step, 0, 3));
|
||||||
|
|
||||||
|
// Assert.InRange(progress.Last(), 0, 3);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Assert.Equal(3, progress.Last());
|
||||||
|
|
||||||
|
// // 3 - 30 %, download releases
|
||||||
|
// for (var step = 0; step <= 100; step++) {
|
||||||
|
// progress.Add(Utility.CalculateProgress(step, 3, 30));
|
||||||
|
|
||||||
|
// Assert.InRange(progress.Last(), 3, 30);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Assert.Equal(30, progress.Last());
|
||||||
|
|
||||||
|
// // 30 - 100 %, apply releases
|
||||||
|
// for (var step = 0; step <= 100; step++) {
|
||||||
|
// progress.Add(Utility.CalculateProgress(step, 30, 100));
|
||||||
|
|
||||||
|
// Assert.InRange(progress.Last(), 30, 100);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Assert.Equal(100, progress.Last());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
@@ -1,367 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Win32;
|
|
||||||
using Squirrel;
|
|
||||||
using Squirrel.Tests.TestHelpers;
|
|
||||||
using Xunit;
|
|
||||||
using System.Net;
|
|
||||||
using Squirrel.NuGet;
|
|
||||||
using System.Net.Http;
|
|
||||||
using NuGet.Versioning;
|
|
||||||
using Squirrel.Sources;
|
|
||||||
|
|
||||||
namespace Squirrel.Tests
|
|
||||||
{
|
|
||||||
public class UpdateManagerTests
|
|
||||||
{
|
|
||||||
public const string APP_ID = "theFakeApp";
|
|
||||||
|
|
||||||
public class CreateUninstallerRegKeyTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public async Task CallingMethodTwiceShouldUpdateInstaller()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var path);
|
|
||||||
using var _2 = Utility.GetTempDirectory(out var remotePkgDir);
|
|
||||||
|
|
||||||
IntegrationTestHelper.CreateNewVersionInPackageDir("0.1.0", remotePkgDir);
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, path))
|
|
||||||
await fixture.FullInstall();
|
|
||||||
|
|
||||||
using (var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePkgDir, APP_ID, path)) {
|
|
||||||
await mgr.CreateUninstallerRegistryEntry();
|
|
||||||
var regKey = await mgr.CreateUninstallerRegistryEntry();
|
|
||||||
|
|
||||||
Assert.False(String.IsNullOrWhiteSpace((string) regKey.GetValue("DisplayName")));
|
|
||||||
|
|
||||||
mgr.RemoveUninstallerRegistryEntry();
|
|
||||||
}
|
|
||||||
|
|
||||||
// NB: Squirrel-Aware first-run might still be running, slow
|
|
||||||
// our roll before blowing away the temp path
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
|
|
||||||
var key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default)
|
|
||||||
.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
|
|
||||||
using (key) {
|
|
||||||
Assert.False(key.GetSubKeyNames().Contains(APP_ID));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class UpdateLocalReleasesTests
|
|
||||||
{
|
|
||||||
[Fact]
|
|
||||||
public async Task UpdateLocalReleasesSmokeTest()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
|
|
||||||
var appDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
var packageDir = Directory.CreateDirectory(Path.Combine(appDir, "packages"));
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-delta.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
|
||||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(tempDir, APP_ID, "packages", x)));
|
|
||||||
|
|
||||||
var info = new AppDescWindows(appDir, APP_ID);
|
|
||||||
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
|
||||||
|
|
||||||
var releasePath = Path.Combine(packageDir.FullName, "RELEASES");
|
|
||||||
File.Exists(releasePath).ShouldBeTrue();
|
|
||||||
|
|
||||||
var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
|
||||||
entries.Count().ShouldEqual(3);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task InitialInstallSmokeTest()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
|
|
||||||
var remotePackageDir = Directory.CreateDirectory(Path.Combine(tempDir, "remotePackages"));
|
|
||||||
var localAppDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
|
||||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(remotePackageDir.FullName, x)));
|
|
||||||
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackageDir.FullName, APP_ID, tempDir);
|
|
||||||
await fixture.FullInstall();
|
|
||||||
|
|
||||||
var releasePath = Path.Combine(localAppDir, "packages", "RELEASES");
|
|
||||||
File.Exists(releasePath).ShouldBeTrue();
|
|
||||||
|
|
||||||
var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
|
||||||
entries.Count().ShouldEqual(1);
|
|
||||||
|
|
||||||
Assert.True(File.Exists(Path.Combine(localAppDir, "current", "ReactiveUI.dll")));
|
|
||||||
Assert.True(File.Exists(Path.Combine(localAppDir, "current", "NSync.Core.dll")));
|
|
||||||
|
|
||||||
var manifest = NuspecManifest.ParseFromFile(Path.Combine(localAppDir, "current", Utility.SpecVersionFileName));
|
|
||||||
Assert.Equal(new NuGetVersion(1, 0, 0, 0), manifest.Version);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task SpecialCharactersInitialInstallTest()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
|
|
||||||
var remotePackageDir = Directory.CreateDirectory(Path.Combine(tempDir, "remotePackages"));
|
|
||||||
var localAppDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"SpecialCharacters-0.1.0-full.nupkg",
|
|
||||||
}.ForEach(x => File.Copy(IntegrationTestHelper.GetPath("fixtures", x), Path.Combine(remotePackageDir.FullName, x)));
|
|
||||||
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackageDir.FullName, APP_ID, tempDir);
|
|
||||||
await fixture.FullInstall();
|
|
||||||
|
|
||||||
var releasePath = Path.Combine(localAppDir, "packages", "RELEASES");
|
|
||||||
File.Exists(releasePath).ShouldBeTrue();
|
|
||||||
|
|
||||||
var entries = ReleaseEntry.ParseReleaseFile(File.ReadAllText(releasePath, Encoding.UTF8));
|
|
||||||
entries.Count().ShouldEqual(1);
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"file space name.txt"
|
|
||||||
}.ForEach(x => File.Exists(Path.Combine(localAppDir, "current", x)).ShouldBeTrue());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task WhenBothFilesAreInSyncNoUpdatesAreApplied()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
|
|
||||||
var appDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
var localPackages = Path.Combine(appDir, "packages");
|
|
||||||
var remotePackages = Path.Combine(tempDir, "releases");
|
|
||||||
Directory.CreateDirectory(localPackages);
|
|
||||||
Directory.CreateDirectory(remotePackages);
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-delta.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
|
||||||
}.ForEach(x => {
|
|
||||||
var path = IntegrationTestHelper.GetPath("fixtures", x);
|
|
||||||
File.Copy(path, Path.Combine(localPackages, x));
|
|
||||||
File.Copy(path, Path.Combine(remotePackages, x));
|
|
||||||
});
|
|
||||||
|
|
||||||
// sync both release files
|
|
||||||
var info = new AppDescWindows(appDir, APP_ID);
|
|
||||||
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
|
||||||
ReleaseEntry.BuildReleasesFile(remotePackages);
|
|
||||||
|
|
||||||
// check for an update
|
|
||||||
using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
|
||||||
UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
|
||||||
|
|
||||||
Assert.NotNull(updateInfo);
|
|
||||||
Assert.Empty(updateInfo.ReleasesToApply);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task WhenRemoteReleasesDoNotHaveDeltasNoUpdatesAreApplied()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
|
|
||||||
var appDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
var localPackages = Path.Combine(appDir, "packages");
|
|
||||||
var remotePackages = Path.Combine(tempDir, "releases");
|
|
||||||
Directory.CreateDirectory(localPackages);
|
|
||||||
Directory.CreateDirectory(remotePackages);
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-delta.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
|
||||||
}.ForEach(x => {
|
|
||||||
var path = IntegrationTestHelper.GetPath("fixtures", x);
|
|
||||||
File.Copy(path, Path.Combine(localPackages, x));
|
|
||||||
});
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
|
||||||
}.ForEach(x => {
|
|
||||||
var path = IntegrationTestHelper.GetPath("fixtures", x);
|
|
||||||
File.Copy(path, Path.Combine(remotePackages, x));
|
|
||||||
});
|
|
||||||
|
|
||||||
// sync both release files
|
|
||||||
var info = new AppDescWindows(appDir, APP_ID);
|
|
||||||
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
|
||||||
ReleaseEntry.BuildReleasesFile(remotePackages);
|
|
||||||
|
|
||||||
using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
|
||||||
UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
|
||||||
|
|
||||||
Assert.NotNull(updateInfo);
|
|
||||||
Assert.Empty(updateInfo.ReleasesToApply);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task WhenTwoRemoteUpdatesAreAvailableChoosesDeltaVersion()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
|
|
||||||
var appDir = Path.Combine(tempDir, APP_ID);
|
|
||||||
var localPackages = Path.Combine(appDir, "packages");
|
|
||||||
var remotePackages = Path.Combine(tempDir, "releases");
|
|
||||||
Directory.CreateDirectory(localPackages);
|
|
||||||
Directory.CreateDirectory(remotePackages);
|
|
||||||
|
|
||||||
new[] { "Squirrel.Core.1.0.0.0-full.nupkg", }.ForEach(x => {
|
|
||||||
var path = IntegrationTestHelper.GetPath("fixtures", x);
|
|
||||||
File.Copy(path, Path.Combine(localPackages, x));
|
|
||||||
});
|
|
||||||
|
|
||||||
new[] {
|
|
||||||
"Squirrel.Core.1.0.0.0-full.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-delta.nupkg",
|
|
||||||
"Squirrel.Core.1.1.0.0-full.nupkg",
|
|
||||||
}.ForEach(x => {
|
|
||||||
var path = IntegrationTestHelper.GetPath("fixtures", x);
|
|
||||||
File.Copy(path, Path.Combine(remotePackages, x));
|
|
||||||
});
|
|
||||||
|
|
||||||
// sync both release files
|
|
||||||
var info = new AppDescWindows(appDir, APP_ID);
|
|
||||||
ReleaseEntry.BuildReleasesFile(info.PackagesDir);
|
|
||||||
ReleaseEntry.BuildReleasesFile(remotePackages);
|
|
||||||
|
|
||||||
using var mgr = UpdateManagerTestImpl.FromLocalPackageTempDir(remotePackages, APP_ID, tempDir);
|
|
||||||
UpdateInfo updateInfo = await mgr.CheckForUpdate();
|
|
||||||
|
|
||||||
Assert.True(updateInfo.ReleasesToApply.First().IsDelta);
|
|
||||||
|
|
||||||
updateInfo = await mgr.CheckForUpdate(ignoreDeltaUpdates: true);
|
|
||||||
Assert.False(updateInfo.ReleasesToApply.First().IsDelta);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task WhenFolderDoesNotExistThrowHelpfulError()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
var directory = Path.Combine(tempDir, "missing-folder");
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
|
||||||
await Assert.ThrowsAsync<Exception>(() => fixture.CheckForUpdate());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task WhenReleasesFileDoesntExistThrowACustomError()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
var directory = Path.Combine(tempDir, "folder");
|
|
||||||
Directory.CreateDirectory(directory);
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
|
||||||
await Assert.ThrowsAsync<Exception>(() => fixture.CheckForUpdate());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task WhenReleasesFileIsBlankThrowAnException()
|
|
||||||
{
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
var directory = Path.Combine(tempDir, "folder");
|
|
||||||
Directory.CreateDirectory(directory);
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromLocalPackageTempDir(directory, APP_ID, tempDir);
|
|
||||||
File.WriteAllText(Path.Combine(directory, "RELEASES"), "");
|
|
||||||
await Assert.ThrowsAsync(typeof(Exception), () => fixture.CheckForUpdate());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task WhenUrlResultsInWebExceptionWeShouldThrow()
|
|
||||||
{
|
|
||||||
// This should result in a WebException (which gets caught) unless you can actually access http://lol
|
|
||||||
using var _1 = Utility.GetTempDirectory(out var tempDir);
|
|
||||||
using var fixture = UpdateManagerTestImpl.FromFakeWebSource("http://lol", APP_ID, tempDir);
|
|
||||||
await Assert.ThrowsAsync(typeof(HttpRequestException), () => fixture.CheckForUpdate());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void IsInstalledHandlesInvalidDirectoryStructure()
|
|
||||||
{
|
|
||||||
using (Utility.GetTempDirectory(out var tempDir)) {
|
|
||||||
Directory.CreateDirectory(Path.Combine(tempDir, APP_ID));
|
|
||||||
Directory.CreateDirectory(Path.Combine(tempDir, APP_ID, "app-1.0.1"));
|
|
||||||
Directory.CreateDirectory(Path.Combine(tempDir, APP_ID, "wrongDir"));
|
|
||||||
File.WriteAllText(Path.Combine(tempDir, APP_ID, "Update.exe"), "1");
|
|
||||||
using (var fixture = UpdateManagerTestImpl.FromFakeWebSource("http://lol", APP_ID, tempDir)) {
|
|
||||||
Assert.Null(new AppDescWindows(Path.Combine(tempDir, "app.exe")).CurrentlyInstalledVersion);
|
|
||||||
Assert.Null(new AppDescWindows(Path.Combine(tempDir, APP_ID, "app.exe")).CurrentlyInstalledVersion);
|
|
||||||
Assert.Null(new AppDescWindows(Path.Combine(tempDir, APP_ID, "wrongDir", "app.exe")).CurrentlyInstalledVersion);
|
|
||||||
Assert.Equal(new SemanticVersion(1, 0, 9),
|
|
||||||
new AppDescWindows(Path.Combine(tempDir, APP_ID, "app-1.0.9", "app.exe")).CurrentlyInstalledVersion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CurrentlyInstalledVersionDoesNotThrow()
|
|
||||||
{
|
|
||||||
using var fixture = new UpdateManager();
|
|
||||||
Assert.Null(fixture.CurrentlyInstalledVersion());
|
|
||||||
Assert.False(fixture.IsInstalledApp);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(0, 0, 25, 0)]
|
|
||||||
[InlineData(12, 0, 25, 3)]
|
|
||||||
[InlineData(55, 0, 25, 13)]
|
|
||||||
[InlineData(100, 0, 25, 25)]
|
|
||||||
[InlineData(0, 25, 50, 25)]
|
|
||||||
[InlineData(12, 25, 50, 28)]
|
|
||||||
[InlineData(55, 25, 50, 38)]
|
|
||||||
[InlineData(100, 25, 50, 50)]
|
|
||||||
public void CalculatesPercentageCorrectly(int percentageOfCurrentStep, int stepStartPercentage, int stepEndPercentage, int expectedPercentage)
|
|
||||||
{
|
|
||||||
var percentage = Utility.CalculateProgress(percentageOfCurrentStep, stepStartPercentage, stepEndPercentage);
|
|
||||||
|
|
||||||
Assert.Equal(expectedPercentage, percentage);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void CalculatesPercentageCorrectlyForUpdateExe()
|
|
||||||
{
|
|
||||||
// Note: this mimicks the update.exe progress reporting of multiple steps
|
|
||||||
|
|
||||||
var progress = new List<int>();
|
|
||||||
|
|
||||||
// 3 % (3 stages), check for updates
|
|
||||||
foreach (var step in new[] { 0, 33, 66, 100 }) {
|
|
||||||
progress.Add(Utility.CalculateProgress(step, 0, 3));
|
|
||||||
|
|
||||||
Assert.InRange(progress.Last(), 0, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.Equal(3, progress.Last());
|
|
||||||
|
|
||||||
// 3 - 30 %, download releases
|
|
||||||
for (var step = 0; step <= 100; step++) {
|
|
||||||
progress.Add(Utility.CalculateProgress(step, 3, 30));
|
|
||||||
|
|
||||||
Assert.InRange(progress.Last(), 3, 30);
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.Equal(30, progress.Last());
|
|
||||||
|
|
||||||
// 30 - 100 %, apply releases
|
|
||||||
for (var step = 0; step <= 100; step++) {
|
|
||||||
progress.Add(Utility.CalculateProgress(step, 30, 100));
|
|
||||||
|
|
||||||
Assert.InRange(progress.Last(), 30, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert.Equal(100, progress.Last());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Squirrel.SimpleSplat;
|
|
||||||
using Squirrel;
|
using Squirrel;
|
||||||
using Squirrel.Tests.TestHelpers;
|
using Squirrel.Tests.TestHelpers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
@@ -15,10 +14,13 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Squirrel.Tests
|
namespace Squirrel.Tests
|
||||||
{
|
{
|
||||||
public class UtilityTests : TestLoggingBase
|
public class UtilityTests
|
||||||
{
|
{
|
||||||
public UtilityTests(ITestOutputHelper log) : base(log)
|
private readonly ITestOutputHelper _output;
|
||||||
|
|
||||||
|
public UtilityTests(ITestOutputHelper output)
|
||||||
{
|
{
|
||||||
|
_output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@@ -122,6 +124,7 @@ namespace Squirrel.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void CanDeleteDeepRecursiveDirectoryStructure()
|
public void CanDeleteDeepRecursiveDirectoryStructure()
|
||||||
{
|
{
|
||||||
|
using var logger = _output.BuildLoggerFor<UtilityTests>();
|
||||||
string tempDir;
|
string tempDir;
|
||||||
using (Utility.GetTempDirectory(out tempDir)) {
|
using (Utility.GetTempDirectory(out tempDir)) {
|
||||||
for (var i = 0; i < 50; i++) {
|
for (var i = 0; i < 50; i++) {
|
||||||
@@ -133,27 +136,27 @@ namespace Squirrel.Tests
|
|||||||
|
|
||||||
var count = files.Count();
|
var count = files.Count();
|
||||||
|
|
||||||
this.Log().Info("Created {0} files under directory {1}", count, tempDir);
|
logger.Info($"Created {count} files under directory {tempDir}");
|
||||||
|
|
||||||
var sw = new Stopwatch();
|
var sw = new Stopwatch();
|
||||||
sw.Start();
|
sw.Start();
|
||||||
Utility.DeleteFileOrDirectoryHard(tempDir);
|
Utility.DeleteFileOrDirectoryHard(tempDir);
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
this.Log().Info("Delete took {0}ms", sw.ElapsedMilliseconds);
|
logger.Info($"Delete took {sw.ElapsedMilliseconds}ms");
|
||||||
|
|
||||||
Assert.False(Directory.Exists(tempDir));
|
Assert.False(Directory.Exists(tempDir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
//[Fact]
|
||||||
public void CreateFakePackageSmokeTest()
|
//public void CreateFakePackageSmokeTest()
|
||||||
{
|
//{
|
||||||
string path;
|
// string path;
|
||||||
using (Utility.GetTempDirectory(out path)) {
|
// using (Utility.GetTempDirectory(out path)) {
|
||||||
var output = IntegrationTestHelper.CreateFakeInstalledApp("0.3.0", path);
|
// var output = IntegrationTestHelper.CreateFakeInstalledApp("0.3.0", path);
|
||||||
Assert.True(File.Exists(output));
|
// Assert.True(File.Exists(output));
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("foo.dll", true)]
|
[InlineData("foo.dll", true)]
|
||||||
|
|||||||
Reference in New Issue
Block a user