-
-
Notifications
You must be signed in to change notification settings - Fork 500
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
feat(modules.mongodb): add replica set support via opts #2469
feat(modules.mongodb): add replica set support via opts #2469
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Some differences between this PR and #2139 include:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
504cd35
to
4e6248c
Compare
4e6248c
to
fa37148
Compare
The `WithReplicaSet` option configures the MongoDB container to run a single-node replica set named "rs". The container will wait until the replica set is ready.
fa37148
to
e6bc11e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
@@ -58,6 +58,12 @@ It is used in conjunction with `WithUsername` to set a username and its password | |||
|
|||
E.g. `testcontainers.WithPassword("mymongopwd")`. | |||
|
|||
#### WithReplicaSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@heiytor I went ahead and added the docs for the new option: https://deploy-preview-2469--testcontainers-go.netlify.app/modules/mongodb/#withreplicaset
Once the CI passes, I'll merge this one, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
* main: (48 commits) Fix race condition when looking up reaper (ryuk) container (testcontainers#2508) chore: bring golangci-lint back (testcontainers#2571) docs(compose): Fix typo docker compose docs (testcontainers#2565) Handle error properly during port forwarding initialization. (testcontainers#2550) chore: pin vearch version (testcontainers#2568) feat: add vearch module (testcontainers#2560) chore: run tests against latest Docker engine, nightly (testcontainers#2566) chore(deps): bump mkdocs-include-markdown-plugin from 6.0.4 to 6.0.7 (testcontainers#2562) Fix network accessor for port-forwarding feature (testcontainers#2551) --- (testcontainers#2549) fix: update search bar eval in mkdocs (testcontainers#2547) docs: improve contributing docs for code snippets (testcontainers#2546) chore: use a virtualenv for working with the docs site (testcontainers#2545) docs: document test session semantics (testcontainers#2544) feat(ryuk): allow to configure ryuk timeouts using env variables (testcontainers#2541) docs: fix CircleCI docs (testcontainers#2539) fix: add import to module generation (testcontainers#2537) chore: prepare for next minor development cycle (0.32.0) chore: use new version (v0.31.0) in modules and examples feat(mongodb): add replica set support via opts (testcontainers#2469) ...
What does this PR do?
Implementing a
WithReplicaSet
function to configure the container to run with a default single-node replica set named "rs". This function appends "--replSet rs" toreq.Cmd
to initialize MongoDB in preparation to receive a replica set. Additionally, after execution, it initializes the replica set using "rs.initiate()", configuring the current host as the PRIMARY.Why is it important?
I've been utilizing testcontainers to test my service environment, which necessitates a replica set to execute transactions. As I've developed this functionality for internal use, I believe it would be beneficial to others as well.
Related issues
This PR closes #2138. Additionally, I noticed that there is another PR, #2139, which also aims to implement this feature. However, it has not been updated for a while, and this branch has certain differences, such as utilizing both
mongosh
andmongo
to ensure version compatibility.How to test this PR
I've tested this in a production environment, so it should work fine. Additionally, I've added new test cases to
TestMongoDB
.Follow-ups
Maybe adding a sharding option would be great.