Light, fluffy, and always free - The AWS Local Emulator alternative
test: share one profile between the Timestream and EKS IMDS Docker tests (#5829)
Priamo Germosen6f8316b7d11e
diff --git a/src/test/java/io/github/hectorvent/floci/services/eks/EksImdsDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/eks/EksImdsDockerIntegrationTest.javaindex b41d66694c..a3581ac55d 100644--- a/src/test/java/io/github/hectorvent/floci/services/eks/EksImdsDockerIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/eks/EksImdsDockerIntegrationTest.java@@ -9,8 +9,8 @@ import io.github.hectorvent.floci.core.common.docker.ContainerSpec;import io.github.hectorvent.floci.core.common.docker.DockerHostResolver;import io.github.hectorvent.floci.services.ec2.Ec2MetadataServer;import io.github.hectorvent.floci.services.eks.model.Cluster;+import io.github.hectorvent.floci.testing.ContainerDataPlaneProfile;import io.quarkus.test.junit.QuarkusTest;-import io.quarkus.test.junit.QuarkusTestProfile;import io.quarkus.test.junit.TestProfile;import jakarta.inject.Inject;import org.jboss.logging.Logger;@@ -20,7 +20,6 @@ import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;import java.util.List;-import java.util.Map;import java.util.UUID;import static org.junit.jupiter.api.Assertions.assertEquals;@@ -28,19 +27,16 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;import static org.junit.jupiter.api.Assertions.assertNotNull;import static org.junit.jupiter.api.Assertions.assertTrue;+/**+ * Configures the link-local IMDS endpoint on a stand-in cluster container and queries it from the+ * node and from a pod network namespace. The settings come from+ * {@link ContainerDataPlaneProfile}, which this class shares with+ * {@code TimestreamInfluxDbDockerIntegrationTest}.+ */@QuarkusTest-@TestProfile(EksImdsDockerIntegrationTest.Profile.class)+@TestProfile(ContainerDataPlaneProfile.class)class EksImdsDockerIntegrationTest {- public static final class Profile implements QuarkusTestProfile {- @Override- public Map<String, String> getConfigOverrides() {- return Map.of(- "floci.services.eks.imds", "true",- "floci.services.eks.imds-pod-network", "true");- }- }-private static final Logger LOG = Logger.getLogger(EksImdsDockerIntegrationTest.class);private static final String TEST_IMAGE = "alpine:3.21";diff --git a/src/test/java/io/github/hectorvent/floci/services/timestreaminfluxdb/TimestreamInfluxDbDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/timestreaminfluxdb/TimestreamInfluxDbDockerIntegrationTest.javaindex b34eed7890..fdba301192 100644--- a/src/test/java/io/github/hectorvent/floci/services/timestreaminfluxdb/TimestreamInfluxDbDockerIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/timestreaminfluxdb/TimestreamInfluxDbDockerIntegrationTest.java@@ -1,9 +1,9 @@package io.github.hectorvent.floci.services.timestreaminfluxdb;import com.github.dockerjava.api.DockerClient;+import io.github.hectorvent.floci.testing.ContainerDataPlaneProfile;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 io.restassured.response.ValidatableResponse;import jakarta.inject.Inject;@@ -28,9 +28,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;import static org.junit.jupiter.api.Assertions.assertTrue;import static org.junit.jupiter.api.Assertions.fail;+/**+ * Runs Timestream for InfluxDB on real InfluxDB containers, published on host ports 18186 to 18285.+ * The settings come from {@link ContainerDataPlaneProfile}, which this class shares with+ * {@code EksImdsDockerIntegrationTest}.+ */@Tag("docker")@QuarkusTest-@TestProfile(TimestreamInfluxDbDockerIntegrationTest.RealContainerProfile.class)+@TestProfile(ContainerDataPlaneProfile.class)// Three 180 s status waits on real containers, plus the requests and cleanup around them.@Timeout(value = 15, unit = TimeUnit.MINUTES)class TimestreamInfluxDbDockerIntegrationTest {@@ -40,16 +45,6 @@ class TimestreamInfluxDbDockerIntegrationTest {private static final String USERNAME = "operator";private static final String PASSWORD = "password123";- public static class RealContainerProfile implements QuarkusTestProfile {- @Override- public Map<String, String> getConfigOverrides() {- return Map.of(- "floci.services.timestream-influxdb.mock", "false",- "floci.services.timestream-influxdb.host-port-base", "18186",- "floci.services.timestream-influxdb.host-port-max", "18285");- }- }-@InjectDockerClient dockerClient;diff --git a/src/test/java/io/github/hectorvent/floci/testing/ContainerDataPlaneProfile.java b/src/test/java/io/github/hectorvent/floci/testing/ContainerDataPlaneProfile.javanew file mode 100644index 0000000000..f0cea61cc6--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/testing/ContainerDataPlaneProfile.java@@ -0,0 +1,44 @@+package io.github.hectorvent.floci.testing;++import io.quarkus.test.junit.QuarkusTestProfile;++import java.util.Map;++/**+ * Runs the container-backed data planes the test defaults mock or leave off, 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.timestream-influxdb.mock=false} backs each DB instance with an+ * InfluxDB container, published on a host port from {@code host-port-base} to+ * {@code host-port-max}, set here to 18186 and 18285. {@code TimestreamInfluxDbDockerIntegrationTest}+ * relies on it.</li>+ * <li>{@code floci.services.eks.imds=true} and {@code floci.services.eks.imds-pod-network=true}+ * program the link-local IMDS endpoint into a cluster's container, for the node and for its pods.+ * {@code EksImdsDockerIntegrationTest} relies on them.</li>+ * </ul>+ *+ * <p>Each override is inert for the other class. An InfluxDB container only starts when a DB+ * instance is created, which the IMDS test never does. The IMDS settings only act when a cluster's+ * container starts, and the test defaults keep EKS mocked, so only {@code EksImdsDockerIntegrationTest},+ * which configures the endpoint on its own container, reaches them. The metadata server it starts+ * stays up for the Timestream test, on a port that test does not use.+ *+ * <p>The ELBv2 data-plane classes stay on {@link RealElbV2DataPlaneProfile}: one of them,+ * {@code ElbV2WebSocketIntegrationTest}, injects a spy, and a class that does is not merged into+ * another group.+ */+public class ContainerDataPlaneProfile implements QuarkusTestProfile {++ @Override+ public Map<String, String> getConfigOverrides() {+ return Map.of(+ "floci.services.timestream-influxdb.mock", "false",+ "floci.services.timestream-influxdb.host-port-base", "18186",+ "floci.services.timestream-influxdb.host-port-max", "18285",+ "floci.services.eks.imds", "true",+ "floci.services.eks.imds-pod-network", "true");+ }+}