-
-
Notifications
You must be signed in to change notification settings - Fork 588
feat(atlaslocal): add MongoDB Atlas Local module #3254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mdelapenya
merged 28 commits into
testcontainers:main
from
prestonvasquez:feat/atlaslocal-module
Sep 18, 2025
Merged
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
4353caf
Bootstrap atlaslocal module
prestonvasquez b4f178a
Create atlaslocal module
prestonvasquez 7e666fc
Remove atlaslocal in favor of mongodb/atlaslocal
prestonvasquez d96db72
Prep mongod for atlaslocal
prestonvasquez db99c8b
Migrate atlaslocal to mongodb/atlas local
prestonvasquez 6a49cd0
Merge branch 'main' into feat/atlaslocal-module
prestonvasquez 1d19def
Make logging API deterministic
prestonvasquez ba459ad
Remove magic strings and clean up tests
prestonvasquez c151080
Merge branch 'main' into feat/atlaslocal-module
prestonvasquez 3b07964
Add functional options API
prestonvasquez 67bb873
Merge branch 'main' into feat/atlaslocal-module
mdelapenya cc079c8
deps: use v2 package for connstring
mdelapenya ec6d903
chore: run make lint
mdelapenya 0a47e03
fix: CleanupContainer already uses t.Cleanup
mdelapenya 6dacc55
docs: fix embedded code snippets
mdelapenya 3bd2515
chore: simplify port endpoint calculation
mdelapenya d319832
chore: refine error messages
mdelapenya 8ace630
chore: remove redundant else after if-return
mdelapenya 8008ff7
chore: remove unused argument from test helper
mdelapenya afc9d98
fix: modulegen format
mdelapenya dde38bf
docs: fix not-released marker
mdelapenya 4c9cfe7
chore: revert gitignore for build speed
mdelapenya 5334f18
fix: no neet to add a dependabot entry
mdelapenya 1f145a9
fix: cleanup container in test
mdelapenya def1ad8
chore: consistent variable name
mdelapenya c5891e4
docs: add whitespace
mdelapenya 7cec56c
chore: use defaultPort constant for consistency
mdelapenya aab5560
chore: close reader in test
mdelapenya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,6 @@ TEST-*.xml | |
|
|
||
| # Environment variables | ||
| .env | ||
|
|
||
| # Coverage files | ||
| coverage.out | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| # MongoDB Atlas Local | ||
|
|
||
| Not available until the next release <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| ## Introduction | ||
|
|
||
| The MongoDB Atlas Local module for Testcontainers lets you spin up a local MongoDB Atlas instance in Docker using | ||
| [mongodb/mongodb-atlas-local](https://hub.docker.com/r/mongodb/mongodb-atlas-local) for integration tests and | ||
| development. This module supports SCRAM authentication, init scripts, and custom log file mounting. | ||
|
|
||
| This module differs from the standard modules/mongodb Testcontainers module, allowing users to spin up a full local | ||
| Atlas-like environment complete with Atlas Search and Atlas Vector Search. | ||
|
|
||
| ## Adding this module to your project dependencies | ||
|
|
||
| Please run the following command to add the MongoDB Atlas Local module to your Go dependencies: | ||
|
|
||
| ``` | ||
| go get github.com/testcontainers/testcontainers-go/modules/mongodb/atlaslocal | ||
| ``` | ||
|
|
||
| ## Usage example | ||
|
|
||
| <!--codeinclude--> | ||
| [Creating a MongoDB Atlas Local container](../../modules/mongodb/atlaslocal/examples_test.go) inside_block:ExampleRun | ||
| <!--/codeinclude--> | ||
|
|
||
| ## Module Reference | ||
|
|
||
| ### Run function | ||
|
|
||
| - Not available until the next release <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| The `atlaslocal` module exposes one entrypoint function to create the MongoDB Atlas Local container, and this | ||
| function receives three parameters: | ||
|
|
||
| ```golang | ||
| func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) | ||
| ``` | ||
|
|
||
| - `context.Context`, the Go context. | ||
| - `string`, the Docker image to use. | ||
| - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
|
||
| #### Image | ||
|
|
||
| Use the second argument in the `Run` function to set a valid Docker image. | ||
| In example: `Run(context.Background(), "mongodb/mongodb-atlas-local:latest")`. | ||
|
|
||
| ### Container Options | ||
|
|
||
| When starting the MongoDB Atlas Local container, you can pass options in a variadic way to configure it. | ||
|
|
||
| #### WithUsername | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option sets the initial username to be created when the container starts, populating the | ||
| `MONGODB_INITDB_ROOT_USERNAME` environment variable. You cannot mix this option with `WithUsernameFile`, as it will | ||
| result in an error. | ||
|
|
||
| #### WithPassword | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option sets the initial password to be created when the container starts, populating the | ||
| `MONGODB_INITDB_ROOT_PASSWORD` environment variable. You cannot mix this option with `WithPasswordFile`, as it will | ||
| result in an error. | ||
|
|
||
| #### WithUsernameFile | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option mounts a local file as the MongoDB root username secret at`/run/secrets/mongo-root-username` | ||
| and sets the `MONGODB_INITDB_ROOT_USERNAME_FILE` environment variable. The path must be absolute and exist; no-op if | ||
| empty. | ||
|
|
||
| #### WithPasswordFile | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option mounts a local file as the MongoDB root password secret at `/run/secrets/mongo-root-password` and | ||
| sets the `MONGODB_INITDB_ROOT_PASSWORD_FILE` environment variable. The path must be absolute and exist; no-op if empty. | ||
|
|
||
| #### WithNoTelemetry | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option disables the telemetry feature of MongoDB Atlas Local, setting the `DO_NOT_TRACK` environment | ||
| variable to `1`. | ||
|
|
||
| #### WithInitDatabase | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option allows you to specify a database name to be initialized when the container starts, populating | ||
| the `MONGODB_INITDB_DATABASE` environment variable. | ||
|
|
||
| #### WithInitScripts | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| Mounts a directory into `/docker-entrypoint-initdb.d`, running `.sh`/`.js` scripts on startup. Calling this function | ||
| multiple times mounts only the latest directory. | ||
|
|
||
| #### WithMongotLogFile | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option writes the mongot logs to `/tmp/mongot.log` inside the container. See | ||
| `(*Container).ReadMongotLogs` to read the logs locally. | ||
|
|
||
| #### WithMongotLogToStdout | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option writes the mongot logs to `/dev/stdout` inside the container. See | ||
| `(*Container).ReadMongotLogs` to read the logs locally. | ||
|
|
||
| #### WithMongotLogToStderr | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option writes the mongot logs to `/dev/stderr` inside the container. See | ||
| `(*Container).ReadMongotLogs` to read the logs locally. | ||
|
|
||
| #### WithRunnerLogFile | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option writes the runner logs to `/tmp/runner.log` inside the container. See | ||
| `(*Container).ReadRunnerLogs` to read the logs locally. | ||
|
|
||
| #### WithRunnerLogToStdout | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option writes the runner logs to `/dev/stdout` inside the container. See | ||
| `(*Container).ReadRunnerLogs` to read the logs locally. | ||
|
|
||
| #### WithRunnerLogToStderr | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| This functional option writes the runner logs to `/dev/stderr` inside the container. See | ||
| `(*Container).ReadRunnerLogs` to read the logs locally. | ||
|
|
||
| {% include "../features/common_functional_options_list.md" %} | ||
|
|
||
| ### Container Methods | ||
|
|
||
| The MongoDB Atlas Local container exposes the following methods: | ||
|
|
||
|
|
||
| #### ConnectionString | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| The `ConnectionString` method returns the connection string to connect to the MongoDB Atlas Local container. | ||
| It returns a string with the format `mongodb://<host>:<port>/?directConnection=true`. | ||
|
|
||
| It can be used to configure a MongoDB client (`go.mongodb.org/mongo-driver/v2/mongo`), e.g.: | ||
|
|
||
| <!--codeinclude--> | ||
| [Using ConnectionString with the MongoDB client](../../modules/mongodb/atlaslocal/examples_test.go) inside_block:connectToMongo | ||
| <!--/codeinclude--> | ||
|
|
||
| #### ReadMongotLogs | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| The `ReadMongotLogs` returns a reader for the log solution specified when constructing the container. | ||
|
|
||
|
|
||
| <!--codeinclude--> | ||
| [Using ReadMongotLogs with the MongoDB client](../../modules/mongodb/atlaslocal/examples_test.go) inside_block:readMongotLogs | ||
| <!--/codeinclude--> | ||
|
|
||
| #### ReadRunnerLogs | ||
|
|
||
| - Since <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
|
||
| The `ReadRunnerLogs` returns a reader for the log solution specified when constructing the container. | ||
|
|
||
|
|
||
| <!--codeinclude--> | ||
| [Using ReadRunnerLogs with the MongoDB client](../../modules/mongodb/atlaslocal/examples_test.go) inside_block:readRunnerLogs | ||
| <!--/codeinclude--> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.