Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

test(apigateway): cover imported REST HTTP_PROXY (#3750)

Vũ Thế Huyec22eac13b65
diff --git a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayHttpProxyIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayHttpProxyIntegrationTest.java
index 4b4b8522d1..695b101074 100644
--- a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayHttpProxyIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayHttpProxyIntegrationTest.java
@@ -16,6 +16,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
@@ -159,6 +160,35 @@ class ApiGatewayHttpProxyIntegrationTest {
return "http://127.0.0.1:" + backendPort + "/{proxy}";
}
+ private String importProxyApi(String spec) {
+ String apiId = given()
+ .contentType(ContentType.JSON)
+ .queryParam("mode", "import")
+ .body(String.format(Locale.ROOT, spec, backendPort))
+ .when().post("/restapis")
+ .then().statusCode(201)
+ .extract().path("id");
+ createdApis.add(apiId);
+ return apiId;
+ }
+
+ private String deploy(String apiId) {
+ return given()
+ .contentType(ContentType.JSON)
+ .body("{}")
+ .when().post("/restapis/" + apiId + "/deployments")
+ .then().statusCode(201)
+ .extract().path("id");
+ }
+
+ private void createStage(String apiId, String deploymentId) {
+ given()
+ .contentType(ContentType.JSON)
+ .body("{\"stageName\":\"test\",\"deploymentId\":\"" + deploymentId + "\"}")
+ .when().post("/restapis/" + apiId + "/stages")
+ .then().statusCode(201);
+ }
+
@AfterEach
void cleanup() {
for (String apiId : createdApis) {
@@ -183,6 +213,44 @@ class ApiGatewayHttpProxyIntegrationTest {
assertEquals("limit=5", lastQuery.get());
}
+ @Test
+ void importsAndInvokesHttpProxyFromOpenApi() {
+ resetRecordings();
+ String spec = """
+ {
+ "openapi": "3.0.1",
+ "info": { "title": "ImportedHttpProxy", "version": "1.0" },
+ "paths": {
+ "/orders/{proxy}": {
+ "get": {
+ "parameters": [
+ { "name": "proxy", "in": "path", "required": true,
+ "schema": { "type": "string" } }
+ ],
+ "x-amazon-apigateway-integration": {
+ "type": "http_proxy",
+ "httpMethod": "GET",
+ "uri": "http://127.0.0.1:%d/{proxy}"
+ }
+ }
+ }
+ }
+ }
+ """;
+
+ String apiId = importProxyApi(spec);
+ String deploymentId = deploy(apiId);
+ createStage(apiId, deploymentId);
+
+ given()
+ .when().get("/execute-api/" + apiId + "/test/orders/42")
+ .then()
+ .statusCode(200)
+ .body("from", org.hamcrest.Matchers.equalTo("backend"));
+
+ assertEquals("/42", lastPath.get());
+ }
+
@Test
void forwardsRequestBodyOnPost() {
resetRecordings();