Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -60,7 +60,8 @@ public static IResourceBuilder<GoFeatureFlagResource> AddGoFeatureFlag(
name: GoFeatureFlagResource.PrimaryEndpointName)
.WithHttpHealthCheck("/health")
.WithEntrypoint("/go-feature-flag")
.WithArgs(args);
.WithArgs(args)
.WithOtlpExporter();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net.Sockets;
using Aspire.Components.Common.Tests;
using Aspire.Hosting;
using Aspire.Hosting.ApplicationModel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace CommunityToolkit.Aspire.Hosting.GoFeatureFlag.Tests;
Expand Down Expand Up @@ -90,42 +93,36 @@ public async Task GoFeatureFlagCreatesConnectionString()
Assert.Equal($"Endpoint=http://localhost:27020", connectionString);
Assert.Equal("Endpoint=http://{goff.bindings.http.host}:{goff.bindings.http.port}", connectionStringResource.ConnectionStringExpression.ValueExpression);
}

[Theory]
[InlineData(LogLevel.Debug, "DEBUG")]
[InlineData(LogLevel.Information, "INFO")]
[InlineData(LogLevel.Warning, "WARN")]
[InlineData(LogLevel.Error, "ERROR")]
public async Task AddSurrealServerContainerWithLogLevel(LogLevel logLevel, string? expected)
{
var appBuilder = DistributedApplication.CreateBuilder();

var goff = appBuilder
.AddGoFeatureFlag("goff")
.WithLogLevel(logLevel);

using var app = appBuilder.Build();

var config = await goff.Resource.GetEnvironmentVariableValuesAsync();

bool hasValue = config.TryGetValue("LOGLEVEL", out var value);

Assert.True(hasValue);
Assert.Equal(expected, value);
}

[Theory]
[InlineData(LogLevel.Trace)]
[InlineData(LogLevel.Critical)]
[InlineData(LogLevel.None)]
public void AddSurrealServerContainerWithLogLevelThrowsOnUnsupportedLogLevel(LogLevel logLevel)
{
var appBuilder = DistributedApplication.CreateBuilder();

var func = () => appBuilder
.AddGoFeatureFlag("goff")
.WithLogLevel(logLevel);

Assert.Throws<ArgumentOutOfRangeException>(func);
}

[Fact]
public void AddGoFeatureFlagAddsOtelAnnotation()
{
var appBuilder = DistributedApplication.CreateBuilder();

appBuilder.AddGoFeatureFlag("goff");

using var app = appBuilder.Build();

var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
var resource = Assert.Single(appModel.Resources.OfType<GoFeatureFlagResource>());

// Verify that OtlpExporterAnnotation is present (added by WithOtlpExporter)
// This annotation marks the resource as an OTEL exporter
Assert.True(resource.HasAnnotationOfType<OtlpExporterAnnotation>());
}
}
Loading