Skip to content

armgit / floci

Public Imported from GitHub
0

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

test: share one sidecar profile across the AppSync, CodeArtifact and Cedar integration tests (#4665)

Priamo Germosen1b87ed44c09e
diff --git a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncAuthIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncAuthIntegrationTest.java
index 17a9c3a6cb..d6c0bc557f 100644
--- a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncAuthIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncAuthIntegrationTest.java
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.appsync;
import io.github.hectorvent.floci.core.common.ResolvedServiceCatalog;
import io.github.hectorvent.floci.services.appsync.graphql.AppSyncExecutionController;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.github.hectorvent.floci.testutil.AppSyncRequestSigner;
import io.restassured.RestAssured;
import io.quarkus.test.junit.QuarkusTest;
@@ -26,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/** Runs against the real GraphQL sidecar image, started by {@link GraphqlSidecarManager}. */
@QuarkusTest
-@TestProfile(AppSyncGraphqlSidecarProfile.class)
+@TestProfile(SidecarContainersProfile.class)
class AppSyncAuthIntegrationTest {
private static final String MGMT_AUTH =
@@ -37,7 +38,7 @@ class AppSyncAuthIntegrationTest {
@BeforeAll
static void configureRestAssured() {
- AppSyncGraphqlSidecarProfile.requireDockerAndTheSidecarImage();
+ SidecarContainersProfile.requireDockerAndImage("floci.services.appsync.graphql-image");
RestAssuredJsonUtils.configureAwsContentTypes();
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncExecutionIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncExecutionIntegrationTest.java
index 0d55b9a700..edec867183 100644
--- a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncExecutionIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncExecutionIntegrationTest.java
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.appsync;
import io.github.hectorvent.floci.services.appsync.graphql.AppSyncErrorFormatter;
import io.github.hectorvent.floci.services.appsync.graphql.SchemaRegistry;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
@@ -23,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/** Runs against the real GraphQL sidecar image, started by {@link GraphqlSidecarManager}. */
@QuarkusTest
-@TestProfile(AppSyncGraphqlSidecarProfile.class)
+@TestProfile(SidecarContainersProfile.class)
class AppSyncExecutionIntegrationTest {
private static final String AUTH = "AWS4-HMAC-SHA256 Credential=test/20260205/us-east-1/appsync/aws4_request";
@@ -36,7 +37,7 @@ class AppSyncExecutionIntegrationTest {
@BeforeAll
static void configureRestAssured() {
- AppSyncGraphqlSidecarProfile.requireDockerAndTheSidecarImage();
+ SidecarContainersProfile.requireDockerAndImage("floci.services.appsync.graphql-image");
RestAssuredJsonUtils.configureAwsContentTypes();
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncGraphqlSidecarProfile.java b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncGraphqlSidecarProfile.java
deleted file mode 100644
index 7038ebf11d..0000000000
--- a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncGraphqlSidecarProfile.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package io.github.hectorvent.floci.services.appsync;
-
-import io.quarkus.test.junit.QuarkusTestProfile;
-import org.eclipse.microprofile.config.ConfigProvider;
-import org.junit.jupiter.api.Assumptions;
-
-import java.util.Map;
-
-/**
- * Shared by every AppSync integration test that needs the real GraphQL sidecar container, started
- * by {@link GraphqlSidecarManager} exactly as in production. Namespaces the container as
- * {@code floci-appsync-test-graphql} so the manager's remove-before-start never touches a
- * developer's real running Floci. Needs Docker; skipped without it. Locally it is also skipped
- * when the pinned image is not present, so a developer without registry access is not stuck; in CI
- * a missing image is a failure, since a vanished tag must not pass silently.
- *
- * <p>Every test class that uses this profile shares one Quarkus test application instance (and
- * one running sidecar container) rather than paying a restart for each, since Quarkus keys its
- * test-application cache by the profile class identity.
- */
-public class AppSyncGraphqlSidecarProfile implements QuarkusTestProfile {
-
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.docker.resource-namespace", "appsync-test");
- }
-
- public static void requireDockerAndTheSidecarImage() {
- Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for AppSync integration tests");
- String image = ConfigProvider.getConfig().getValue("floci.services.appsync.graphql-image", String.class);
- Assumptions.assumeTrue(imageUsable(image), "GraphQL sidecar image " + image + " is not present locally");
- }
-
- private static boolean isDockerAvailable() {
- return run("docker", "version", "--format", "{{.Server.Version}}");
- }
-
- private static boolean imageUsable(String image) {
- if ("true".equals(System.getenv("CI"))) {
- return true;
- }
- return run("docker", "image", "inspect", image);
- }
-
- private static boolean run(String... command) {
- try {
- Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
- return process.waitFor() == 0;
- } catch (Exception e) {
- return false;
- }
- }
-}
diff --git a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncIntegrationTest.java
index a7afd6ee7d..b48187d4b0 100644
--- a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncIntegrationTest.java
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.services.appsync.model.SchemaCreationStatus;
import io.github.hectorvent.floci.services.appsync.model.SchemaCreationStatusType;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.BeforeAll;
@@ -24,7 +25,7 @@ import static org.hamcrest.Matchers.*;
* {@code StartSchemaCreation} validates against it, so it needs to be up.
*/
@QuarkusTest
-@TestProfile(AppSyncGraphqlSidecarProfile.class)
+@TestProfile(SidecarContainersProfile.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class AppSyncIntegrationTest {
@@ -37,7 +38,7 @@ class AppSyncIntegrationTest {
@BeforeAll
static void configureRestAssured() {
- AppSyncGraphqlSidecarProfile.requireDockerAndTheSidecarImage();
+ SidecarContainersProfile.requireDockerAndImage("floci.services.appsync.graphql-image");
RestAssuredJsonUtils.configureAwsContentTypes();
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncJsResolverDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncJsResolverDockerIntegrationTest.java
index e202390190..9a82594573 100644
--- a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncJsResolverDockerIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncJsResolverDockerIntegrationTest.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.appsync;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.BeforeAll;
@@ -31,7 +32,7 @@ import static org.hamcrest.Matchers.nullValue;
* <p>Needs Docker for both sidecars, and skips without it.
*/
@QuarkusTest
-@TestProfile(AppSyncResolverCallbackProfile.class)
+@TestProfile(SidecarContainersProfile.class)
class AppSyncJsResolverDockerIntegrationTest {
private static final String AUTH =
@@ -173,7 +174,7 @@ class AppSyncJsResolverDockerIntegrationTest {
@BeforeAll
static void configure() {
- AppSyncGraphqlSidecarProfile.requireDockerAndTheSidecarImage();
+ SidecarContainersProfile.requireDockerAndImage("floci.services.appsync.graphql-image");
RestAssuredJsonUtils.configureAwsContentTypes();
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncResolverCallbackProfile.java b/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncResolverCallbackProfile.java
deleted file mode 100644
index b50c4bd14e..0000000000
--- a/src/test/java/io/github/hectorvent/floci/services/appsync/AppSyncResolverCallbackProfile.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package io.github.hectorvent.floci.services.appsync;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-/**
- * {@link AppSyncGraphqlSidecarProfile} plus a Floci base URL the sidecar container can actually
- * reach back on.
- *
- * <p>The resolver callback URL is built from {@code floci.base-url}'s port, which in production is
- * the port Floci listens on. Under {@code @QuarkusTest} the application listens on the test port
- * instead, so without this the sidecar would call back to 4566 and every resolver-backed field
- * would fail with a connection error. Both values are pinned together here so they cannot drift.
- */
-public class AppSyncResolverCallbackProfile extends AppSyncGraphqlSidecarProfile {
-
- private static final String TEST_PORT = "8081";
-
- @Override
- public Map<String, String> getConfigOverrides() {
- Map<String, String> overrides = new LinkedHashMap<>(super.getConfigOverrides());
- overrides.put("quarkus.http.test-port", TEST_PORT);
- overrides.put("floci.base-url", "http://localhost:" + TEST_PORT);
- return overrides;
- }
-}
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/AppSyncCfnIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/AppSyncCfnIntegrationTest.java
index 31f8cc7ead..1977d1d3ce 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/AppSyncCfnIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/AppSyncCfnIntegrationTest.java
@@ -1,7 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
-import io.github.hectorvent.floci.services.appsync.AppSyncGraphqlSidecarProfile;
+import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.response.ValidatableResponse;
@@ -37,12 +37,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* never touches a developer's own running sidecar, and skips (rather than fails) without Docker.
*/
@QuarkusTest
-@TestProfile(AppSyncGraphqlSidecarProfile.class)
+@TestProfile(SidecarContainersProfile.class)
class AppSyncCfnIntegrationTest {
@BeforeAll
static void requireDockerAndTheSidecarImage() {
- AppSyncGraphqlSidecarProfile.requireDockerAndTheSidecarImage();
+ SidecarContainersProfile.requireDockerAndImage("floci.services.appsync.graphql-image");
}
private static final String CFN_AUTH =
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java
index 181bf4227a..852a1d65c8 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.codeartifact;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import jakarta.inject.Inject;
@@ -36,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* Docker-gated form.
*/
@QuarkusTest
-@TestProfile(CodeArtifactMavenSidecarProfile.class)
+@TestProfile(SidecarContainersProfile.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class CodeArtifactMavenDockerIntegrationTest {
@@ -49,7 +50,7 @@ class CodeArtifactMavenDockerIntegrationTest {
@BeforeAll
static void setUp() {
- CodeArtifactMavenSidecarProfile.requireDockerAndTheSidecarImage();
+ SidecarContainersProfile.requireDockerAndImage("floci.services.codeartifact.maven-image");
RestAssuredJsonUtils.configureAwsContentTypes();
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenSidecarProfile.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenSidecarProfile.java
deleted file mode 100644
index b2359ada23..0000000000
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenSidecarProfile.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package io.github.hectorvent.floci.services.codeartifact;
-
-import io.quarkus.test.junit.QuarkusTestProfile;
-import org.eclipse.microprofile.config.ConfigProvider;
-import org.junit.jupiter.api.Assumptions;
-
-import java.util.Map;
-
-/**
- * Shared by every CodeArtifact integration test that needs the real Reposilite sidecar container,
- * started by {@link ReposiliteSidecarManager} exactly as in production. Namespaces the container
- * as {@code floci-codeartifact-maven-test-reposilite} so the manager's remove-before-start never
- * touches a developer's real running Floci. Needs Docker; skipped without it. Locally it is also
- * skipped when the pinned image is not present, so a developer without registry access is not
- * stuck; in CI a missing image is a failure, since a vanished tag must not pass silently.
- */
-public class CodeArtifactMavenSidecarProfile implements QuarkusTestProfile {
-
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.docker.resource-namespace", "codeartifact-maven-test");
- }
-
- public static void requireDockerAndTheSidecarImage() {
- Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for CodeArtifact Maven "
- + "sidecar integration tests");
- String image = ConfigProvider.getConfig().getValue("floci.services.codeartifact.maven-image", String.class);
- Assumptions.assumeTrue(imageUsable(image), "Reposilite sidecar image " + image + " is not present locally");
- }
-
- private static boolean isDockerAvailable() {
- return run("docker", "version", "--format", "{{.Server.Version}}");
- }
-
- private static boolean imageUsable(String image) {
- if ("true".equals(System.getenv("CI"))) {
- return true;
- }
- return run("docker", "image", "inspect", image);
- }
-
- private static boolean run(String... command) {
- try {
- Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
- return process.waitFor() == 0;
- } catch (Exception e) {
- return false;
- }
- }
-}
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDockerIntegrationTest.java
index bc6ea2945a..a627511e2d 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDockerIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDockerIntegrationTest.java
@@ -2,9 +2,12 @@ package io.github.hectorvent.floci.services.codeartifact;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
+import jakarta.inject.Inject;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
@@ -43,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* internal, client-unreachable address instead of back through this proxy.
*/
@QuarkusTest
-@TestProfile(CodeArtifactNpmSidecarProfile.class)
+@TestProfile(SidecarContainersProfile.class)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class CodeArtifactNpmDockerIntegrationTest {
@@ -52,13 +55,16 @@ class CodeArtifactNpmDockerIntegrationTest {
private static final String REPO = "npm-sidecar-repo";
private static final String PACKAGE_NAME = "floci-verdaccio-spike";
+ @Inject
+ EmulatorConfig config;
+
private static String bearerToken;
private static byte[] publishFixture;
private static byte[] expectedTarballBytes;
@BeforeAll
static void setUp() throws IOException {
- CodeArtifactNpmSidecarProfile.requireDockerAndTheSidecarImage();
+ SidecarContainersProfile.requireDockerAndImage("floci.services.codeartifact.npm-image");
RestAssuredJsonUtils.configureAwsContentTypes();
ObjectMapper mapper = new ObjectMapper();
@@ -104,11 +110,12 @@ class CodeArtifactNpmDockerIntegrationTest {
// Pins VERDACCIO_PUBLIC_URL: without it this would be the container's own internal,
// client-unreachable address instead of a URL back through this same proxy.
- assertTrue(tarballUrl.startsWith("http://localhost:4566/codeartifact/npm/" + DOMAIN + "/" + REPO + "/"),
+ String publicUrl = config.effectiveBaseUrl();
+ assertTrue(tarballUrl.startsWith(publicUrl + "/codeartifact/npm/" + DOMAIN + "/" + REPO + "/"),
"tarball URL must point back through the proxy, was: " + tarballUrl);
byte[] fetchedTarball = given().header("Authorization", "Bearer " + bearerToken)
- .get(tarballUrl.substring("http://localhost:4566".length()))
+ .get(tarballUrl.substring(publicUrl.length()))
.then().statusCode(200)
.extract().asByteArray();
assertArrayEquals(expectedTarballBytes, fetchedTarball);
@@ -326,7 +333,7 @@ class CodeArtifactNpmDockerIntegrationTest {
private static int runningVerdaccioTestContainerCount() throws IOException, InterruptedException {
Process process = new ProcessBuilder("docker", "ps", "-q",
- "--filter", "name=floci-aws-codeartifact-npm-test-verdaccio-")
+ "--filter", "name=floci-aws-" + SidecarContainersProfile.NAMESPACE + "-verdaccio-")
.redirectErrorStream(true).start();
String output = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
process.waitFor();
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmSidecarProfile.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmSidecarProfile.java
deleted file mode 100644
index 9d347a9e85..0000000000
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmSidecarProfile.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package io.github.hectorvent.floci.services.codeartifact;
-
-import io.quarkus.test.junit.QuarkusTestProfile;
-import org.eclipse.microprofile.config.ConfigProvider;
-import org.junit.jupiter.api.Assumptions;
-
-import java.util.Map;
-
-/**
- * Shared by every CodeArtifact integration test that needs a real Verdaccio sidecar container,
- * started by {@link VerdaccioSidecarManager} exactly as in production. Namespaces containers as
- * {@code floci-codeartifact-npm-test-*} so the manager's remove-before-start never touches a
- * developer's real running Floci. Needs Docker; skipped without it. Locally it is also skipped
- * when the pinned image is not present, so a developer without registry access is not stuck; in
- * CI a missing image is a failure, since a vanished tag must not pass silently.
- */
-public class CodeArtifactNpmSidecarProfile implements QuarkusTestProfile {
-
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.docker.resource-namespace", "codeartifact-npm-test");
- }
-
- public static void requireDockerAndTheSidecarImage() {
- Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for CodeArtifact npm "
- + "sidecar integration tests");
- String image = ConfigProvider.getConfig().getValue("floci.services.codeartifact.npm-image", String.class);
- Assumptions.assumeTrue(imageUsable(image), "Verdaccio sidecar image " + image + " is not present locally");
- }
-
- private static boolean isDockerAvailable() {
- return run("docker", "version", "--format", "{{.Server.Version}}");
- }
-
- private static boolean imageUsable(String image) {
- if ("true".equals(System.getenv("CI"))) {
- return true;
- }
- return run("docker", "image", "inspect", image);
- }
-
- private static boolean run(String... command) {
- try {
- Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
- return process.waitFor() == 0;
- } catch (Exception ignored) {
- // Docker (or the image) isn't available; the caller turns this into a skipped test,
- // not a failure, so there is nothing more useful to log here.
- return false;
- }
- }
-}
diff --git a/src/test/java/io/github/hectorvent/floci/services/verifiedpermissions/VerifiedPermissionsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/verifiedpermissions/VerifiedPermissionsIntegrationTest.java
index cad8c8a41c..d3b0ada812 100644
--- a/src/test/java/io/github/hectorvent/floci/services/verifiedpermissions/VerifiedPermissionsIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/verifiedpermissions/VerifiedPermissionsIntegrationTest.java
@@ -1,11 +1,9 @@
package io.github.hectorvent.floci.services.verifiedpermissions;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
-import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
-import org.eclipse.microprofile.config.ConfigProvider;
-import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -25,50 +23,15 @@ import static org.hamcrest.Matchers.matchesPattern;
* not pass silently.
*/
@QuarkusTest
-@TestProfile(VerifiedPermissionsIntegrationTest.CedarSidecarProfile.class)
+@TestProfile(SidecarContainersProfile.class)
class VerifiedPermissionsIntegrationTest {
private static final String CONTENT_TYPE = "application/x-amz-json-1.0";
private static final String AUTH = "AWS4-HMAC-SHA256 Credential=111122223333/20260101/us-east-1/verifiedpermissions/aws4_request";
- /**
- * Namespaces the sidecar container as {@code floci-vp-test-cedar}: the manager removes any
- * container of its name before starting, and the test config uses the same empty namespace
- * as a developer's running Floci, whose live sidecar would otherwise be killed.
- */
- public static class CedarSidecarProfile implements QuarkusTestProfile {
- @Override
- public Map<String, String> getConfigOverrides() {
- return Map.of("floci.docker.resource-namespace", "vp-test");
- }
- }
-
@BeforeAll
static void requireDockerAndTheSidecarImage() {
RestAssuredJsonUtils.configureAwsContentTypes();
- Assumptions.assumeTrue(isDockerAvailable(),
- "Docker daemon must be available for Verified Permissions integration tests");
- String image = ConfigProvider.getConfig().getValue("floci.services.verifiedpermissions.cedar-image", String.class);
- Assumptions.assumeTrue(imageUsable(image), "Cedar sidecar image " + image + " is not present locally");
- }
-
- private static boolean isDockerAvailable() {
- return run("docker", "version", "--format", "{{.Server.Version}}");
- }
-
- private static boolean imageUsable(String image) {
- if ("true".equals(System.getenv("CI"))) {
- return true;
- }
- return run("docker", "image", "inspect", image);
- }
-
- private static boolean run(String... command) {
- try {
- Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
- return process.waitFor() == 0;
- } catch (Exception e) {
- return false;
- }
+ SidecarContainersProfile.requireDockerAndImage("floci.services.verifiedpermissions.cedar-image");
}
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/testing/SidecarContainersProfile.java b/src/test/java/io/github/hectorvent/floci/testing/SidecarContainersProfile.java
new file mode 100644
index 0000000000..7d1e191c6d
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/testing/SidecarContainersProfile.java
@@ -0,0 +1,73 @@
+package io.github.hectorvent.floci.testing;
+
+import io.quarkus.test.junit.QuarkusTestProfile;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.junit.jupiter.api.Assumptions;
+
+import java.util.Map;
+
+/**
+ * Shared by every integration test that runs a real sidecar container, started by its manager
+ * exactly as in production: the AppSync GraphQL sidecar, the CodeArtifact Reposilite and Verdaccio
+ * sidecars, and the Verified Permissions Cedar sidecar. Quarkus builds the application once per
+ * distinct profile class, so these classes share one application rather than each paying for
+ * their own.
+ *
+ * <p>Namespaces the containers as {@code floci-aws-sidecar-test-<sidecar>}. Each manager removes
+ * any container of its name before starting one, and the test config uses the same empty namespace
+ * as a developer's running Floci, whose live sidecars would otherwise be killed. Every sidecar type
+ * keeps its own name inside the namespace, so they never collide with each other.
+ *
+ * <p>Also pins the HTTP port and {@code floci.base-url} together. The AppSync resolver callback URL
+ * is built from the base URL's port, which in production is the port Floci listens on. Under
+ * {@code @QuarkusTest} the application listens on the test port instead, so without this the
+ * sidecar would call back to 4566 and every resolver-backed field would fail with a connection
+ * error.
+ */
+public class SidecarContainersProfile implements QuarkusTestProfile {
+
+ public static final String NAMESPACE = "sidecar-test";
+
+ private static final String TEST_PORT = "8081";
+
+ @Override
+ public Map<String, String> getConfigOverrides() {
+ return Map.of(
+ "floci.docker.resource-namespace", NAMESPACE,
+ "quarkus.http.test-port", TEST_PORT,
+ "floci.base-url", "http://localhost:" + TEST_PORT);
+ }
+
+ /**
+ * Skips the calling class without Docker. Locally it is also skipped when the sidecar image named
+ * by {@code imageProperty} is not present, so a developer without registry access is not stuck;
+ * in CI a missing image is a failure, since a vanished tag must not pass silently.
+ */
+ public static void requireDockerAndImage(String imageProperty) {
+ Assumptions.assumeTrue(isDockerAvailable(), "Docker daemon must be available for sidecar integration tests");
+ String image = ConfigProvider.getConfig().getValue(imageProperty, String.class);
+ Assumptions.assumeTrue(imageUsable(image), "Sidecar image " + image + " is not present locally");
+ }
+
+ private static boolean isDockerAvailable() {
+ return run("docker", "version", "--format", "{{.Server.Version}}");
+ }
+
+ private static boolean imageUsable(String image) {
+ if ("true".equals(System.getenv("CI"))) {
+ return true;
+ }
+ return run("docker", "image", "inspect", image);
+ }
+
+ private static boolean run(String... command) {
+ try {
+ Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
+ return process.waitFor() == 0;
+ } catch (Exception ignored) {
+ // Docker (or the image) isn't available; the caller turns this into a skipped test,
+ // not a failure, so there is nothing more useful to log here.
+ return false;
+ }
+ }
+}