Skip to content

Commit dbb88cb

Browse files
committed
complete tests
1 parent e1b58b0 commit dbb88cb

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

powertools-logging/src/test/java/software/amazon/lambda/powertools/logging/LoggingUtilsTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void setUp() {
3131
}
3232

3333
@Test
34-
void shouldSetCustomKeyOnThreadContext() {
34+
void shouldSetCustomKeyInLoggingContext() {
3535
LoggingUtils.appendKey("org/slf4j/test", "value");
3636

3737
assertThat(MDC.getCopyOfContextMap())
@@ -40,7 +40,7 @@ void shouldSetCustomKeyOnThreadContext() {
4040
}
4141

4242
@Test
43-
void shouldSetCustomKeyAsMapOnThreadContext() {
43+
void shouldSetCustomKeyAsMapInLoggingContext() {
4444
Map<String, String> customKeys = new HashMap<>();
4545
customKeys.put("org/slf4j/test", "value");
4646
customKeys.put("test1", "value1");
@@ -54,7 +54,7 @@ void shouldSetCustomKeyAsMapOnThreadContext() {
5454
}
5555

5656
@Test
57-
void shouldRemoveCustomKeyOnThreadContext() {
57+
void shouldRemoveCustomKeyInLoggingContext() {
5858
LoggingUtils.appendKey("org/slf4j/test", "value");
5959

6060
assertThat(MDC.getCopyOfContextMap())
@@ -68,7 +68,7 @@ void shouldRemoveCustomKeyOnThreadContext() {
6868
}
6969

7070
@Test
71-
void shouldRemoveCustomKeysOnThreadContext() {
71+
void shouldRemoveCustomKeysInLoggingContext() {
7272
Map<String, String> customKeys = new HashMap<>();
7373
customKeys.put("org/slf4j/test", "value");
7474
customKeys.put("test1", "value1");
@@ -85,4 +85,13 @@ void shouldRemoveCustomKeysOnThreadContext() {
8585
assertThat(MDC.getCopyOfContextMap())
8686
.isEmpty();
8787
}
88+
89+
@Test
90+
void shouldAddCorrelationIdToLoggingContext() {
91+
LoggingUtils.setCorrelationId("correlationID_12345");
92+
93+
assertThat(MDC.getCopyOfContextMap())
94+
.hasSize(1)
95+
.containsEntry("correlation_id", "correlationID_12345");
96+
}
8897
}

powertools-logging/src/test/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspectTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,19 @@ void shouldLogDebugWhenSamplingEnvVarEqualsOne() {
192192

193193
@Test
194194
@SetEnvironmentVariable(key = "POWERTOOLS_LOGGER_SAMPLE_RATE", value = "42")
195+
void shouldNotLogDebugWhenSamplingEnvVarIsTooBig() {
196+
requestHandler.handleRequest(new Object(), context);
197+
File logFile = new File("target/logfile.json");
198+
assertThat(contentOf(logFile)).doesNotContain("Test debug event");
199+
}
200+
201+
@Test
202+
@SetEnvironmentVariable(key = "POWERTOOLS_LOGGER_SAMPLE_RATE", value = "NotANumber")
195203
void shouldNotLogDebugWhenSamplingEnvVarIsInvalid() {
196204
requestHandler.handleRequest(new Object(), context);
197205
File logFile = new File("target/logfile.json");
198206
assertThat(contentOf(logFile)).doesNotContain("Test debug event");
207+
assertThat(contentOf(logFile)).contains("Skipping sampling rate on environment variable configuration because of invalid value");
199208
}
200209

201210
@Test

0 commit comments

Comments
 (0)