Skip to content

Add MongoDB init script regression test#11923

Open
HuseynBlv wants to merge 1 commit into
testcontainers:mainfrom
HuseynBlv:mongodb-init-script-startup
Open

Add MongoDB init script regression test#11923
HuseynBlv wants to merge 1 commit into
testcontainers:mainfrom
HuseynBlv:mongodb-init-script-startup

Conversation

@HuseynBlv

Copy link
Copy Markdown

Summary

Related to #3066.

This PR adds a regression test for MongoDB init script support in MongoDBContainer.

The new test verifies that a JavaScript init file copied into /docker-entrypoint-initdb.d/mongo-init.js is executed during MongoDB startup, and that the data inserted by the script is available after the container starts.

Context

MongoDB Docker images support initialization scripts placed under /docker-entrypoint-initdb.d/. This is useful in tests where users want to create initial databases, collections, users, or seed data automatically when the container starts.

This PR adds test coverage for that behavior in MongoDBContainer, so future changes do not accidentally break init-script support.

Changes

  • Added shouldRunInitScript() to MongoDBContainerTest
  • Added a small mongo-init.js test resource
  • The test:
    • copies mongo-init.js into /docker-entrypoint-initdb.d/mongo-init.js
    • starts MongoDBContainer
    • connects to MongoDB after startup
    • verifies that the init script inserted the expected document
  • No production code changes
  • No dependency changes
  • No new module added

Verification

Ran:

./gradlew checkstyleMain checkstyleTest spotlessApply

./gradlew spotlessCheck

./gradlew :testcontainers-mongodb:test --tests "org.testcontainers.mongodb.MongoDBContainerTest.shouldRunInitScript"

@HuseynBlv HuseynBlv requested a review from a team as a code owner July 12, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant