mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
test(compat): gate Lambda dispatch tests on container availability (#387)
Tests that invoke Lambda with REQUEST_RESPONSE depend on Docker-in-Docker for container execution. When DinD is unavailable in CI, these tests time out instead of skipping. Add a shared memoized probe (TestFixtures.isLambdaDispatchAvailable) that creates a throwaway Lambda, invokes it with a 30s timeout, and caches the result per JVM. Tests that need real dispatch now skip cleanly via Assumptions.assumeTrue. Java: ApiGatewayV2ExecuteTest, LambdaLongPathTest, S3NotificationsTest Go: lambda_test.go Invoke subtest
This commit is contained in:
5 files changed
+129
-8
No files matched your search
+29
-7
@@ -151,6 +151,30 @@ class ApiGatewayV2ExecuteTest {
|
||||
} catch (ConnectException e) {
|
||||
Assumptions.assumeTrue(false, "Floci endpoint is not reachable at " + TestFixtures.endpoint());
|
||||
}
|
||||
|
||||
// Probe result is memoized in TestFixtures; skip warmup if dispatch is unavailable
|
||||
if (!TestFixtures.isLambdaDispatchAvailable()) {
|
||||
lambdaDispatchAvailable = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Warm the API GW → Lambda dispatch path and verify the response carries
|
||||
// the expected Lambda proxy envelope (statusCode in body). The direct
|
||||
// probe above only tests raw invoke; APIGW integration may behave differently.
|
||||
try {
|
||||
HttpResponse<String> warmup = http.send(HttpRequest.newBuilder()
|
||||
.uri(URI.create(baseUrl + "/echo/warmup"))
|
||||
.timeout(Duration.ofSeconds(30))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString("{}"))
|
||||
.build(),
|
||||
HttpResponse.BodyHandlers.ofString());
|
||||
JsonNode warmupBody = JSON.readTree(warmup.body());
|
||||
lambdaDispatchAvailable = warmup.statusCode() == 200
|
||||
&& warmupBody.path("statusCode").asInt() == 200;
|
||||
} catch (Exception e) {
|
||||
lambdaDispatchAvailable = false;
|
||||
}
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
@@ -174,6 +198,9 @@ class ApiGatewayV2ExecuteTest {
|
||||
@Test
|
||||
@Order(1)
|
||||
void dispatchesHttpApiRouteToLambdaWithV2EventShape() throws Exception {
|
||||
Assumptions.assumeTrue(lambdaDispatchAvailable,
|
||||
"Lambda dispatch unavailable in this environment");
|
||||
|
||||
HttpResponse<String> response = http.send(HttpRequest.newBuilder()
|
||||
.uri(URI.create(baseUrl + "/echo/child/path?color=blue"))
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
@@ -183,14 +210,9 @@ class ApiGatewayV2ExecuteTest {
|
||||
.build(),
|
||||
HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
// Lambda dispatch may not work in CI (no Docker-in-Docker for containers).
|
||||
// Gate this and downstream tests on successful dispatch.
|
||||
JsonNode body = JSON.readTree(response.body());
|
||||
lambdaDispatchAvailable = response.statusCode() == 200
|
||||
&& body.path("statusCode").asInt() == 200;
|
||||
Assumptions.assumeTrue(lambdaDispatchAvailable,
|
||||
"Lambda dispatch unavailable (HTTP " + response.statusCode()
|
||||
+ ", body statusCode " + body.path("statusCode").asInt() + ")");
|
||||
assertThat(response.statusCode()).isEqualTo(200);
|
||||
assertThat(body.path("statusCode").asInt()).isEqualTo(200);
|
||||
|
||||
JsonNode event = JSON.readTree(body.path("body").asText());
|
||||
|
||||
|
||||
@@ -66,6 +66,9 @@ class LambdaLongPathTest {
|
||||
@Test
|
||||
@Order(2)
|
||||
void longPathFileIsAccessibleAtRuntime() throws Exception {
|
||||
Assumptions.assumeTrue(TestFixtures.isLambdaDispatchAvailable(),
|
||||
"Lambda REQUEST_RESPONSE dispatch unavailable in this environment");
|
||||
|
||||
InvokeResponse response = lambda.invoke(InvokeRequest.builder()
|
||||
.functionName(FUNCTION_NAME)
|
||||
.invocationType(InvocationType.REQUEST_RESPONSE)
|
||||
|
||||
+4
@@ -1,6 +1,7 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -206,6 +207,9 @@ class S3NotificationsTest {
|
||||
|
||||
@Test
|
||||
void lambdaNotificationInvokesFunctionForMatchingObject() throws InterruptedException {
|
||||
Assumptions.assumeTrue(TestFixtures.isLambdaDispatchAvailable(),
|
||||
"Lambda REQUEST_RESPONSE dispatch unavailable in this environment");
|
||||
|
||||
String key = "incoming/report.csv";
|
||||
String expectedMessage = "[s3-notification] received " + bucketName + "/" + key;
|
||||
|
||||
|
||||
Reference in new issue
Block a user