Skip to content

Commit 2dbae69

Browse files
committed
Prepare Logging E2E test to support paramaterized versions by logging backend.
1 parent d9fe1e1 commit 2dbae69

File tree

2 files changed

+54
-36
lines changed

2 files changed

+54
-36
lines changed

powertools-e2e-tests/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@
102102
<artifactId>junit-jupiter-engine</artifactId>
103103
<scope>test</scope>
104104
</dependency>
105+
<dependency>
106+
<groupId>org.junit.jupiter</groupId>
107+
<artifactId>junit-jupiter-params</artifactId>
108+
<scope>test</scope>
109+
</dependency>
105110
<dependency>
106111
<groupId>org.assertj</groupId>
107112
<artifactId>assertj-core</artifactId>

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/LoggingE2ET.java

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
import java.util.stream.Stream;
2727

2828
import org.junit.jupiter.api.AfterAll;
29-
import org.junit.jupiter.api.BeforeAll;
30-
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.TestInstance;
3130
import org.junit.jupiter.api.Timeout;
31+
import org.junit.jupiter.params.ParameterizedTest;
32+
import org.junit.jupiter.params.provider.ValueSource;
3233

3334
import com.fasterxml.jackson.core.JsonProcessingException;
3435
import com.fasterxml.jackson.databind.JsonNode;
@@ -37,20 +38,19 @@
3738
import software.amazon.lambda.powertools.testutils.Infrastructure;
3839
import software.amazon.lambda.powertools.testutils.lambda.InvocationResult;
3940

41+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
4042
class LoggingE2ET {
4143

4244
private static final ObjectMapper objectMapper = new ObjectMapper();
4345

44-
private static Infrastructure infrastructure;
45-
private static String functionName;
46+
private Infrastructure infrastructure;
47+
private String functionName;
4648

47-
@BeforeAll
48-
@Timeout(value = 10, unit = TimeUnit.MINUTES)
49-
static void setup() {
49+
private void setupInfrastructure(String pathToFunction) {
5050
infrastructure = Infrastructure.builder()
51-
.testName(LoggingE2ET.class.getSimpleName())
51+
.testName(LoggingE2ET.class.getSimpleName() + "-" + pathToFunction)
5252
.tracing(true)
53-
.pathToFunction("logging")
53+
.pathToFunction(pathToFunction)
5454
.environmentVariables(
5555
Stream.of(new String[][] {
5656
{ "POWERTOOLS_LOG_LEVEL", "INFO" },
@@ -63,37 +63,50 @@ static void setup() {
6363
}
6464

6565
@AfterAll
66-
static void tearDown() {
66+
void tearDown() {
6767
if (infrastructure != null) {
6868
infrastructure.destroy();
6969
}
7070
}
7171

72-
@Test
73-
void test_logInfoWithAdditionalKeys() throws JsonProcessingException {
74-
// GIVEN
75-
String orderId = UUID.randomUUID().toString();
76-
String event = "{\"message\":\"New Order\", \"keys\":{\"orderId\":\"" + orderId + "\"}}";
77-
78-
// WHEN
79-
InvocationResult invocationResult1 = invokeFunction(functionName, event);
80-
InvocationResult invocationResult2 = invokeFunction(functionName, event);
81-
82-
// THEN
83-
String[] functionLogs = invocationResult1.getLogs().getFunctionLogs(INFO);
84-
assertThat(functionLogs).hasSize(1);
85-
86-
JsonNode jsonNode = objectMapper.readTree(functionLogs[0]);
87-
assertThat(jsonNode.get("message").asText()).isEqualTo("New Order");
88-
assertThat(jsonNode.get("orderId").asText()).isEqualTo(orderId);
89-
assertThat(jsonNode.get("cold_start").asBoolean()).isTrue();
90-
assertThat(jsonNode.get("xray_trace_id").asText()).isNotBlank();
91-
assertThat(jsonNode.get("function_request_id").asText()).isEqualTo(invocationResult1.getRequestId());
92-
93-
// second call should not be cold start
94-
functionLogs = invocationResult2.getLogs().getFunctionLogs(INFO);
95-
assertThat(functionLogs).hasSize(1);
96-
jsonNode = objectMapper.readTree(functionLogs[0]);
97-
assertThat(jsonNode.get("cold_start").asBoolean()).isFalse();
72+
@ParameterizedTest
73+
@ValueSource(strings = { "logging" })
74+
@Timeout(value = 15, unit = TimeUnit.MINUTES)
75+
void test_logInfoWithAdditionalKeys(String pathToFunction) throws JsonProcessingException {
76+
setupInfrastructure(pathToFunction);
77+
78+
try {
79+
// GIVEN
80+
String orderId = UUID.randomUUID().toString();
81+
String event = "{\"message\":\"New Order\", \"keys\":{\"orderId\":\"" + orderId + "\"}}";
82+
83+
// WHEN
84+
InvocationResult invocationResult1 = invokeFunction(functionName, event);
85+
InvocationResult invocationResult2 = invokeFunction(functionName, event);
86+
87+
// THEN
88+
String[] functionLogs = invocationResult1.getLogs().getFunctionLogs(INFO);
89+
assertThat(functionLogs).hasSize(1);
90+
91+
JsonNode jsonNode = objectMapper.readTree(functionLogs[0]);
92+
assertThat(jsonNode.get("message").asText()).isEqualTo("New Order");
93+
assertThat(jsonNode.get("orderId").asText()).isEqualTo(orderId);
94+
assertThat(jsonNode.get("cold_start").asBoolean()).isTrue();
95+
assertThat(jsonNode.get("xray_trace_id").asText()).isNotBlank();
96+
assertThat(jsonNode.get("function_request_id").asText()).isEqualTo(invocationResult1.getRequestId());
97+
98+
// second call should not be cold start
99+
functionLogs = invocationResult2.getLogs().getFunctionLogs(INFO);
100+
assertThat(functionLogs).hasSize(1);
101+
jsonNode = objectMapper.readTree(functionLogs[0]);
102+
assertThat(jsonNode.get("cold_start").asBoolean()).isFalse();
103+
104+
} finally {
105+
// Clean up infrastructure after each parameter
106+
if (infrastructure != null) {
107+
infrastructure.destroy();
108+
infrastructure = null;
109+
}
110+
}
98111
}
99112
}

0 commit comments

Comments
 (0)