From f9757de7b0882e9d27c8aed35218de982ba8630b Mon Sep 17 00:00:00 2001 From: Radoslav Husar Date: Tue, 16 Apr 2024 16:26:49 +0200 Subject: [PATCH] Update tests to always run at least one of the variants against genuine or mock service. Rename the alternative test to MockS3.. to GenuineS3.. Update readme file accordingly. --- README.md | 3 +++ .../aws/AbstractS3_PINGDiscoveryTestCase.java | 4 ++++ ...Case.java => GenuineS3_PINGDiscoveryTestCase.java} | 7 +++---- .../protocols/aws/MockS3_PINGDiscoveryTestCase.java | 11 +++++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) rename src/test/java/org/jgroups/protocols/aws/{RealS3_PINGDiscoveryTestCase.java => GenuineS3_PINGDiscoveryTestCase.java} (69%) diff --git a/README.md b/README.md index 1714ca6..e6f7993 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,9 @@ mvn verify If any of the required properties are not specified tests will be skipped (uses `org.junit.Assume`). +In case credentials are not provided, tests will be run against mock containerized S3 instance. +These require a functioning podman or Docker environment. + # Reporting Issues Project JGroups AWS uses GitHub issues: diff --git a/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java b/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java index 9e1d034..eb90128 100644 --- a/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java +++ b/src/test/java/org/jgroups/protocols/aws/AbstractS3_PINGDiscoveryTestCase.java @@ -40,6 +40,10 @@ public abstract class AbstractS3_PINGDiscoveryTestCase { // credentials (e.g. running JDK8 and JDK9 on the CI). public static final String RANDOM_CLUSTER_NAME = UUID.randomUUID().toString(); + static boolean isGenuineCredentialsAvailable() { + return System.getenv("AWS_ACCESS_KEY_ID") != null && System.getenv("AWS_SECRET_ACCESS_KEY") != null && System.getenv("S3_PING_BUCKET_NAME") != null; + } + @Test public void testDiscovery() throws Exception { discover(RANDOM_CLUSTER_NAME, S3_PING.class.getSimpleName()); diff --git a/src/test/java/org/jgroups/protocols/aws/RealS3_PINGDiscoveryTestCase.java b/src/test/java/org/jgroups/protocols/aws/GenuineS3_PINGDiscoveryTestCase.java similarity index 69% rename from src/test/java/org/jgroups/protocols/aws/RealS3_PINGDiscoveryTestCase.java rename to src/test/java/org/jgroups/protocols/aws/GenuineS3_PINGDiscoveryTestCase.java index aebf532..88c22ae 100644 --- a/src/test/java/org/jgroups/protocols/aws/RealS3_PINGDiscoveryTestCase.java +++ b/src/test/java/org/jgroups/protocols/aws/GenuineS3_PINGDiscoveryTestCase.java @@ -20,15 +20,14 @@ import org.junit.BeforeClass; /** - * Tests against real S3 endpoint requiring credentials. + * Tests against genuine S3 endpoint requiring credentials. * * @author Radoslav Husar */ -public class RealS3_PINGDiscoveryTestCase extends AbstractS3_PINGDiscoveryTestCase { +public class GenuineS3_PINGDiscoveryTestCase extends AbstractS3_PINGDiscoveryTestCase { @BeforeClass public static void assumeCredentials() { - Assume.assumeTrue("Credentials are not available, test is ignored!", System.getenv("AWS_ACCESS_KEY_ID") != null && System.getenv("AWS_SECRET_ACCESS_KEY") != null && System.getenv("S3_PING_BUCKET_NAME") != null); + Assume.assumeTrue("Credentials are not available, test will be ignored!", isGenuineCredentialsAvailable()); } - } diff --git a/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java b/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java index fa6cdc6..4f396b2 100644 --- a/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java +++ b/src/test/java/org/jgroups/protocols/aws/MockS3_PINGDiscoveryTestCase.java @@ -22,8 +22,10 @@ import org.junit.BeforeClass; import org.testcontainers.DockerClientFactory; +import static org.junit.Assert.fail; + /** - * Tests against a mock S3 service. + * Tests against a containerized mock S3 service. * * @author Radoslav Husar */ @@ -33,7 +35,12 @@ public class MockS3_PINGDiscoveryTestCase extends AbstractS3_PINGDiscoveryTestCa @BeforeClass public static void setUp() { - Assume.assumeTrue("Docker environment is not available - skipping tests against S3 mock service.", isDockerAvailable()); + // If credentials are available, we can conditionally skip Mock tests + if (isGenuineCredentialsAvailable()) { + Assume.assumeTrue("Podman/Docker environment is not available - skipping tests against S3 mock service.", isDockerAvailable()); + } else if (!isDockerAvailable()) { + fail("Credentials are not provided, thus Podman/Docker is required to run tests against a mock service!"); + } // TODO Since 3.3.0 the obscure cluster name tests start to fail. Manage the version manually and keep on '3.2.0' for now. s3Mock = new S3MockContainer("3.2.0");