Skip to content
Merged
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
@@ -1,4 +1,3 @@
using System;

namespace Aspirate.Services.Implementations;

Expand Down Expand Up @@ -26,7 +25,7 @@ public async Task<bool> BuildAndPushContainerForProject(
containerDetails.ContainerRepository = $"{options.Prefix}/{containerDetails.ContainerRepository}";
}

await AddProjectPublishArguments(argumentsBuilder, fullProjectPath, runtimeIdentifier);
AddProjectPublishArguments(argumentsBuilder, fullProjectPath, runtimeIdentifier);
AddContainerDetailsToArguments(argumentsBuilder, containerDetails);

await shellExecutionService.ExecuteCommand(new()
Expand Down Expand Up @@ -171,33 +170,13 @@ private bool AskIfShouldRetryHandlingDuplicateFiles(bool nonInteractive)
"[red bold]Implicitly, dotnet publish does not allow duplicate filenames to be output to the artefact directory at build time.Would you like to retry the build explicitly allowing them?[/]");
}

private async Task AddProjectPublishArguments(ArgumentsBuilder argumentsBuilder, string fullProjectPath, string? runtimeIdentifier)
private static void AddProjectPublishArguments(ArgumentsBuilder argumentsBuilder, string fullProjectPath, string? runtimeIdentifier)
{
var defaultRuntimeIdentifier = GetRuntimeIdentifier();

var propertiesJson = await projectPropertyService.GetProjectPropertiesAsync(
fullProjectPath,
MsBuildPropertiesLiterals.PublishSingleFileArgument,
MsBuildPropertiesLiterals.PublishTrimmedArgument);

var msbuildProperties = JsonSerializer.Deserialize<MsBuildProperties<MsBuildPublishingProperties>>(propertiesJson ?? "{}");

if (string.IsNullOrEmpty(msbuildProperties.Properties.PublishSingleFile))
{
msbuildProperties.Properties.PublishSingleFile = DotNetSdkLiterals.DefaultSingleFile;
}

if (string.IsNullOrEmpty(msbuildProperties.Properties.PublishTrimmed))
{
msbuildProperties.Properties.PublishTrimmed = DotNetSdkLiterals.DefaultPublishTrimmed;
}

argumentsBuilder
.AppendArgument(DotNetSdkLiterals.PublishArgument, fullProjectPath)
.AppendArgument(DotNetSdkLiterals.ContainerTargetArgument, string.Empty, quoteValue: false)
.AppendArgument(DotNetSdkLiterals.PublishSingleFileArgument, msbuildProperties.Properties.PublishSingleFile)
.AppendArgument(DotNetSdkLiterals.PublishTrimmedArgument, msbuildProperties.Properties.PublishTrimmed)
.AppendArgument(DotNetSdkLiterals.SelfContainedArgument, DotNetSdkLiterals.DefaultSelfContained)
.AppendArgument(DotNetSdkLiterals.VerbosityArgument, DotNetSdkLiterals.DefaultVerbosity)
.AppendArgument(DotNetSdkLiterals.NoLogoArgument, string.Empty, quoteValue: false);

Expand Down
11 changes: 0 additions & 11 deletions src/Aspirate.Shared/Models/MsBuild/MsBuildPublishingProperties.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Aspirate.Shared.Outputs;

namespace Aspirate.Tests.ActionsTests.Containers;

public class PopulateContainerDetailsForProjectsActionTests : BaseActionTests<PopulateContainerDetailsForProjectsAction>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Aspirate.Shared.Outputs;

namespace Aspirate.Tests.ActionsTests.Manifests;

public class ApplyManifestsToClusterActionTests : BaseActionTests<ApplyManifestsToClusterAction>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Aspirate.Shared.Outputs;

namespace Aspirate.Tests.ActionsTests.Manifests;

public class GenerateAspireManifestActionTests : BaseActionTests<GenerateAspireManifestAction>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Aspirate.Shared.Outputs;

namespace Aspirate.Tests.ActionsTests.Manifests;

public class RemoveManifestsToClusterActionTests : BaseActionTests<RemoveManifestsFromClusterAction>
Expand Down
1 change: 1 addition & 0 deletions tests/Aspirate.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
global using Aspirate.Shared.Models.AspireManifests.Components.V0.Parameters;
global using Aspirate.Shared.Models.AspireManifests.Interfaces;
global using Aspirate.Shared.Models.MsBuild;
global using Aspirate.Shared.Outputs;
global using DockerComposeBuilder.Builders;
global using DockerComposeBuilder.Model.Services.BuildArguments;
global using FluentAssertions;
Expand Down
107 changes: 0 additions & 107 deletions tests/Aspirate.Tests/ServiceTests/ContainerCompositionServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,114 +1,7 @@
using Aspirate.Shared.Outputs;

namespace Aspirate.Tests.ServiceTests;

public class ContainerCompositionServiceTest
{
[Theory]
[InlineData("docker")]
[InlineData("podman")]
public async Task BuildAndPushContainerForProject_ShouldCallExpectedMethods_WhenCalled(string builder)
{
// Arrange
var fileSystem = Substitute.For<IFileSystem>();
var console = Substitute.For<IAnsiConsole>();
var projectPropertyService = Substitute.For<IProjectPropertyService>();
var shellExecutionService = Substitute.For<IShellExecutionService>();

var service = new ContainerCompositionService(fileSystem, console, projectPropertyService, shellExecutionService);

var project = new ProjectResource
{
Path = "testPath",
};

var containerDetails = new MsBuildContainerProperties();

projectPropertyService.GetProjectPropertiesAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
.Returns(
JsonSerializer.Serialize(
new MsBuildProperties<MsBuildPublishingProperties>
{
Properties = new()
{
PublishSingleFile = "true",
PublishTrimmed = "true",
},
}));

var response = builder == "docker" ? DockerInfoOutput : PodmanInfoOutput;

shellExecutionService.ExecuteCommand(Arg.Is<ShellCommandOptions>(options => options.Command != null && options.ArgumentsBuilder != null))
.Returns(Task.FromResult(new ShellCommandResult(true, response, string.Empty, 0)));

shellExecutionService.IsCommandAvailable(Arg.Any<string>())
.Returns(CommandAvailableResult.Available(builder));

// Act
var result = await service.BuildAndPushContainerForProject(project, containerDetails, new()
{
ContainerBuilder = builder,
});

// Assert
await shellExecutionService.Received(2).ExecuteCommand(Arg.Is<ShellCommandOptions>(options => options.Command != null && options.ArgumentsBuilder != null));
result.Should().BeTrue();
}

[Theory]
[InlineData("docker")]
[InlineData("podman")]
public async Task BuildAndPushContainerForProject_ShouldThrowWhenBuilderOffline(string builder)
{
// Arrange
var fileSystem = Substitute.For<IFileSystem>();
var console = Substitute.For<IAnsiConsole>();
var projectPropertyService = Substitute.For<IProjectPropertyService>();
var shellExecutionService = Substitute.For<IShellExecutionService>();

var service = new ContainerCompositionService(fileSystem, console, projectPropertyService, shellExecutionService);

var project = new ProjectResource
{
Path = "testPath",
};

var containerDetails = new MsBuildContainerProperties();

projectPropertyService.GetProjectPropertiesAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
.Returns(
JsonSerializer.Serialize(
new MsBuildProperties<MsBuildPublishingProperties>
{
Properties = new()
{
PublishSingleFile = "true",
PublishTrimmed = "true",
},
}));

var response = "{\"ServerErrors\":[\"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?\"]}";

shellExecutionService.ExecuteCommand(Arg.Is<ShellCommandOptions>(options => options.Command != null && options.ArgumentsBuilder != null))
.Returns(Task.FromResult(new ShellCommandResult(false, response, string.Empty, 0)));

shellExecutionService.ExecuteCommandWithEnvironmentNoOutput(Arg.Any<string>(), Arg.Any<ArgumentsBuilder>(),Arg.Any<Dictionary<string, string?>>())
.Returns(Task.FromResult(false));

shellExecutionService.IsCommandAvailable(Arg.Any<string>())
.Returns(CommandAvailableResult.Available(builder));

// Act
var action = () => service.BuildAndPushContainerForProject(project, containerDetails, new()
{
ContainerBuilder = builder,
});

// Assert
await action.Should().ThrowAsync<ActionCausesExitException>();
}


[Theory]
[InlineData("docker")]
[InlineData("podman")]
Expand Down
2 changes: 0 additions & 2 deletions tests/Aspirate.Tests/ServiceTests/KubeCtlServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Aspirate.Shared.Outputs;

namespace Aspirate.Tests.ServiceTests;

public class KubeCtlServiceTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Aspirate.Shared.Outputs;

namespace Aspirate.Tests.ServiceTests;

public class ProjectPropertyServiceTest
Expand Down