mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat: support GSI and LSI in CloudFormation DynamoDB table provisioning (#125)
This commit is contained in:
3 files changed
+192
-1
No files matched your search
+87
@@ -1,15 +1,29 @@
|
||||
package io.github.hectorvent.floci.services.cloudformation;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.config.EncoderConfig;
|
||||
import io.restassured.http.ContentType;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
@QuarkusTest
|
||||
class CloudFormationIntegrationTest {
|
||||
|
||||
private static final String DYNAMODB_CONTENT_TYPE = "application/x-amz-json-1.0";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssured.config = RestAssured.config().encoderConfig(
|
||||
EncoderConfig.encoderConfig()
|
||||
.encodeContentTypeAs(DYNAMODB_CONTENT_TYPE, ContentType.TEXT));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_withS3AndSqs() {
|
||||
String template = """
|
||||
@@ -75,6 +89,79 @@ class CloudFormationIntegrationTest {
|
||||
.body(containsString("<StackStatus>CREATE_COMPLETE</StackStatus>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStack_withDynamoDbGsiAndLsi() {
|
||||
String template = """
|
||||
{
|
||||
"Resources": {
|
||||
"MyTable": {
|
||||
"Type": "AWS::DynamoDB::Table",
|
||||
"Properties": {
|
||||
"TableName": "cf-index-table",
|
||||
"AttributeDefinitions": [
|
||||
{"AttributeName": "pk", "AttributeType": "S"},
|
||||
{"AttributeName": "sk", "AttributeType": "S"},
|
||||
{"AttributeName": "gsiPk", "AttributeType": "S"}
|
||||
],
|
||||
"KeySchema": [
|
||||
{"AttributeName": "pk", "KeyType": "HASH"},
|
||||
{"AttributeName": "sk", "KeyType": "RANGE"}
|
||||
],
|
||||
"GlobalSecondaryIndexes": [
|
||||
{
|
||||
"IndexName": "gsi-1",
|
||||
"KeySchema": [
|
||||
{"AttributeName": "gsiPk", "KeyType": "HASH"},
|
||||
{"AttributeName": "sk", "KeyType": "RANGE"}
|
||||
],
|
||||
"Projection": {"ProjectionType": "ALL"}
|
||||
}
|
||||
],
|
||||
"LocalSecondaryIndexes": [
|
||||
{
|
||||
"IndexName": "lsi-1",
|
||||
"KeySchema": [
|
||||
{"AttributeName": "pk", "KeyType": "HASH"},
|
||||
{"AttributeName": "gsiPk", "KeyType": "RANGE"}
|
||||
],
|
||||
"Projection": {"ProjectionType": "KEYS_ONLY"}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
// 1. Create Stack
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateStack")
|
||||
.formParam("StackName", "test-dynamo-index-stack")
|
||||
.formParam("TemplateBody", template)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackId>"));
|
||||
|
||||
// 2. Verify GSI and LSI via DescribeTable
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "cf-index-table"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Table.GlobalSecondaryIndexes.size()", equalTo(1))
|
||||
.body("Table.GlobalSecondaryIndexes[0].IndexName", equalTo("gsi-1"))
|
||||
.body("Table.LocalSecondaryIndexes.size()", equalTo(1))
|
||||
.body("Table.LocalSecondaryIndexes[0].IndexName", equalTo("lsi-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteChangeSet_removesChangeSet() {
|
||||
String template = """
|
||||
|
||||
+60
@@ -78,6 +78,66 @@ class DynamoDbIntegrationTest {
|
||||
.body("__type", equalTo("ResourceInUseException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createTableWithGsiAndLsi() {
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "IndexTable",
|
||||
"KeySchema": [
|
||||
{"AttributeName": "pk", "KeyType": "HASH"},
|
||||
{"AttributeName": "sk", "KeyType": "RANGE"}
|
||||
],
|
||||
"AttributeDefinitions": [
|
||||
{"AttributeName": "pk", "AttributeType": "S"},
|
||||
{"AttributeName": "sk", "AttributeType": "S"},
|
||||
{"AttributeName": "gsiPk", "AttributeType": "S"}
|
||||
],
|
||||
"GlobalSecondaryIndexes": [
|
||||
{
|
||||
"IndexName": "gsi-1",
|
||||
"KeySchema": [
|
||||
{"AttributeName": "gsiPk", "KeyType": "HASH"},
|
||||
{"AttributeName": "sk", "KeyType": "RANGE"}
|
||||
],
|
||||
"Projection": {"ProjectionType": "ALL"}
|
||||
}
|
||||
],
|
||||
"LocalSecondaryIndexes": [
|
||||
{
|
||||
"IndexName": "lsi-1",
|
||||
"KeySchema": [
|
||||
{"AttributeName": "pk", "KeyType": "HASH"},
|
||||
{"AttributeName": "gsiPk", "KeyType": "RANGE"}
|
||||
],
|
||||
"Projection": {"ProjectionType": "KEYS_ONLY"}
|
||||
}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TableDescription.GlobalSecondaryIndexes.size()", equalTo(1))
|
||||
.body("TableDescription.GlobalSecondaryIndexes[0].IndexName", equalTo("gsi-1"))
|
||||
.body("TableDescription.LocalSecondaryIndexes.size()", equalTo(1))
|
||||
.body("TableDescription.LocalSecondaryIndexes[0].IndexName", equalTo("lsi-1"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DeleteTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "IndexTable"}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void describeTable() {
|
||||
|
||||
Reference in new issue
Block a user