chore(couchbase|etcd|firestore|mcpgateway|eventhubs|servicebus): apply consistent pattern for options by mdelapenya · Pull Request #3447 · testcontainers/testcontainers-go
Summary by CodeRabbit
- New Features
- More consistent option handling across Azure Event Hubs, Service Bus, Couchbase, etcd, Firestore, and Docker MCP Gateway modules, leading to clearer errors and smoother container startup.
- Bug Fixes
- Corrected Couchbase admin password validation message to require “at least 6 characters,” improving guidance during setup.
- Refactor
- Reordered initialization to apply user options earlier in the startup sequence across multiple modules, improving reliability and surfacing misconfigurations sooner without changing external APIs.
Walkthrough
Refactors multiple module Run functions to apply options/settings before constructing default module options, then append user customizations and invoke Run. Adjusts control flow in Azure Event Hubs/Service Bus, Couchbase, Docker MCP Gateway, etcd, and GCloud Firestore without altering public APIs.
Changes
| Cohort / File(s) | Summary |
|---|---|
Azure modules (option-first Run flow)modules/azure/eventhubs/eventhubs.go, modules/azure/servicebus/servicebus.go |
Move option application earlier: build defaultOptions and apply Option(s) first, then initialize moduleOpts (exposed ports, wait, health) and append user opts; preserves EULA, env, network, and container startup logic. |
etcd (cluster-aware option processing)modules/etcd/etcd.go |
Apply ContainerCustomizer options early, prepare cluster-related options via configureCluster, then construct moduleOpts with defaults and lifecycle hooks; return early on option errors. |
GCloud Firestore (two-phase assembly)modules/gcloud/firestore/firestore.go |
Extract emulator settings first into a settings object, then assemble moduleOpts (port, wait, WithCmd), and append user opts; retains explicit command composition and host binding. |
Couchbase (unified customizers pipeline)modules/couchbase/couchbase.go |
Consolidate default service customizers and user opts into allCustomizers, iterate once to populate runtime config and moduleOpts; fix admin password validation message. |
Docker MCP Gateway (settings-first, then defaults)modules/dockermcpgateway/dockermcpgateway.go |
Process options to derive settings before building default moduleOpts (ports, docker.sock bind, wait), then append user opts; keep secrets and command assembly unchanged. |
Sequence Diagram(s)
sequenceDiagram
autonumber
actor Caller
participant RunFn as Module.Run
participant Opts as Option(s)
participant Settings as Settings/Config
participant ModuleOpts as moduleOpts
participant Runtime as testcontainers.Run
Caller->>RunFn: Invoke Run(ctx, ..., opts...)
RunFn->>Opts: Apply each Option (mutate default settings)
alt Option error
Opts-->>RunFn: error
RunFn-->>Caller: return error
else Options ok
Opts-->>Settings: Populate settings
RunFn->>ModuleOpts: Build defaults (ports, wait, CMD)
RunFn->>ModuleOpts: Append user opts
RunFn->>Runtime: Run(ctx, image, ModuleOpts...)
Runtime-->>RunFn: Container / error
RunFn-->>Caller: Return result
end
sequenceDiagram
autonumber
actor Caller
participant RunETCD as etcd.Run
participant Opts as ContainerCustomizer(s)
participant Cluster as configureCluster
participant ModuleOpts as moduleOpts
participant Runtime as testcontainers.Run
Caller->>RunETCD: Run(ctx, nodes, opts...)
RunETCD->>Opts: Apply to settings
alt Option error
RunETCD-->>Caller: error
else
RunETCD->>Cluster: Prepare network + per-node opts
Cluster-->>RunETCD: cluster options
RunETCD->>ModuleOpts: Build defaults + hooks
RunETCD->>ModuleOpts: Append cluster opts + user opts
RunETCD->>Runtime: Run(...)
Runtime-->>RunETCD: Container(s)
RunETCD-->>Caller: Return
end
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
- chore(azurite): use Run function #3318: Refactors Azure Event Hubs and Service Bus modules to an option-first Run flow, closely matching the Azure changes in this PR.
- chore(etcd)!: use Run function #3409: Reworks etcd to consolidate option handling and Run invocation, overlapping with this PR’s etcd cluster preparation changes.
- chore(gcloud): use Run function #3411: Adjusts gcloud modules to extract settings first and build
moduleOptsafterward, directly related to the Firestore changes here.
Suggested reviewers
- stevenh
Poem
I tweaked my hops and ordered my options first,
Then built my nests of ports and waits well-versed.
From clouds to hubs, I line them in a row—
A tidy warren where containers grow.
Thump-thump! says the bunny, CI lights aglow. 🐇✨
Pre-merge checks and finishing touches
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title Check | ✅ Passed | The title clearly indicates the chore scope by listing the affected modules and concisely summarizes that a consistent options pattern is being applied across them. |
| Description Check | ✅ Passed | The description outlines the modules updated, states the intent to enforce consistency in module option definitions, and is directly related to the changes without drifting off-topic. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
modules/couchbase/couchbase.go(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- modules/couchbase/couchbase.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
- GitHub Check: test (1.24.x, modules/dockermcpgateway) / test: modules/dockermcpgateway/1.24.x
- GitHub Check: test (1.25.x, modules/gcloud) / test: modules/gcloud/1.25.x
- GitHub Check: test (1.24.x, modules/azure) / test: modules/azure/1.24.x
- GitHub Check: test (1.24.x, modules/couchbase) / test: modules/couchbase/1.24.x
- GitHub Check: test (1.25.x, modules/couchbase) / test: modules/couchbase/1.25.x
- GitHub Check: test (1.24.x, modules/gcloud) / test: modules/gcloud/1.24.x
- GitHub Check: test (1.24.x, modules/etcd) / test: modules/etcd/1.24.x
- GitHub Check: test (1.25.x, modules/azure) / test: modules/azure/1.25.x
- GitHub Check: Analyze (go)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.