Skip to content

Commit 8bcea71

Browse files
committed
more test coverage
1 parent f5ae52d commit 8bcea71

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,59 @@ public void CorrelationId_Should_Return_Null_When_Not_Set()
404404
Assert.Null(Logger.CorrelationId);
405405
}
406406

407+
[Fact]
408+
public void OnEntry_WhenPropertyCasingDoesNotMatch_UsesCaseInsensitiveFallback()
409+
{
410+
// Arrange
411+
var correlationId = Guid.NewGuid().ToString();
412+
413+
// This test uses a path "/detail/CORRELATIONID" (all caps)
414+
// but the actual property is "correlationId" (camelCase)
415+
// This should trigger the case-insensitive fallback
416+
417+
// Act
418+
_testHandlers.CorrelationIdCaseInsensitiveFallback(new CloudWatchEvent<CwEvent>
419+
{
420+
Detail = new CwEvent
421+
{
422+
CorrelationId = correlationId
423+
}
424+
});
425+
426+
// Assert
427+
var allKeys = Logger.GetAllKeys()
428+
.ToDictionary(keyValuePair => keyValuePair.Key, keyValuePair => keyValuePair.Value);
429+
430+
Assert.True(allKeys.ContainsKey(LoggingConstants.KeyCorrelationId));
431+
Assert.Equal((string)allKeys[LoggingConstants.KeyCorrelationId], correlationId);
432+
}
433+
434+
[Fact]
435+
public void OnEntry_WhenNestedPropertyCasingDoesNotMatch_UsesCaseInsensitiveFallback()
436+
{
437+
// Arrange
438+
var correlationId = Guid.NewGuid().ToString();
439+
440+
// This test uses a path with mismatched casing at multiple levels
441+
// Path: "/DETAIL/CORRELATIONID" but actual properties are "detail" and "correlationId"
442+
443+
// Act
444+
_testHandlers.CorrelationIdNestedCaseInsensitive(new CloudWatchEvent<CwEvent>
445+
{
446+
Detail = new CwEvent
447+
{
448+
CorrelationId = correlationId
449+
}
450+
});
451+
452+
// Assert
453+
var allKeys = Logger.GetAllKeys()
454+
.ToDictionary(keyValuePair => keyValuePair.Key, keyValuePair => keyValuePair.Value);
455+
456+
Assert.True(allKeys.ContainsKey(LoggingConstants.KeyCorrelationId));
457+
Assert.Equal((string)allKeys[LoggingConstants.KeyCorrelationId], correlationId);
458+
}
459+
407460
[Fact]
408461
public void When_Setting_Service_Should_Update_Key()
409462
{

libraries/tests/AWS.Lambda.Powertools.Logging.Tests/Handlers/TestHandlers.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ public void CorrelationIdExtensionTest(CloudWatchEvent<CwEvent> cwEvent)
8585
}
8686
}
8787

88+
[Logging(CorrelationIdPath = "/detail/CORRELATIONID")]
89+
public void CorrelationIdCaseInsensitiveFallback(CloudWatchEvent<CwEvent> cwEvent)
90+
{
91+
// This handler uses all caps "CORRELATIONID" in the path
92+
// but the actual JSON property is "correlationId" (camelCase)
93+
// This tests the case-insensitive fallback logic
94+
}
95+
96+
[Logging(CorrelationIdPath = "/DETAIL/CORRELATIONID")]
97+
public void CorrelationIdNestedCaseInsensitive(CloudWatchEvent<CwEvent> cwEvent)
98+
{
99+
// This handler uses all caps for both path segments
100+
// but the actual JSON properties are "detail" and "correlationId"
101+
// This tests the case-insensitive fallback at multiple levels
102+
}
103+
88104
[Logging(CorrelationIdPath = "/headers/my_request_id_header")]
89105
public void CorrelationIdFromString(TestObject testObject)
90106
{

0 commit comments

Comments
 (0)