Skip to content

Commit

Permalink
revert test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SoMuchForSubtlety committed Nov 9, 2022
1 parent ff9d3a0 commit 67c04bc
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 77 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci-rootless-podman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -382,9 +381,4 @@ public boolean isUsing(Class<? extends DockerClientProviderStrategy> providerStr
public Info getInfo() {
return getOrInitializeStrategy().getInfo();
}

public boolean supportsCompose() {
// podman does not support compose
return !(getOrInitializeStrategy() instanceof RootlessPodmanClientProviderStrategy);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DockerRegistryContainer(@NonNull Future<String> 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");
});
Expand Down Expand Up @@ -77,7 +77,7 @@ protected void containerIsStarting(InspectContainerResponse containerInfo) {
);
}

endpoint = "http://" + getHost() + ":" + port.get();
endpoint = getHost() + ":" + port.get();
}

public DockerImageName createImage() {
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand Down Expand Up @@ -139,13 +136,7 @@ public void shouldOnlyPublishExposedPorts() {
.getHostConfig()
.getPortBindings()
.getBindings();
// podman also returns unbound ports, but sets the binding value to null
List<Ports.Binding[]> 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();
Expand Down
29 changes: 2 additions & 27 deletions core/src/test/java/org/testcontainers/containers/NetworkTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand All @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
)
)
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 67c04bc

Please sign in to comment.