Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename DCP command-line args. #5082

Merged
merged 2 commits into from
Jul 29, 2024
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
13 changes: 11 additions & 2 deletions src/Aspire.Hosting/Dcp/DcpOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ internal class ConfigureDefaultDcpOptions(
public void Configure(DcpOptions options)
{
var dcpPublisherConfiguration = configuration.GetSection(DcpPublisher);
var assemblyMetadata = appOptions.Assembly?.GetCustomAttributes<AssemblyMetadataAttribute>();

if (!string.IsNullOrEmpty(dcpPublisherConfiguration[nameof(options.CliPath)]))
{
Expand All @@ -119,10 +120,18 @@ public void Configure(DcpOptions options)
}
else
{
var assemblyMetadata = appOptions.Assembly?.GetCustomAttributes<AssemblyMetadataAttribute>();
options.CliPath = GetMetadataValue(assemblyMetadata, DcpCliPathMetadataKey);
options.ExtensionsPath = GetMetadataValue(assemblyMetadata, DcpExtensionsPathMetadataKey);
options.BinPath = GetMetadataValue(assemblyMetadata, DcpBinPathMetadataKey);
}

if (!string.IsNullOrEmpty(dcpPublisherConfiguration[nameof(options.DashboardPath)]))
{
// If an explicit path to DCP was provided from configuration, don't try to resolve via assembly attributes
options.DashboardPath = dcpPublisherConfiguration[nameof(options.DashboardPath)];
}
else
{
options.DashboardPath = GetMetadataValue(assemblyMetadata, DashboardPathMetadataKey);
}

Expand All @@ -143,7 +152,7 @@ public void Configure(DcpOptions options)
}
else
{
throw new InvalidOperationException($"Invalid value \"{dcpPublisherConfiguration[nameof(options.DependencyCheckTimeout)]}\" for \"--dependency-check-timeout\". Exepcted an integer value.");
throw new InvalidOperationException($"Invalid value \"{dcpPublisherConfiguration[nameof(options.DependencyCheckTimeout)]}\" for \"--dcp-dependency-check-timeout\". Expected an integer value.");
}
}
else
Expand Down
5 changes: 3 additions & 2 deletions src/Aspire.Hosting/DistributedApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ private void ConfigurePublishingOptions(DistributedApplicationOptions options)
{ "--publisher", "Publishing:Publisher" },
{ "--output-path", "Publishing:OutputPath" },
{ "--dcp-cli-path", "DcpPublisher:CliPath" },
{ "--container-runtime", "DcpPublisher:ContainerRuntime" },
{ "--dependency-check-timeout", "DcpPublisher:DependencyCheckTimeout" },
{ "--dcp-container-runtime", "DcpPublisher:ContainerRuntime" },
{ "--dcp-dependency-check-timeout", "DcpPublisher:DependencyCheckTimeout" },
{ "--dcp-dashboard-path", "DcpPublisher:DashboardPath" },
};
_innerBuilder.Configuration.AddCommandLine(options.Args ?? [], switchMappings);
_innerBuilder.Services.Configure<PublishingOptions>(_innerBuilder.Configuration.GetSection(PublishingOptions.Publishing));
Expand Down
62 changes: 62 additions & 0 deletions tests/Aspire.Hosting.Tests/Dcp/DcpCliArgsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.Dcp;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Xunit;

namespace Aspire.Hosting.Tests.Dcp;

public class DcpCliArgsTests
{
[Fact]
public void TestDcpCliPathArgumentPopulatesConfig()
{
var builder = DistributedApplication.CreateBuilder([
"--dcp-cli-path", "/not/a/valid/path",
]);

Assert.Equal("/not/a/valid/path", builder.Configuration["DcpPublisher:CliPath"]);
}

[Fact]
public void TestDcpDependencyCheckTimeoutPopulatesConfig()
{
var builder = DistributedApplication.CreateBuilder([
"--dcp-dependency-check-timeout", "42",
]);

Assert.Equal("42", builder.Configuration["DcpPublisher:DependencyCheckTimeout"]);
}

[Fact]
public void TestDcpContainerRuntimePopulatesConfig()
{
var builder = DistributedApplication.CreateBuilder([
"--dcp-container-runtime", "not-a-valid-container-runtime",
]);

Assert.Equal("not-a-valid-container-runtime", builder.Configuration["DcpPublisher:ContainerRuntime"]);
}

[Fact]
public void TestDcpOptionsPopulated()
{
var builder = DistributedApplication.CreateBuilder(
[
"--dcp-cli-path", "/not/a/valid/path",
"--dcp-container-runtime", "not-a-valid-container-runtime",
"--dcp-dependency-check-timeout", "42",
"--dcp-dashboard-path", "/not/a/valid/path"
]);

using var app = builder.Build();
var dcpOptions = app.Services.GetRequiredService<IOptions<DcpOptions>>().Value;

Assert.Equal("not-a-valid-container-runtime", dcpOptions.ContainerRuntime);
Assert.Equal(42, dcpOptions.DependencyCheckTimeout);
Assert.Equal("/not/a/valid/path", dcpOptions.CliPath);
Assert.Equal("/not/a/valid/path", dcpOptions.DashboardPath);
}
}