From 67c04bc7faca8b0a290e6b17a5dd61ce15edcd5a Mon Sep 17 00:00:00 2001 From: SoMuchForSubtlety Date: Wed, 9 Nov 2022 16:24:22 +0100 Subject: [PATCH] revert test changes --- .github/workflows/ci-rootless-podman.yml | 8 ++--- build.gradle | 16 +++++++++- .../testcontainers/DockerClientFactory.java | 6 ---- .../utility/TestEnvironment.java | 4 --- .../DockerRegistryContainer.java | 8 ++--- .../containers/GenericContainerTest.java | 11 +------ .../containers/NetworkTest.java | 29 ++----------------- .../DockerHealthcheckWaitStrategyTest.java | 2 +- .../junit/DockerNetworkModeTest.java | 14 +++------ .../utility/AuthenticatedImagePullTest.java | 6 ++-- .../test/java/generic/CmdModifierTest.java | 4 --- 11 files changed, 31 insertions(+), 77 deletions(-) diff --git a/.github/workflows/ci-rootless-podman.yml b/.github/workflows/ci-rootless-podman.yml index 829b786c6c6..8966897f856 100644 --- a/.github/workflows/ci-rootless-podman.yml +++ b/.github/workflows/ci-rootless-podman.yml @@ -17,15 +17,11 @@ jobs: - name: Set XDG_RUNTIME_DIR run: echo "XDG_RUNTIME_DIR=/run/user/$UID" >> $GITHUB_ENV - name: Create registries.conf - # allow pulling images without a registry specified and allow pulling from insecure local registry + # allow pulling images without a registry specified run: | mkdir -p $HOME/.config/containers echo 'unqualified-search-registries = ["docker.io"]' > $HOME/.config/containers/registries.conf - echo '' >> $HOME/.config/containers/registries.conf - echo '[[registry]]' >> $HOME/.config/containers/registries.conf - echo 'location = "localhost:50001"' >> $HOME/.config/containers/registries.conf - echo 'insecure = true' >> $HOME/.config/containers/registries.conf - - name: Istall latest podman release + - name: Install latest podman release # see https://podman.io/getting-started/installation#ubuntu run: | sudo mkdir -p /etc/apt/keyrings diff --git a/build.gradle b/build.gradle index 10ba3124049..f32bdd38555 100644 --- a/build.gradle +++ b/build.gradle @@ -98,9 +98,23 @@ subprojects { } } - // podman does not support compose if (System.properties['test.profile'] == 'podman') { exclude '**/*DockerCompose*' + filter { + excludeTestsMatching '*AuthenticatedImagePullTest*' + excludeTestsMatching '*DockerNetworkModeTest*' + excludeTestsMatching '*AmbiguousImagePullTest*' + excludeTestsMatching '*ImagePullPolicyTest*' + + excludeTestsMatching '*testThatAuthLocatorIsUsedForDockerComposePull' + excludeTestsMatching '*testMemoryLimitModified' + excludeTestsMatching '*testBuilder' + excludeTestsMatching '*testModifiers' + excludeTestsMatching '*shouldOnlyPublishExposedPorts' + excludeTestsMatching '*shouldReportOOMAfterWait' + excludeTestsMatching '*runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally' + } + } } diff --git a/core/src/main/java/org/testcontainers/DockerClientFactory.java b/core/src/main/java/org/testcontainers/DockerClientFactory.java index 10b48556932..73bf24e511c 100644 --- a/core/src/main/java/org/testcontainers/DockerClientFactory.java +++ b/core/src/main/java/org/testcontainers/DockerClientFactory.java @@ -21,7 +21,6 @@ import org.apache.commons.lang3.SystemUtils; import org.testcontainers.dockerclient.DockerClientProviderStrategy; import org.testcontainers.dockerclient.DockerMachineClientProviderStrategy; -import org.testcontainers.dockerclient.RootlessPodmanClientProviderStrategy; import org.testcontainers.dockerclient.TransportConfig; import org.testcontainers.images.RemoteDockerImage; import org.testcontainers.images.TimeLimitedLoggedPullImageResultCallback; @@ -382,9 +381,4 @@ public boolean isUsing(Class providerStr public Info getInfo() { return getOrInitializeStrategy().getInfo(); } - - public boolean supportsCompose() { - // podman does not support compose - return !(getOrInitializeStrategy() instanceof RootlessPodmanClientProviderStrategy); - } } diff --git a/core/src/main/java/org/testcontainers/utility/TestEnvironment.java b/core/src/main/java/org/testcontainers/utility/TestEnvironment.java index 21c4a9ffb63..ee58199540b 100644 --- a/core/src/main/java/org/testcontainers/utility/TestEnvironment.java +++ b/core/src/main/java/org/testcontainers/utility/TestEnvironment.java @@ -17,10 +17,6 @@ public static boolean dockerApiAtLeast(String minimumVersion) { return current.compareTo(min) >= 0; } - public static boolean clientSupportsCompose() { - return DockerClientFactory.instance().supportsCompose(); - } - public static boolean dockerExecutionDriverSupportsExec() { String executionDriver = DockerClientFactory.instance().getActiveExecutionDriver(); diff --git a/core/src/test/java/org/testcontainers/DockerRegistryContainer.java b/core/src/test/java/org/testcontainers/DockerRegistryContainer.java index 219ee02644e..a907c674386 100644 --- a/core/src/test/java/org/testcontainers/DockerRegistryContainer.java +++ b/core/src/test/java/org/testcontainers/DockerRegistryContainer.java @@ -37,7 +37,7 @@ public DockerRegistryContainer(@NonNull Future image) { @Override protected void configure() { super.configure(); - withEnv("REGISTRY_HTTP_ADDR", "127.0.0.1:50001"); + withEnv("REGISTRY_HTTP_ADDR", "127.0.0.1:0"); withCreateContainerCmdModifier(cmd -> { cmd.getHostConfig().withNetworkMode("host"); }); @@ -77,7 +77,7 @@ protected void containerIsStarting(InspectContainerResponse containerInfo) { ); } - endpoint = "http://" + getHost() + ":" + port.get(); + endpoint = getHost() + ":" + port.get(); } public DockerImageName createImage() { @@ -96,11 +96,11 @@ public DockerImageName createImage(String originalImage, String tag) { String dummyImageId = client.inspectImageCmd(originalImage).exec().getId(); DockerImageName imageName = DockerImageName - .parse(getEndpoint().replaceFirst("http://", "") + "/" + Base58.randomString(6).toLowerCase()) + .parse(getEndpoint() + "/" + Base58.randomString(6).toLowerCase()) .withTag(tag); // push the image to the registry - client.tagImageCmd(dummyImageId, imageName.getUnversionedPart(), tag).exec(); + client.tagImageCmd(dummyImageId, imageName.asCanonicalNameString(), tag).exec(); client .pushImageCmd(imageName.asCanonicalNameString()) diff --git a/core/src/test/java/org/testcontainers/containers/GenericContainerTest.java b/core/src/test/java/org/testcontainers/containers/GenericContainerTest.java index 317eeba42ca..12f5810bc27 100644 --- a/core/src/test/java/org/testcontainers/containers/GenericContainerTest.java +++ b/core/src/test/java/org/testcontainers/containers/GenericContainerTest.java @@ -25,7 +25,6 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -41,8 +40,6 @@ public void shouldReportOOMAfterWait() { Info info = DockerClientFactory.instance().client().infoCmd().exec(); // Poor man's rootless Docker detection :D Assumptions.assumeThat(info.getSecurityOptions()).doesNotContain("rootless"); - // setting swappiness is not allowed for cgroups v2 - Assumptions.assumeThat(info.getRawValues().get("CgroupVersion")).isNotEqualTo("2"); try ( GenericContainer container = new GenericContainer<>(TestImages.TINY_IMAGE) .withStartupCheckStrategy(new NoopStartupCheckStrategy()) @@ -139,13 +136,7 @@ public void shouldOnlyPublishExposedPorts() { .getHostConfig() .getPortBindings() .getBindings(); - // podman also returns unbound ports, but sets the binding value to null - List boundPorts = hostBindings - .values() - .stream() - .filter(Objects::nonNull) - .collect(Collectors.toList()); - assertThat(boundPorts).as("only 1 port is bound on the host (published)").hasSize(1); + assertThat(hostBindings).as("only 1 port is bound on the host (published)").hasSize(1); Integer mappedPort = container.getMappedPort(8080); assertThat(mappedPort != 8080).as("port 8080 is bound to a different port on the host").isTrue(); diff --git a/core/src/test/java/org/testcontainers/containers/NetworkTest.java b/core/src/test/java/org/testcontainers/containers/NetworkTest.java index cbf06baf066..099bef20ed7 100644 --- a/core/src/test/java/org/testcontainers/containers/NetworkTest.java +++ b/core/src/test/java/org/testcontainers/containers/NetworkTest.java @@ -1,6 +1,5 @@ package org.testcontainers.containers; -import com.github.dockerjava.api.model.Network.Ipam; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.runners.Enclosed; @@ -66,19 +65,7 @@ public void testNetworkSupport() throws Exception { @Test public void testBuilder() { - try ( - Network network = Network - .builder() - .driver("macvlan") - .createNetworkCmdModifier(cmd -> { - cmd.withIpam( - // mcvlan needs a subnet or podman will refuse to create the network - // https://docs.podman.io/en/latest/markdown/podman-network-create.1.html#driver-d - new Ipam().withConfig(new Ipam.Config().withSubnet("192.168.100.1/25")) - ); - }) - .build() - ) { + try (Network network = Network.builder().driver("macvlan").build()) { String id = network.getId(); assertThat( DockerClientFactory.instance().client().inspectNetworkCmd().withNetworkId(id).exec().getDriver() @@ -91,19 +78,7 @@ public void testBuilder() { @Test public void testModifiers() { try ( - Network network = Network - .builder() - .createNetworkCmdModifier(cmd -> { - cmd - .withDriver("macvlan") - .withIpam( - new Ipam() - // mcvlan needs a subnet or podman will refuse to create the network - // https://docs.podman.io/en/latest/markdown/podman-network-create.1.html#driver-d - .withConfig(new Ipam.Config().withSubnet("192.168.100.1/25")) - ); - }) - .build() + Network network = Network.builder().createNetworkCmdModifier(cmd -> cmd.withDriver("macvlan")).build() ) { String id = network.getId(); assertThat( diff --git a/core/src/test/java/org/testcontainers/containers/wait/strategy/DockerHealthcheckWaitStrategyTest.java b/core/src/test/java/org/testcontainers/containers/wait/strategy/DockerHealthcheckWaitStrategyTest.java index 7ef82f28079..0cbf257e9b5 100644 --- a/core/src/test/java/org/testcontainers/containers/wait/strategy/DockerHealthcheckWaitStrategyTest.java +++ b/core/src/test/java/org/testcontainers/containers/wait/strategy/DockerHealthcheckWaitStrategyTest.java @@ -27,7 +27,7 @@ public void setUp() { ) .withFileFromClasspath("Dockerfile", "health-wait-strategy-dockerfile/Dockerfile") ) - .waitingFor(Wait.forHealthcheck().withStartupTimeout(Duration.ofSeconds(5))); + .waitingFor(Wait.forHealthcheck().withStartupTimeout(Duration.ofSeconds(3))); } @Test diff --git a/core/src/test/java/org/testcontainers/junit/DockerNetworkModeTest.java b/core/src/test/java/org/testcontainers/junit/DockerNetworkModeTest.java index 97aafb80bdb..b048e4716fd 100644 --- a/core/src/test/java/org/testcontainers/junit/DockerNetworkModeTest.java +++ b/core/src/test/java/org/testcontainers/junit/DockerNetworkModeTest.java @@ -27,11 +27,8 @@ public void testNoNetworkContainer() { container.start(); NetworkSettings networkSettings = container.getContainerInfo().getNetworkSettings(); - assertThat(networkSettings.getNetworks()) - .as("only one network is set") - .allSatisfy((name, containerNetwork) -> { - assertThat(name).as("network is 'none'").isEqualTo("none"); - }); + assertThat(networkSettings.getNetworks()).as("only one network is set").hasSize(1); + assertThat(networkSettings.getNetworks()).as("network is 'none'").containsKey("none"); } } @@ -46,11 +43,8 @@ public void testHostNetworkContainer() { container.start(); NetworkSettings networkSettings = container.getContainerInfo().getNetworkSettings(); - assertThat(networkSettings.getNetworks()) - .as("only one network is set") - .allSatisfy((name, containerNetwork) -> { - assertThat(networkSettings.getNetworks()).as("network is 'host'").containsKey("host"); - }); + assertThat(networkSettings.getNetworks()).as("only one network is set").hasSize(1); + assertThat(networkSettings.getNetworks()).as("network is 'host'").containsKey("host"); } } } diff --git a/core/src/test/java/org/testcontainers/utility/AuthenticatedImagePullTest.java b/core/src/test/java/org/testcontainers/utility/AuthenticatedImagePullTest.java index 21ba4fe7e34..0e00dd87bf7 100644 --- a/core/src/test/java/org/testcontainers/utility/AuthenticatedImagePullTest.java +++ b/core/src/test/java/org/testcontainers/utility/AuthenticatedImagePullTest.java @@ -3,7 +3,6 @@ import com.github.dockerjava.api.model.AuthConfig; import org.intellij.lang.annotations.Language; import org.junit.AfterClass; -import org.junit.Assume; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; @@ -64,14 +63,14 @@ public static void beforeClass() throws Exception { final AuthConfig authConfig = new AuthConfig() .withUsername("testuser") .withPassword("notasecret") - .withRegistryAddress(testRegistryAddress); + .withRegistryAddress("http://" + testRegistryAddress); // Replace the RegistryAuthLocator singleton with our mock, for the duration of this test final RegistryAuthLocator mockAuthLocator = Mockito.mock(RegistryAuthLocator.class); RegistryAuthLocator.setInstance(mockAuthLocator); when( mockAuthLocator.lookupAuthConfig( - argThat(argument -> testRegistryAddress.replaceFirst("http://", "").equals(argument.getRegistry())), + argThat(argument -> testRegistryAddress.equals(argument.getRegistry())), any() ) ) @@ -118,7 +117,6 @@ public void testThatAuthLocatorIsUsedForDockerfileBuild() throws IOException { @Test public void testThatAuthLocatorIsUsedForDockerComposePull() throws IOException { - Assume.assumeTrue(TestEnvironment.clientSupportsCompose()); // Prepare a simple temporary Docker Compose manifest which requires our custom private image Path tempFile = getLocalTempFile(".docker-compose.yml"); @Language("yaml") diff --git a/docs/examples/junit4/generic/src/test/java/generic/CmdModifierTest.java b/docs/examples/junit4/generic/src/test/java/generic/CmdModifierTest.java index 314098bfb7a..a32f23ca8c2 100644 --- a/docs/examples/junit4/generic/src/test/java/generic/CmdModifierTest.java +++ b/docs/examples/junit4/generic/src/test/java/generic/CmdModifierTest.java @@ -2,7 +2,6 @@ import com.github.dockerjava.api.DockerClient; import com.github.dockerjava.api.model.Info; -import org.assertj.core.api.Assumptions; import org.junit.Rule; import org.junit.Test; import org.testcontainers.DockerClientFactory; @@ -49,9 +48,6 @@ public void testHostnameModified() throws IOException, InterruptedException { @Test public void testMemoryLimitModified() throws IOException, InterruptedException { - Info info = DockerClientFactory.instance().client().infoCmd().exec(); - // setting swap is not allowed for cgroups v2 - Assumptions.assumeThat(info.getRawValues().get("CgroupVersion")).isNotEqualTo("2"); final Container.ExecResult execResult = memoryLimitedRedis.execInContainer("cat", getMemoryLimitFilePath()); assertThat(execResult.getStdout().trim()).isEqualTo(String.valueOf(memoryInBytes)); }