11package com .playtika .testcontainer .common .utils ;
22
3- import com .github .dockerjava .api .model .AccessMode ;
4- import com .github .dockerjava .api .model .Bind ;
53import com .playtika .testcontainer .bootstrap .EchoContainer ;
64import com .playtika .testcontainer .common .checks .PositiveCommandWaitStrategy ;
75import com .playtika .testcontainer .common .properties .CommonContainerProperties ;
1311import org .junit .jupiter .api .BeforeEach ;
1412import org .junit .jupiter .api .Test ;
1513import org .testcontainers .containers .BindMode ;
14+ import org .testcontainers .containers .GenericContainer ;
15+ import org .testcontainers .images .builder .Transferable ;
1616import org .testcontainers .utility .MountableFile ;
1717
18+ import java .lang .reflect .Field ;
1819import java .util .ArrayList ;
1920import java .util .HashMap ;
2021import 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