mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
test: fold the CloudFormation and IoT one-off profiles into shared ones (#5791)
Slice 8 of #4542. Three CloudFormation classes each declared a profile for one setting, and ApiGatewayV2DomainCfnIntegrationTest borrowed the strict one. All four now use CloudFormationSettingsProfile, which carries the three settings: an unsupported resource type fails instead of being stubbed, Lambda code that cannot be read falls back to the stub handler, and a deleted stack is retained for a day. Each only reaches the class that tests it: the other templates declare only types Floci provisions and no Lambda function, and only the race test lists stacks or looks one up by its id after a delete. The two IoT classes that changed a default, the DescribeEndpoint address and strict rule SQL, share IotSettingsProfile. 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. Why the race test keeps a deleted stack for a day, the test clock advancing on every read, moves from the retired profile's javadoc to the class javadoc. IotTopicRuleSqlStrictIntegrationTest gains a class javadoc saying what strict mode changes.
This commit is contained in:
1 parent
7e98592761
commit
e494e1aecf
8 files changed
+113
-63
No files matched your search
+2
-1
@@ -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 =
|
||||
|
||||
+8
-16
@@ -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";
|
||||
/**
|
||||
|
||||
+5
-11
@@ -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);
|
||||
|
||||
+5
-11
@@ -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);
|
||||
|
||||
+6
-13
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-11
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user