Skip to content

armgit / floci

Public Imported from GitHub
0

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

test: fold the CloudFormation and IoT one-off profiles into shared ones (#5791)

Priamo Germosene494e1aecf53
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayV2DomainCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayV2DomainCfnIntegrationTest.java
index 7640f99866..0cb82cd035 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayV2DomainCfnIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayV2DomainCfnIntegrationTest.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.net.httpserver.HttpServer;
import io.github.hectorvent.floci.core.common.XmlParser;
+import io.github.hectorvent.floci.testing.CloudFormationSettingsProfile;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
@@ -48,7 +49,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* domain under a key with several levels, which CDK maps with {@code AWS::ApiGatewayV2::ApiMapping}.
*/
@QuarkusTest
-@TestProfile(CloudFormationUnsupportedResourceTypeStrictIntegrationTest.StrictProfile.class)
+@TestProfile(CloudFormationSettingsProfile.class)
class ApiGatewayV2DomainCfnIntegrationTest {
private static final String CFN_AUTH =
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDeletedStackListingRaceTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDeletedStackListingRaceTest.java
index 13a21e5a03..9f2c80f769 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDeletedStackListingRaceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationDeletedStackListingRaceTest.java
@@ -2,9 +2,9 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.services.cloudformation.model.Stack;
+import io.github.hectorvent.floci.testing.CloudFormationSettingsProfile;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
@@ -12,7 +12,6 @@ import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
@@ -26,24 +25,17 @@ import static org.junit.jupiter.api.Assertions.fail;
* A stack being deleted moves from the live map to the retained-deleted one. Handing it over in
* the wrong order leaves a window in which it is in neither, and a ListStacks landing there loses
* a stack that both exists and is retained.
+ *
+ * <p>{@link CloudFormationSettingsProfile} keeps a deleted stack for a day, long enough that
+ * retention cannot end this test. The shipped 30 seconds are measured on the test
+ * {@code MutableClock}, which advances a millisecond on every read, and the pollers below read it
+ * thousands of times: left at the default they expire the retained record themselves and lose the
+ * stack for a reason that has nothing to do with the handoff.
*/
@QuarkusTest
-@TestProfile(CloudFormationDeletedStackListingRaceTest.LongRetentionProfile.class)
+@TestProfile(CloudFormationSettingsProfile.class)
class CloudFormationDeletedStackListingRaceTest {
- /**
- * Retention long enough that it cannot end this test. The shipped 30 seconds are measured on
- * the test {@code MutableClock}, which advances a millisecond on every read, and the pollers
- * below read it thousands of times: left at the default they expire the retained record
- * themselves and lose the stack for a reason that has nothing to do with the handoff.
- */
- public static final class LongRetentionProfile implements QuarkusTestProfile {
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.services.cloudformation.deleted-stack-retention-seconds", "86400");
- }
- }
-
private static final String REGION = "us-east-1";
private static final String ACCOUNT = "000000000000";
/**
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaStubCodeAllowedIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaStubCodeAllowedIntegrationTest.java
index 107f823673..3e33a5ef78 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaStubCodeAllowedIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationLambdaStubCodeAllowedIntegrationTest.java
@@ -1,12 +1,10 @@
package io.github.hectorvent.floci.services.cloudformation;
+import io.github.hectorvent.floci.testing.CloudFormationSettingsProfile;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.Test;
-import java.util.Map;
-
import static io.github.hectorvent.floci.services.cloudformation.CloudFormationLambdaMissingS3CodeIntegrationTest.CFN_AUTH;
import static io.github.hectorvent.floci.services.cloudformation.CloudFormationLambdaMissingS3CodeIntegrationTest.createStack;
import static io.github.hectorvent.floci.services.cloudformation.CloudFormationLambdaMissingS3CodeIntegrationTest.template;
@@ -22,18 +20,14 @@ import static org.hamcrest.Matchers.containsString;
* <p>A separate top-level class rather than a nested one, because {@code @TestProfile} applies per
* test class and Surefire discovers test classes by file name: a nested class carrying the profile
* compiles and passes when targeted directly, but is silently skipped in a full {@code mvn test}.
+ *
+ * <p>The setting comes from {@link CloudFormationSettingsProfile}, which this class shares with the
+ * other CloudFormation classes that change a default.
*/
@QuarkusTest
-@TestProfile(CloudFormationLambdaStubCodeAllowedIntegrationTest.AllowStubProfile.class)
+@TestProfile(CloudFormationSettingsProfile.class)
class CloudFormationLambdaStubCodeAllowedIntegrationTest {
- public static final class AllowStubProfile implements QuarkusTestProfile {
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.services.cloudformation.allow-stub-lambda-code", "true");
- }
- }
-
@Test
void unreadableS3CodeFallsBackToTheStubHandler() {
String suffix = Long.toString(System.nanoTime(), 36);
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUnsupportedResourceTypeStrictIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUnsupportedResourceTypeStrictIntegrationTest.java
index 68fe3da637..c931440c90 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUnsupportedResourceTypeStrictIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationUnsupportedResourceTypeStrictIntegrationTest.java
@@ -1,12 +1,10 @@
package io.github.hectorvent.floci.services.cloudformation;
+import io.github.hectorvent.floci.testing.CloudFormationSettingsProfile;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.Test;
-import java.util.Map;
-
import static io.github.hectorvent.floci.services.cloudformation.CloudFormationLambdaMissingS3CodeIntegrationTest.CFN_AUTH;
import static io.github.hectorvent.floci.services.cloudformation.CloudFormationLambdaMissingS3CodeIntegrationTest.createStack;
import static io.restassured.RestAssured.given;
@@ -21,18 +19,14 @@ import static org.hamcrest.Matchers.containsString;
* <p>A separate top-level class rather than a nested one, because {@code @TestProfile} applies per
* test class and Surefire discovers test classes by file name: a nested class carrying the profile
* compiles and passes when targeted directly, but is silently skipped in a full {@code mvn test}.
+ *
+ * <p>The setting comes from {@link CloudFormationSettingsProfile}, which this class shares with the
+ * other CloudFormation classes that change a default.
*/
@QuarkusTest
-@TestProfile(CloudFormationUnsupportedResourceTypeStrictIntegrationTest.StrictProfile.class)
+@TestProfile(CloudFormationSettingsProfile.class)
class CloudFormationUnsupportedResourceTypeStrictIntegrationTest {
- public static final class StrictProfile implements QuarkusTestProfile {
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.services.cloudformation.allow-stub-unsupported-resource-types", "false");
- }
- }
-
@Test
void strictProfileRollsTheStackBack() {
String stackName = "cfn-unsupported-strict-" + Long.toString(System.nanoTime(), 36);
diff --git a/src/test/java/io/github/hectorvent/floci/services/iot/IotDescribeEndpointOverrideIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iot/IotDescribeEndpointOverrideIntegrationTest.java
index 8a6ccf1333..9ca4e86b19 100644
--- a/src/test/java/io/github/hectorvent/floci/services/iot/IotDescribeEndpointOverrideIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/iot/IotDescribeEndpointOverrideIntegrationTest.java
@@ -1,14 +1,13 @@
package io.github.hectorvent.floci.services.iot;
+import io.github.hectorvent.floci.testing.IotSettingsProfile;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import java.util.Map;
-
+import static io.github.hectorvent.floci.testing.IotSettingsProfile.ENDPOINT_ADDRESS;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
@@ -17,13 +16,14 @@ import static org.hamcrest.Matchers.equalTo;
* for every endpoint type, the way AWS returns a bare hostname that devices complete with their
* own port. {@link IotIntegrationTest} and {@link IotEndpointHostnameIntegrationTest} keep
* guarding the unset case, the host and port of the base URL.
+ *
+ * <p>The address comes from {@link IotSettingsProfile}, which this class shares with the other IoT
+ * class that changes a default.
*/
@QuarkusTest
-@TestProfile(IotDescribeEndpointOverrideIntegrationTest.Profile.class)
+@TestProfile(IotSettingsProfile.class)
class IotDescribeEndpointOverrideIntegrationTest {
- static final String ENDPOINT_ADDRESS = "iot.example.localhost.floci.io";
-
@Test
void omittedEndpointTypeReturnsTheConfiguredAddress() {
given()
@@ -68,11 +68,4 @@ class IotDescribeEndpointOverrideIntegrationTest {
.body("domainType", equalTo("AWS_MANAGED"))
.body("domainName", equalTo(ENDPOINT_ADDRESS));
}
-
- public static final class Profile implements QuarkusTestProfile {
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.services.iot.endpoint-address", ENDPOINT_ADDRESS);
- }
- }
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/iot/IotTopicRuleSqlStrictIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iot/IotTopicRuleSqlStrictIntegrationTest.java
index a1bd8f2607..08a5dbd218 100644
--- a/src/test/java/io/github/hectorvent/floci/services/iot/IotTopicRuleSqlStrictIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/iot/IotTopicRuleSqlStrictIntegrationTest.java
@@ -1,18 +1,24 @@
package io.github.hectorvent.floci.services.iot;
+import io.github.hectorvent.floci.testing.IotSettingsProfile;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.Test;
-import java.util.Map;
-
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
+/**
+ * With {@code floci.services.iot.rule-sql-strict} on, a topic rule whose SQL is outside the subset
+ * Floci evaluates is rejected with {@code SqlParseException}, while one inside it is still accepted.
+ * Off, the default, such a rule is stored and fires on every matching topic with the whole payload.
+ *
+ * <p>The setting comes from {@link IotSettingsProfile}, which this class shares with the other IoT
+ * class that changes a default.
+ */
@QuarkusTest
-@TestProfile(IotTopicRuleSqlStrictIntegrationTest.StrictRuleSqlProfile.class)
+@TestProfile(IotSettingsProfile.class)
class IotTopicRuleSqlStrictIntegrationTest {
@Test
@@ -56,11 +62,4 @@ class IotTopicRuleSqlStrictIntegrationTest {
}
""".formatted(sql);
}
-
- public static final class StrictRuleSqlProfile implements QuarkusTestProfile {
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.services.iot.rule-sql-strict", "true");
- }
- }
}
diff --git a/src/test/java/io/github/hectorvent/floci/testing/CloudFormationSettingsProfile.java b/src/test/java/io/github/hectorvent/floci/testing/CloudFormationSettingsProfile.java
new file mode 100644
index 0000000000..afc473e316
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/testing/CloudFormationSettingsProfile.java
@@ -0,0 +1,42 @@
+package io.github.hectorvent.floci.testing;
+
+import io.quarkus.test.junit.QuarkusTestProfile;
+
+import java.util.Map;
+
+/**
+ * The CloudFormation settings that differ from the test defaults, for the classes that test them.
+ * Quarkus builds the application once per distinct profile class, so they share this one rather
+ * than each declaring their own.
+ *
+ * <p>The overrides, and who relies on them:
+ * <ul>
+ * <li>{@code floci.services.cloudformation.allow-stub-unsupported-resource-types=false} fails a
+ * resource type Floci has no provisioner for instead of stubbing it.
+ * {@code CloudFormationUnsupportedResourceTypeStrictIntegrationTest} relies on it.
+ * {@code ApiGatewayV2DomainCfnIntegrationTest} runs under it too, so that a type nothing
+ * provisions would fail its stacks instead of passing as a stub; it passes without it.</li>
+ * <li>{@code floci.services.cloudformation.allow-stub-lambda-code=true} gives a Lambda function
+ * whose code in S3 cannot be read the built-in stub handler instead of failing it.
+ * {@code CloudFormationLambdaStubCodeAllowedIntegrationTest} relies on it.</li>
+ * <li>{@code floci.services.cloudformation.deleted-stack-retention-seconds=86400} keeps a deleted
+ * stack in ListStacks, and answering DescribeStacks by its stack id, for a day instead of 30
+ * seconds. {@code CloudFormationDeletedStackListingRaceTest} relies on it.</li>
+ * </ul>
+ *
+ * <p>Each override is inert for the other classes. Every type their templates declare has a
+ * provisioner, so the strict gate never fires for them. Only the stub test declares a Lambda
+ * function. Retention only changes what ListStacks and DescribeStacks by stack id return after a
+ * delete, and the other classes look a stack up only by name, which stops answering as soon as the
+ * stack is deleted.
+ */
+public class CloudFormationSettingsProfile implements QuarkusTestProfile {
+
+ @Override
+ public Map<String, String> getConfigOverrides() {
+ return Map.of(
+ "floci.services.cloudformation.allow-stub-unsupported-resource-types", "false",
+ "floci.services.cloudformation.allow-stub-lambda-code", "true",
+ "floci.services.cloudformation.deleted-stack-retention-seconds", "86400");
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/testing/IotSettingsProfile.java b/src/test/java/io/github/hectorvent/floci/testing/IotSettingsProfile.java
new file mode 100644
index 0000000000..77d36928d2
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/testing/IotSettingsProfile.java
@@ -0,0 +1,35 @@
+package io.github.hectorvent.floci.testing;
+
+import io.quarkus.test.junit.QuarkusTestProfile;
+
+import java.util.Map;
+
+/**
+ * The IoT Core settings that differ from the test defaults, for the classes that test them.
+ * Quarkus builds the application once per distinct profile class, so they share this one rather
+ * than each declaring their own.
+ *
+ * <p>The overrides, and who relies on them:
+ * <ul>
+ * <li>{@code floci.services.iot.endpoint-address=}{@value #ENDPOINT_ADDRESS} is what
+ * DescribeEndpoint returns for every endpoint type, and the domain name of the AWS-managed domain
+ * configurations. {@code IotDescribeEndpointOverrideIntegrationTest} relies on it.</li>
+ * <li>{@code floci.services.iot.rule-sql-strict=true} rejects a topic rule whose SQL is outside
+ * the subset Floci evaluates. {@code IotTopicRuleSqlStrictIntegrationTest} relies on it.</li>
+ * </ul>
+ *
+ * <p>Each override is inert for the other class. The address only changes what DescribeEndpoint
+ * and the AWS-managed domain configurations report, which the rule test never reads, and strict
+ * SQL only changes how a topic rule is created, which the endpoint test never does.
+ */
+public class IotSettingsProfile implements QuarkusTestProfile {
+
+ public static final String ENDPOINT_ADDRESS = "iot.example.localhost.floci.io";
+
+ @Override
+ public Map<String, String> getConfigOverrides() {
+ return Map.of(
+ "floci.services.iot.endpoint-address", ENDPOINT_ADDRESS,
+ "floci.services.iot.rule-sql-strict", "true");
+ }
+}