Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,9 @@
<PackageReference Include="nunit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
<PackageReference Include="Octopus.Dependencies.AzureCLI" Version="2.41.0" GeneratePathProperty="true" />
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.41" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" Condition="'$(TargetFramework)' == 'net462'" />
</ItemGroup>
<Target Name="GetPackageFiles" AfterTargets="ResolveReferences" DependsOnTargets="RunResolvePackageDependencies">
<ItemGroup>
<Content Include="$(PkgOctopus_Dependencies_AzureCLI)/*.nupkg">
<Visible>false</Visible>
<Link>Octopus.Dependencies.AzureCLI.nupkg</Link>
<Pack>true</Pack>
<PackageCopyToOutput>true</PackageCopyToOutput>
<PackageFlatten>true</PackageFlatten>
<PackagePath>contentFiles/any/any/Octopus.Dependencies.AzureCLI.nupkg</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Target>
<ItemGroup>
<ProjectReference Include="..\Calamari.AzureResourceGroup\Calamari.AzureResourceGroup.csproj" />
<ProjectReference Include="..\Calamari.Testing\Calamari.Testing.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Calamari.Testing;
using Calamari.Testing.Azure;
using Calamari.Testing.Helpers;
using Calamari.Testing.Tools;
using NUnit.Framework;

namespace Calamari.AzureResourceGroup.Tests
Expand All @@ -32,8 +31,6 @@ class DeployAzureBicepTemplateCommandFixture
readonly string packagePath = TestEnvironment.GetTestPath("Packages", "Bicep");
SubscriptionResource subscriptionResource;

static IDeploymentTool AzureCLI = new InPathDeploymentTool("Octopus.Dependencies.AzureCLI", "AzureCLI\\wbin");

[OneTimeSetUp]
public async Task Setup()
{
Expand Down Expand Up @@ -142,8 +139,6 @@ await CommandTestBuilder.CreateAsync<DeployAzureBicepTemplateCommand, Program>()

void AddDefaults(CommandTestBuilderContext context)
{
context.WithTool(AzureCLI);

context.Variables.Add(AzureScripting.SpecialVariables.Account.AccountType, "AzureServicePrincipal");
context.Variables.Add(AzureAccountVariables.SubscriptionId, subscriptionId);
context.Variables.Add(AzureAccountVariables.TenantId, tenantId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using NUnit.Framework;
using Calamari.Testing;
using Calamari.Testing.Requirements;
using Calamari.Testing.Tools;

namespace Calamari.AzureScripting.Tests
{
Expand All @@ -19,14 +18,6 @@ class AzurePowerShellCommandFixture
string? tenantId;
string? subscriptionId;

static IDeploymentTool AzureCLI = new InPathDeploymentTool("Octopus.Dependencies.AzureCLI", "AzureCLI\\wbin");
static IDeploymentTool AzureCmdlets = new BoostrapperModuleDeploymentTool("Octopus.Dependencies.AzureCmdlets",
new[]
{
"Powershell\\Azure.Storage\\4.6.1",
"Powershell\\Azure\\5.3.0",
"Powershell",
});
static readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource();
readonly CancellationToken cancellationToken = CancellationTokenSource.Token;

Expand Down Expand Up @@ -113,8 +104,6 @@ void AddDefaults(CommandTestBuilderContext context)
context.Variables.Add(SpecialVariables.Action.Azure.TenantId, tenantId);
context.Variables.Add(SpecialVariables.Action.Azure.ClientId, clientId);
context.Variables.Add(SpecialVariables.Action.Azure.Password, clientSecret);
context.WithTool(AzureCLI);
context.WithTool(AzureCmdlets);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,7 @@
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.41" />
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="Shouldly" Version="2.8.2" />
<PackageReference Include="Octopus.Dependencies.AzureCLI" Version="2.0.50" GeneratePathProperty="true" />
<PackageReference Include="Octopus.Dependencies.AzureCmdlets" Version="6.13.1" GeneratePathProperty="true" />
</ItemGroup>
<ItemGroup>

</ItemGroup>
<Target Name="GetPackageFiles" AfterTargets="ResolveReferences" DependsOnTargets="RunResolvePackageDependencies">
<ItemGroup>
<Content Include="$(PkgOctopus_Dependencies_AzureCLI)/*.nupkg">
<Visible>false</Visible>
<Link>Octopus.Dependencies.AzureCLI.nupkg</Link>
<Pack>true</Pack>
<PackageCopyToOutput>true</PackageCopyToOutput>
<PackageFlatten>true</PackageFlatten>
<PackagePath>contentFiles/any/any/Octopus.Dependencies.AzureCLI.nupkg</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="$(PkgOctopus_Dependencies_AzureCmdlets)/*.nupkg">
<Visible>false</Visible>
<Link>Octopus.Dependencies.AzureCmdlets.nupkg</Link>
<Pack>true</Pack>
<PackageCopyToOutput>true</PackageCopyToOutput>
<PackageFlatten>true</PackageFlatten>
<PackagePath>contentFiles/any/any/Octopus.Dependencies.AzureCmdlets.nupkg</PackagePath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Target>
<ItemGroup>
<ProjectReference Include="..\Calamari.AzureScripting\Calamari.AzureScripting.csproj" />
<ProjectReference Include="..\Calamari.Testing\Calamari.Testing.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.41" />
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="Shouldly" Version="2.8.2" />
<PackageReference Include="Octopus.Dependencies.TerraformCLI" Version="1.0.10" />
</ItemGroup>

<ItemGroup>
Expand Down
68 changes: 4 additions & 64 deletions source/Calamari.Testing/CommandTestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,49 +159,6 @@ List<string> GetArgs(string workingPath)
return args;
}

List<string> InstallTools(string toolsPath)
{
var extractor = new NupkgExtractor(new InMemoryLog());

var modulePaths = new List<string>();
var addToPath = new List<string>();
var platform = "win-x64";

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
platform = "linux-x64";
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
platform = "osx-x64";

foreach (var tool in context.Tools)
{
var toolPath = Path.Combine(toolsPath, tool.Id);
modulePaths.AddRange(tool.GetCompatiblePackage(platform)
.SelectValueOr(package => package.BootstrapperModulePaths, Enumerable.Empty<string>())
.Select(s => Path.Combine(toolPath, s)));

var toolPackagePath = Path.Combine(Path.GetDirectoryName(AssemblyExtensions.FullLocalPath(Assembly.GetExecutingAssembly())) ?? string.Empty, $"{tool.Id}.nupkg");
if (!File.Exists(toolPackagePath))
throw new Exception($"{tool.Id}.nupkg missing.");

extractor.Extract(toolPackagePath, toolPath);
var fullPathToTool = tool.SubFolder.None()
? toolPath
: Path.Combine(toolPath, tool.SubFolder.Value);
if (tool.ToolPathVariableToSet.Some())
context.Variables[tool.ToolPathVariableToSet.Value] = fullPathToTool
.Replace("$HOME", "#{env:HOME}")
.Replace("$TentacleHome", "#{env:TentacleHome}");

if (tool.AddToPath)
addToPath.Add(fullPathToTool);
}

var modules = string.Join(";", modulePaths);
context.Variables["Octopus.Calamari.Bootstrapper.ModulePaths"] = modules;

return addToPath;
}

void Copy(string sourcePath, string destinationPath)
{
foreach (var dirPath in Directory.EnumerateDirectories(sourcePath, "*", SearchOption.AllDirectories))
Expand Down Expand Up @@ -243,7 +200,7 @@ void CopyFilesToWorkingFolder(string workingPath)
}
}

async Task<TestCalamariCommandResult> ExecuteActionHandler(List<string> args, string workingFolder, List<string> paths)
async Task<TestCalamariCommandResult> ExecuteActionHandler(List<string> args, string workingFolder)
{
var inMemoryLog = new InMemoryLog();
var constructor = typeof(TCalamariProgram).GetConstructor(
Expand All @@ -267,8 +224,7 @@ async Task<TestCalamariCommandResult> ExecuteActionHandler(List<string> args, st
throw new Exception($"{typeof(TCalamariProgram).Name}.Run method was not found.");
}

var exitCode = await ExecuteWrapped(paths,
async () =>
var exitCode = await ExecuteWrapped(async () =>
{
if (methodInfo.ReturnType.IsGenericType)
return await (Task<int>)methodInfo.Invoke(instance, new object?[] { args.ToArray() })!;
Expand Down Expand Up @@ -312,13 +268,12 @@ async Task<TestCalamariCommandResult> ExecuteActionHandler(List<string> args, st
Environment.CurrentDirectory = workingPath;

using var toolsBasePath = TemporaryDirectory.Create();
var paths = InstallTools(toolsBasePath.DirectoryPath);

var args = GetArgs(workingPath);

CopyFilesToWorkingFolder(workingPath);

result = await ExecuteActionHandler(args, workingPath, paths);
result = await ExecuteActionHandler(args, workingPath);

if (assertWasSuccess)
{
Expand All @@ -335,23 +290,8 @@ async Task<TestCalamariCommandResult> ExecuteActionHandler(List<string> args, st
return result;
}

async Task<int> ExecuteWrapped(IReadOnlyCollection<string> paths, Func<Task<int>> func)
async Task<int> ExecuteWrapped( Func<Task<int>> func)
{
if (paths.Count > 0)
{
var originalPath = Environment.GetEnvironmentVariable("PATH");
try
{
Environment.SetEnvironmentVariable("PATH", $"{originalPath}{Path.PathSeparator}{string.Join(Path.PathSeparator.ToString(), paths)}", EnvironmentVariableTarget.Process);

return await func();
}
finally
{
Environment.SetEnvironmentVariable("PATH", originalPath, EnvironmentVariableTarget.Process);
}
}

return await func();
}
}
Expand Down
8 changes: 0 additions & 8 deletions source/Calamari.Testing/CommandTestBuilderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using Calamari.Common.Plumbing.Extensions;
using Calamari.Testing.Tools;
using Octostache;

namespace Calamari.Testing
Expand All @@ -11,7 +10,6 @@ public class CommandTestBuilderContext
{
public List<(string? filename, Stream contents)> Files = new List<(string?, Stream)>();

public List<IDeploymentTool> Tools { get; } = new();

internal bool withStagedPackageArgument;

Expand Down Expand Up @@ -52,11 +50,5 @@ public CommandTestBuilderContext WithDataFile(Stream fileContents, string? fileN
Files.Add((fileName, fileContents));
return this;
}

public CommandTestBuilderContext WithTool(IDeploymentTool tool)
{
Tools.Add(tool);
return this;
}
}
}
35 changes: 0 additions & 35 deletions source/Calamari.Testing/Tools/BootstrapperModuleDeploymentTool.cs

This file was deleted.

38 changes: 0 additions & 38 deletions source/Calamari.Testing/Tools/IDeploymentTool.cs

This file was deleted.

35 changes: 0 additions & 35 deletions source/Calamari.Testing/Tools/InPathDeploymentTool.cs

This file was deleted.