diff --git a/modules/mongodb/mongodb.go b/modules/mongodb/mongodb.go index ac29414825..8d6f5c98e4 100644 --- a/modules/mongodb/mongodb.go +++ b/modules/mongodb/mongodb.go @@ -81,9 +81,9 @@ func WithPassword(password string) testcontainers.CustomizeRequestOption { // WithReplicaSet configures the container to run a single-node MongoDB replica set named "rs". // It will wait until the replica set is ready. -func WithReplicaSet() testcontainers.CustomizeRequestOption { +func WithReplicaSet(replSetName string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) error { - req.Cmd = append(req.Cmd, "--replSet", "rs") + req.Cmd = append(req.Cmd, "--replSet", replSetName) req.LifecycleHooks = append(req.LifecycleHooks, testcontainers.ContainerLifecycleHooks{ PostStarts: []testcontainers.ContainerHook{ func(ctx context.Context, c testcontainers.Container) error { @@ -92,7 +92,7 @@ func WithReplicaSet() testcontainers.CustomizeRequestOption { return err } - cmd := eval("rs.initiate({ _id: 'rs', members: [ { _id: 0, host: '%s:27017' } ] })", ip) + cmd := eval("rs.initiate({ _id: '%s', members: [ { _id: 0, host: '%s:27017' } ] })", replSetName, ip) return wait.ForExec(cmd).WaitUntilReady(ctx, c) }, }, diff --git a/modules/mongodb/mongodb_test.go b/modules/mongodb/mongodb_test.go index 0012b97624..f55fb762ed 100644 --- a/modules/mongodb/mongodb_test.go +++ b/modules/mongodb/mongodb_test.go @@ -40,14 +40,14 @@ func TestMongoDB(t *testing.T) { name: "With Replica set and mongo:4", opts: []testcontainers.ContainerCustomizer{ testcontainers.WithImage("mongo:4"), - mongodb.WithReplicaSet(), + mongodb.WithReplicaSet("rs"), }, }, { name: "With Replica set and mongo:6", opts: []testcontainers.ContainerCustomizer{ testcontainers.WithImage("mongo:6"), - mongodb.WithReplicaSet(), + mongodb.WithReplicaSet("rs"), }, }, }