Skip to content

Commit d81b504

Browse files
committed
improve code coverage
1 parent f05e96c commit d81b504

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

libraries/tests/AWS.Lambda.Powertools.Logging.Tests/EnvironmentVariableSamplingTests.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,86 @@ public void EnvironmentVariables_ErrorLevelWithNoSampling_ShouldNotLogInfo()
167167
Assert.Contains("This is an error message", logOutput);
168168
Assert.DoesNotContain("This is an info message — should NOT appear with 0% sampling", logOutput);
169169
}
170+
171+
/// <summary>
172+
/// Test the ShouldEnableDebugSampling() method without out parameter
173+
/// </summary>
174+
[Fact]
175+
public void ShouldEnableDebugSampling_WithoutOutParameter_ShouldReturnCorrectValue()
176+
{
177+
// Arrange
178+
var config = new PowertoolsLoggerConfiguration
179+
{
180+
SamplingRate = 1.0 // 100% sampling
181+
};
182+
183+
// Act
184+
var result = config.ShouldEnableDebugSampling();
185+
186+
// Assert
187+
Assert.True(result);
188+
}
189+
190+
/// <summary>
191+
/// Test the ShouldEnableDebugSampling() method with zero sampling rate
192+
/// </summary>
193+
[Fact]
194+
public void ShouldEnableDebugSampling_WithZeroSamplingRate_ShouldReturnFalse()
195+
{
196+
// Arrange
197+
var config = new PowertoolsLoggerConfiguration
198+
{
199+
SamplingRate = 0.0 // 0% sampling
200+
};
201+
202+
// Act
203+
var result = config.ShouldEnableDebugSampling();
204+
205+
// Assert
206+
Assert.False(result);
207+
}
208+
209+
/// <summary>
210+
/// Test the RefreshSampleRateCalculation() method without out parameter
211+
/// </summary>
212+
[Fact]
213+
public void RefreshSampleRateCalculation_WithoutOutParameter_ShouldReturnCorrectValue()
214+
{
215+
// Arrange
216+
var config = new PowertoolsLoggerConfiguration
217+
{
218+
SamplingRate = 1.0, // 100% sampling
219+
InitialLogLevel = LogLevel.Error,
220+
MinimumLogLevel = LogLevel.Error
221+
};
222+
223+
// Act - First call should return false due to cold start protection
224+
var firstResult = config.RefreshSampleRateCalculation();
225+
226+
// Second call should return true with 100% sampling
227+
var secondResult = config.RefreshSampleRateCalculation();
228+
229+
// Assert
230+
Assert.False(firstResult); // Cold start protection
231+
Assert.True(secondResult); // Should enable sampling
232+
}
233+
234+
/// <summary>
235+
/// Test the RefreshSampleRateCalculation() method with zero sampling rate
236+
/// </summary>
237+
[Fact]
238+
public void RefreshSampleRateCalculation_WithZeroSamplingRate_ShouldReturnFalse()
239+
{
240+
// Arrange
241+
var config = new PowertoolsLoggerConfiguration
242+
{
243+
SamplingRate = 0.0 // 0% sampling
244+
};
245+
246+
// Act
247+
var result = config.RefreshSampleRateCalculation();
248+
249+
// Assert
250+
Assert.False(result);
251+
}
170252
}

0 commit comments

Comments
 (0)