Skip to content

Commit 84dfe0a

Browse files
committed
Add tests for WithLoglevel method to validate environment variable addition and error handling
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
1 parent 585eb86 commit 84dfe0a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/CommunityToolkit.Aspire.Hosting.Flagd.Tests/AddFlagdTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,45 @@ public void WithLoggingAddsEnvironmentVariable()
151151
Assert.NotEmpty(envAnnotations);
152152
}
153153

154+
[Fact]
155+
public void WithLoglevelDebugAddsEnvironmentVariable()
156+
{
157+
var builder = DistributedApplication.CreateBuilder();
158+
builder.AddFlagd(FlagdName).WithLoglevel(Microsoft.Extensions.Logging.LogLevel.Debug);
159+
160+
using var app = builder.Build();
161+
162+
var appModel = app.Services.GetRequiredService<DistributedApplicationModel>();
163+
var resource = Assert.Single(appModel.Resources.OfType<FlagdResource>());
164+
165+
var envAnnotations = resource.Annotations.OfType<EnvironmentCallbackAnnotation>().ToArray();
166+
Assert.NotEmpty(envAnnotations);
167+
}
168+
169+
[Theory]
170+
[InlineData(Microsoft.Extensions.Logging.LogLevel.Trace)]
171+
[InlineData(Microsoft.Extensions.Logging.LogLevel.Information)]
172+
[InlineData(Microsoft.Extensions.Logging.LogLevel.Warning)]
173+
[InlineData(Microsoft.Extensions.Logging.LogLevel.Error)]
174+
[InlineData(Microsoft.Extensions.Logging.LogLevel.Critical)]
175+
[InlineData(Microsoft.Extensions.Logging.LogLevel.None)]
176+
public void WithLoglevelThrowsForUnsupportedLogLevels(Microsoft.Extensions.Logging.LogLevel logLevel)
177+
{
178+
var builder = DistributedApplication.CreateBuilder();
179+
var flagd = builder.AddFlagd(FlagdName);
180+
181+
var exception = Assert.Throws<InvalidOperationException>(() => flagd.WithLoglevel(logLevel));
182+
Assert.Equal("Only debug log level is supported", exception.Message);
183+
}
184+
185+
[Fact]
186+
public void WithLoglevelThrowsWhenBuilderIsNull()
187+
{
188+
IResourceBuilder<FlagdResource> builder = null!;
189+
190+
Assert.Throws<ArgumentNullException>(() => builder.WithLoglevel(Microsoft.Extensions.Logging.LogLevel.Debug));
191+
}
192+
154193
[Fact]
155194
public void WithBindFileSyncAddsBindMountAndArgs()
156195
{

0 commit comments

Comments
 (0)