Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Mar 30, 2024
1 parent 0a48233 commit 46a0071
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/Aspire.Hosting/DistributedApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)

AppHostDirectory = options.ProjectDirectory ?? _innerBuilder.Environment.ContentRootPath;

// Set configuration
ConfigurePublishingOptions(options);
_innerBuilder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
{
// Make the app host directory available to the application via configuration
["AppHost:Directory"] = AppHostDirectory
});

if (!IsOtlpApiKeyAuthDisabled(_innerBuilder.Configuration))
{
// Set a random API key for the OTLP exporter.
Expand All @@ -97,7 +98,6 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
}
);
}

if (!options.DisableDashboard)
{
// Set a random API key for the OTLP exporter.
Expand Down Expand Up @@ -136,7 +136,6 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
_innerBuilder.Services.AddSingleton<IKubernetesService, KubernetesService>();

// Publishing support
ConfigurePublishingOptions(options);
_innerBuilder.Services.AddLifecycleHook<Http2TransportMutationHook>();
_innerBuilder.Services.AddKeyedSingleton<IDistributedApplicationPublisher, ManifestPublisher>("manifest");
_innerBuilder.Services.AddKeyedSingleton<IDistributedApplicationPublisher, DcpPublisher>("dcp");
Expand Down
30 changes: 20 additions & 10 deletions tests/Aspire.Hosting.Tests/ProjectResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Aspire.Hosting.Tests.Helpers;
using Aspire.Hosting.Tests.Utils;
using Aspire.Hosting.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Xunit;

Expand Down Expand Up @@ -91,11 +90,7 @@ public async Task AddProjectAddsEnvironmentVariablesAndServiceMetadata()
[InlineData(null, true)]
public async Task AddProjectAddsEnvironmentVariablesAndServiceMetadata_OtlpAuthDisabledSetting(string? value, bool hasHeader)
{
var appBuilder = CreateBuilder();
appBuilder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
{
["DOTNET_DISABLE_OTLP_API_KEY_AUTH"] = value
});
var appBuilder = CreateBuilder(args: [$"DOTNET_DISABLE_OTLP_API_KEY_AUTH={value}"]);

appBuilder.AddProject<TestProject>("projectName", launchProfileName: null);
using var app = appBuilder.Build();
Expand All @@ -108,7 +103,14 @@ public async Task AddProjectAddsEnvironmentVariablesAndServiceMetadata_OtlpAuthD

var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(resource);

Assert.Equal(hasHeader, config.ContainsKey("OTEL_EXPORTER_OTLP_HEADERS"));
if (hasHeader)
{
Assert.True(config.ContainsKey("OTEL_EXPORTER_OTLP_HEADERS"), "Config should have 'OTEL_EXPORTER_OTLP_HEADERS' header and doesn't.");
}
else
{
Assert.False(config.ContainsKey("OTEL_EXPORTER_OTLP_HEADERS"), "Config shouldn't have 'OTEL_EXPORTER_OTLP_HEADERS' header and does.");
}
}

[Fact]
Expand Down Expand Up @@ -282,10 +284,18 @@ public async Task VerifyManifest(bool disableForwardedHeaders)
Assert.Equal(expectedManifest, manifest.ToString());
}

private static IDistributedApplicationBuilder CreateBuilder(DistributedApplicationOperation operation = DistributedApplicationOperation.Publish)
private static IDistributedApplicationBuilder CreateBuilder(string[]? args = null, DistributedApplicationOperation operation = DistributedApplicationOperation.Publish)
{
var args = operation == DistributedApplicationOperation.Publish ? new[] { "--publisher", "manifest" } : Array.Empty<string>();
var appBuilder = DistributedApplication.CreateBuilder(args);
var resovledArgs = new List<string>();
if (args != null)
{
resovledArgs.AddRange(args);
}
if (operation == DistributedApplicationOperation.Publish)
{
resovledArgs.AddRange(["--publisher", "manifest"]);
}
var appBuilder = DistributedApplication.CreateBuilder(resovledArgs.ToArray());
// Block DCP from actually starting anything up as we don't need it for this test.
appBuilder.Services.AddKeyedSingleton<IDistributedApplicationPublisher, NoopPublisher>("manifest");

Expand Down

0 comments on commit 46a0071

Please sign in to comment.