Skip to content

armgit / floci

Public Imported from GitHub
0

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

feat(athena): support DeleteWorkGroup action (#1213)

MAN$I VERMAe35d30bc42ec
diff --git a/src/main/java/io/github/hectorvent/floci/services/athena/AthenaJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/athena/AthenaJsonHandler.java
index 29cd4ba688..e7d976576b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/athena/AthenaJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/athena/AthenaJsonHandler.java
@@ -94,6 +94,16 @@ public class AthenaJsonHandler {
String tableName = request.get("TableName").asText();
yield Response.ok(Map.of("TableMetadata", athenaService.getTableMetadata(catalog, database, tableName))).build();
}
+ case "DeleteWorkGroup" -> {
+ String wg = request.path("WorkGroup").asText(null);
+ if (wg == null || !wg.matches("[a-zA-Z0-9._-]{1,128}")) {
+ throw new AwsException("InvalidRequestException", "WorkGroup is required.", 400);
+ }
+ if ("primary".equals(wg)) {
+ throw new AwsException("InvalidRequestException", "The primary workgroup cannot be deleted.", 400);
+ }
+ yield Response.ok(Map.of()).build();
+ }
default -> throw new AwsException("InvalidAction", "Action " + action + " is not supported", 400);
};
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java
index 2e2da2bf22..15cb569690 100644
--- a/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java
@@ -192,4 +192,81 @@ class AthenaIntegrationTest {
.body("TableMetadata.Columns[0].Type", equalTo("varchar"))
.body("TableMetadata.Columns[1].Type", equalTo("varchar"));
}
+
+ @Test
+ @Order(8)
+ void deleteWorkGroup() {
+ given()
+ .header("X-Amz-Target", "AmazonAthena.DeleteWorkGroup")
+ .contentType(CONTENT_TYPE)
+ .body("{ \"WorkGroup\": \"athena-workgroup-sample\" }")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body(equalTo("{}"));
+ }
+
+ @Test
+ @Order(9)
+ void deleteWorkGroupMissingOrBlank() {
+ given()
+ .header("X-Amz-Target", "AmazonAthena.DeleteWorkGroup")
+ .contentType(CONTENT_TYPE)
+ .body("{}")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidRequestException"))
+ .body("message", equalTo("WorkGroup is required."));
+
+ given()
+ .header("X-Amz-Target", "AmazonAthena.DeleteWorkGroup")
+ .contentType(CONTENT_TYPE)
+ .body("{ \"WorkGroup\": \" \" }")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidRequestException"))
+ .body("message", equalTo("WorkGroup is required."));
+
+ given()
+ .header("X-Amz-Target", "AmazonAthena.DeleteWorkGroup")
+ .contentType(CONTENT_TYPE)
+ .body("{ \"WorkGroup\": \"bad name\" }")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidRequestException"))
+ .body("message", equalTo("WorkGroup is required."));
+
+ given()
+ .header("X-Amz-Target", "AmazonAthena.DeleteWorkGroup")
+ .contentType(CONTENT_TYPE)
+ .body("{ \"WorkGroup\": \"" + "a".repeat(129) + "\" }")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidRequestException"))
+ .body("message", equalTo("WorkGroup is required."));
+ }
+
+ @Test
+ @Order(10)
+ void deletePrimaryWorkGroup() {
+ given()
+ .header("X-Amz-Target", "AmazonAthena.DeleteWorkGroup")
+ .contentType(CONTENT_TYPE)
+ .body("{ \"WorkGroup\": \"primary\" }")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidRequestException"))
+ .body("message", equalTo("The primary workgroup cannot be deleted."));
+ }
}