mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
test(cloudformation): reuse physical ID helper in custom resource tests (#7649)
This commit is contained in:
1 parent
b1ba11c61e
commit
626af42d45
2 files changed
+8
-18
No files matched your search
+6
-11
@@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.CfnRequests.physicalIdUnauthenticated;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@@ -57,7 +58,7 @@ class CloudFormationCustomResourceRollbackIntegrationTest {
|
||||
String stackName = "cr-rollback-" + Long.toString(System.nanoTime(), 36);
|
||||
String stackId = createStack(stackName, template("1", false));
|
||||
awaitStackStatus(stackId, "CREATE_COMPLETE");
|
||||
String physicalId = probePhysicalId(stackName);
|
||||
String physicalId = physicalIdUnauthenticated(stackName, "Probe");
|
||||
|
||||
updateStack(stackName, template("2", true));
|
||||
awaitStackStatus(stackId, "UPDATE_ROLLBACK_COMPLETE");
|
||||
@@ -67,7 +68,7 @@ class CloudFormationCustomResourceRollbackIntegrationTest {
|
||||
assertProperties(probe.events().get(1), "2", "1");
|
||||
assertProperties(probe.events().get(2), "1", "2");
|
||||
assertEquals(physicalId, probe.events().get(2).get("PhysicalResourceId").asText());
|
||||
assertEquals(physicalId, probePhysicalId(stackName));
|
||||
assertEquals(physicalId, physicalIdUnauthenticated(stackName, "Probe"));
|
||||
assertFalse(describeStackEvents(stackId).contains("Rollback is not implemented"));
|
||||
}
|
||||
|
||||
@@ -98,7 +99,7 @@ class CloudFormationCustomResourceRollbackIntegrationTest {
|
||||
String stackName = "cr-own-update-failed-" + Long.toString(System.nanoTime(), 36);
|
||||
String stackId = createStack(stackName, template("1", false));
|
||||
awaitStackStatus(stackId, "CREATE_COMPLETE");
|
||||
String physicalId = probePhysicalId(stackName);
|
||||
String physicalId = physicalIdUnauthenticated(stackName, "Probe");
|
||||
|
||||
updateStack(stackName, template("3", false));
|
||||
awaitStackStatus(stackId, "UPDATE_ROLLBACK_COMPLETE");
|
||||
@@ -108,7 +109,7 @@ class CloudFormationCustomResourceRollbackIntegrationTest {
|
||||
assertProperties(probe.events().get(1), "3", "1");
|
||||
assertProperties(probe.events().get(2), "1", "3");
|
||||
assertEquals(physicalId, probe.events().get(2).get("PhysicalResourceId").asText());
|
||||
assertEquals(physicalId, probePhysicalId(stackName));
|
||||
assertEquals(physicalId, physicalIdUnauthenticated(stackName, "Probe"));
|
||||
List<String> probeStatuses = XmlParser.extractGroups(describeStackEvents(stackId), "member")
|
||||
.reversed()
|
||||
.stream()
|
||||
@@ -125,7 +126,7 @@ class CloudFormationCustomResourceRollbackIntegrationTest {
|
||||
String stackName = "cr-delete-after-failed-" + Long.toString(System.nanoTime(), 36);
|
||||
String stackId = createStack(stackName, template("1", false));
|
||||
awaitStackStatus(stackId, "CREATE_COMPLETE");
|
||||
String physicalId = probePhysicalId(stackName);
|
||||
String physicalId = physicalIdUnauthenticated(stackName, "Probe");
|
||||
updateStack(stackName, template("2", true));
|
||||
awaitStackStatus(stackId, "UPDATE_ROLLBACK_FAILED");
|
||||
|
||||
@@ -209,12 +210,6 @@ class CloudFormationCustomResourceRollbackIntegrationTest {
|
||||
cfn(Map.of("Action", "DeleteStack", "StackName", stackName));
|
||||
}
|
||||
|
||||
private static String probePhysicalId(String stackName) {
|
||||
String xml = cfn(Map.of("Action", "DescribeStackResource", "StackName", stackName,
|
||||
"LogicalResourceId", "Probe"));
|
||||
return XmlParser.extractFirst(xml, "PhysicalResourceId", null);
|
||||
}
|
||||
|
||||
private static String describeStackEvents(String stackId) {
|
||||
return cfn(Map.of("Action", "DescribeStackEvents", "StackName", stackId));
|
||||
}
|
||||
|
||||
+2
-7
@@ -12,6 +12,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.CfnRequests.physicalIdUnauthenticated;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@@ -57,7 +58,7 @@ class CloudFormationCustomResourceUsesIntegrationTest {
|
||||
|
||||
Map<String, String> kept = attributes(stack);
|
||||
assertEquals(stack + "-data", kept.get(USES + "Data"), kept::toString);
|
||||
assertEquals(queueUrl(stack), kept.get(USES + "Queue"), kept::toString);
|
||||
assertEquals(physicalIdUnauthenticated(stack, "Queue"), kept.get(USES + "Queue"), kept::toString);
|
||||
assertFalse(kept.containsValue(stack + ".example.com"), kept::toString);
|
||||
|
||||
updateStack(stack, template(stack, "Archive", ""));
|
||||
@@ -168,12 +169,6 @@ class CloudFormationCustomResourceUsesIntegrationTest {
|
||||
.getResources().get("Emptier").getAttributes();
|
||||
}
|
||||
|
||||
private static String queueUrl(String stack) {
|
||||
String xml = cfn(Map.of("Action", "DescribeStackResource", "StackName", stack,
|
||||
"LogicalResourceId", "Queue"));
|
||||
return XmlParser.extractFirst(xml, "PhysicalResourceId", null);
|
||||
}
|
||||
|
||||
private static String createStack(String stackName, String template) {
|
||||
String xml = cfn(Map.of("Action", "CreateStack", "StackName", stackName, "TemplateBody", template));
|
||||
return XmlParser.extractFirst(xml, "StackId", null);
|
||||
|
||||
Reference in new issue
Block a user