Skip to content

Commit d233109

Browse files
committed
fix tests for new Enabled validation
1 parent 133c692 commit d233109

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

libraries/src/AWS.Lambda.Powertools.Logging/PowertoolsLoggerConfiguration.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,14 @@ public JsonSerializerOptions JsonOptions
226226
}
227227
}
228228

229+
private LogBufferingOptions _logBuffering = new LogBufferingOptions();
230+
229231
/// <summary>
230-
/// Configuration options for log buffering. Logs below the specified level will be buffered
231-
/// until the buffer is flushed or an error occurs.
232-
/// Buffer logs at the WARNING, INFO, and DEBUG levels and reduce CloudWatch costs by decreasing the number of emitted log messages.
233-
/// <para></para>
234-
/// Log buffering is disabled by default. Set <see cref="LogBufferingOptions.Enabled"/> to true to enable it.
232+
/// Gets or sets the configuration options for log buffering.
233+
/// When enabled, logs below the specified level are buffered until explicitly flushed or an error occurs.
234+
/// This can reduce CloudWatch costs by decreasing the number of emitted log messages.
235+
/// <para>Log buffering is disabled by default. Set <see cref="LogBufferingOptions.Enabled"/> to true to enable it.</para>
236+
/// <para>Setting this property to null will reset it to a default <see cref="LogBufferingOptions"/> instance with buffering disabled.</para>
235237
/// </summary>
236238
/// <example>
237239
/// <code>
@@ -248,8 +250,6 @@ public JsonSerializerOptions JsonOptions
248250
/// options.LogBuffering.BufferAtLogLevel = LogLevel.Warning;
249251
/// </code>
250252
/// </example>
251-
private LogBufferingOptions _logBuffering = new LogBufferingOptions();
252-
253253
public LogBufferingOptions LogBuffering
254254
{
255255
get => _logBuffering;

libraries/tests/AWS.Lambda.Powertools.Logging.Tests/Attributes/LoggerAspectTests.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,17 +546,17 @@ public void OnEntry_WhenBufferingDisabled_ShouldSetBufferingEnabledFlagToFalse()
546546
}
547547

548548
[Fact]
549-
public void OnEntry_WhenLogBufferingIsNull_ShouldSetBufferingEnabledFlagToFalse()
549+
public void OnEntry_WhenLogBufferingIsSetToNull_ShouldDefaultToDisabledBuffering()
550550
{
551-
// Arrange - This test covers the null path: _bufferingEnabled = _currentConfig.LogBuffering?.Enabled == true;
551+
// Arrange - This test covers the null assignment path: LogBuffering setter defaults to new LogBufferingOptions() when null
552552
var consoleOut = Substitute.For<IConsoleWrapper>();
553553

554554
var config = new PowertoolsLoggerConfiguration
555555
{
556556
Service = "TestService",
557557
MinimumLogLevel = LogLevel.Information,
558558
LogOutput = consoleOut,
559-
LogBuffering = null
559+
LogBuffering = null // This will be converted to a default LogBufferingOptions with Enabled = false
560560
};
561561

562562
PowertoolsLoggingBuilderExtensions.UpdateConfiguration(config);
@@ -581,9 +581,10 @@ public void OnEntry_WhenLogBufferingIsNull_ShouldSetBufferingEnabledFlagToFalse(
581581
var loggingAspect = new LoggingAspect(logger);
582582
loggingAspect.OnEntry(aspectArgs);
583583

584-
// Assert
584+
// Assert - LogBuffering should never be null, but Enabled should be false by default
585585
var updatedConfig = PowertoolsLoggingBuilderExtensions.GetCurrentConfiguration();
586-
Assert.Null(updatedConfig.LogBuffering);
586+
Assert.NotNull(updatedConfig.LogBuffering);
587+
Assert.False(updatedConfig.LogBuffering.Enabled);
587588
}
588589

589590
public void Dispose()

0 commit comments

Comments
 (0)