Skip to content

Commit 42a8e50

Browse files
author
admitrov
committed
Update ContainerUtilsTest to use copyToTransferableContainerPathMap instead of getBinds
Replace deprecated getBinds() assertions with reflection-based access to copyToTransferableContainerPathMap field. Update mount volume verification to check Transferable entries instead of Bind objects. Remove unused docker-java imports (AccessMode, Bind) and add reflection-related imports (Field, GenericContainer, Transferable).
1 parent b58ad50 commit 42a8e50

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

testcontainers-common/src/test/java/com/playtika/testcontainer/common/utils/ContainerUtilsTest.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.playtika.testcontainer.common.utils;
22

3-
import com.github.dockerjava.api.model.AccessMode;
4-
import com.github.dockerjava.api.model.Bind;
53
import com.playtika.testcontainer.bootstrap.EchoContainer;
64
import com.playtika.testcontainer.common.checks.PositiveCommandWaitStrategy;
75
import com.playtika.testcontainer.common.properties.CommonContainerProperties;
@@ -13,8 +11,11 @@
1311
import org.junit.jupiter.api.BeforeEach;
1412
import org.junit.jupiter.api.Test;
1513
import org.testcontainers.containers.BindMode;
14+
import org.testcontainers.containers.GenericContainer;
15+
import org.testcontainers.images.builder.Transferable;
1616
import org.testcontainers.utility.MountableFile;
1717

18+
import java.lang.reflect.Field;
1819
import java.util.ArrayList;
1920
import java.util.HashMap;
2021
import java.util.List;
@@ -39,7 +40,7 @@ void tearDown() {
3940
}
4041

4142
@Test
42-
void configureCommonsAndStart() {
43+
void configureCommonsAndStart() throws Exception {
4344
String[] command = {"/bin/sh", "-c", "while true; do echo 'Press [CTRL+C] to stop..'; sleep 1; done"};
4445
Map<String, String> env = new HashMap<>();
4546
env.put("TEST_ENV_VAR", "VALUE_TEST");
@@ -79,13 +80,23 @@ public boolean matches(Map.Entry<MountableFile, String> mountableFileObjectEntry
7980
};
8081
assertThat(echoContainer.getCopyToFileContainerPathMap()).hasEntrySatisfying(hasCopyToFileContainerPath);
8182

83+
Map<Transferable, String> transferableMap = getCopyToTransferableContainerPathMap(echoContainer);
84+
assertThat(transferableMap).hasSize(2);
8285
for (MountVolume mountVolume : mountVolumes) {
83-
Condition<Bind> hasMountBindings = new Condition<>(
84-
bind -> MountableFile.forHostPath(mountVolume.getHostPath()).getResolvedPath().equals(bind.getPath())
85-
&& mountVolume.getContainerPath().equals(bind.getVolume().getPath())
86-
&& (BindMode.READ_WRITE.equals(mountVolume.getMode()) && AccessMode.rw == bind.getAccessMode()
87-
|| BindMode.READ_ONLY.equals(mountVolume.getMode()) && AccessMode.ro == bind.getAccessMode()), "binding");
88-
assertThat(echoContainer.getBinds()).hasSize(2).haveExactly(1, hasMountBindings);
86+
String expectedPath = MountableFile.forHostPath(mountVolume.getHostPath()).getResolvedPath();
87+
Condition<Map.Entry<Transferable, String>> hasMountVolume = new Condition<>(
88+
entry -> entry.getKey() instanceof MountableFile mountableFile
89+
&& mountableFile.getResolvedPath().equals(expectedPath)
90+
&& mountVolume.getContainerPath().equals(entry.getValue()),
91+
"mount volume copy");
92+
assertThat(transferableMap).hasEntrySatisfying(hasMountVolume);
8993
}
9094
}
95+
96+
@SuppressWarnings("unchecked")
97+
private static Map<Transferable, String> getCopyToTransferableContainerPathMap(EchoContainer container) throws Exception {
98+
Field field = GenericContainer.class.getDeclaredField("copyToTransferableContainerPathMap");
99+
field.setAccessible(true);
100+
return (Map<Transferable, String>) field.get(container);
101+
}
91102
}

0 commit comments

Comments
 (0)