File tree Expand file tree Collapse file tree 2 files changed +9
-12
lines changed
main/java/org/testcontainers/containers
test/java/org/testcontainers/mongodb Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -236,10 +236,7 @@ void withSharding() {
236236 * @return this container instance
237237 */
238238 public MongoDBContainer withInitScript (String scriptPath ) {
239- withCopyFileToContainer (
240- MountableFile .forClasspathResource (scriptPath ),
241- "/docker-entrypoint-initdb.d/init.js"
242- );
239+ withCopyFileToContainer (MountableFile .forClasspathResource (scriptPath ), "/docker-entrypoint-initdb.d/init.js" );
243240
244241 this .waitStrategy = Wait .forLogMessage ("(?i).*waiting for connections.*" , 2 );
245242
Original file line number Diff line number Diff line change 11package org .testcontainers .containers ;
22
33import org .junit .jupiter .api .Test ;
4- import org .testcontainers .utility .MountableFile ;
54
65import java .time .Duration ;
76
@@ -12,16 +11,17 @@ class MongoDBInitScriptTest {
1211 @ Test
1312 void testWithInitScript () {
1413 // Start the container using try-with-resources to ensure it closes automatically
15- try (MongoDBContainer mongoDB = new MongoDBContainer ("mongo:4.0.10" )
16- // Configure the init script. This triggers a restart inside the container,
17- // so the container must wait for the second "waiting for connections" log message.
18- .withInitScript ("init.js" )
19- .withStartupTimeout (Duration .ofSeconds (30 ))) {
20-
14+ try (
15+ MongoDBContainer mongoDB = new MongoDBContainer ("mongo:4.0.10" )
16+ // Configure the init script. This triggers a restart inside the container,
17+ // so the container must wait for the second "waiting for connections" log message.
18+ .withInitScript ("init.js" )
19+ .withStartupTimeout (Duration .ofSeconds (30 ))
20+ ) {
2121 mongoDB .start ();
2222
2323 // Assert that the container started successfully
2424 assertThat (mongoDB .isRunning ()).isTrue ();
2525 }
2626 }
27- }
27+ }
You can’t perform that action at this time.
0 commit comments