chore(surrealdb): use Run function by mdelapenya · Pull Request #3434 · testcontainers/testcontainers-go
Summary by CodeRabbit
- Refactor
- Streamlined container startup using composable options for more predictable configuration.
- Unified environment variable handling to reduce setup side effects and improve reliability.
- Improved error messages when container startup fails to aid troubleshooting.
- Preserves existing public APIs; no changes required for current integrations.
Walkthrough
Refactors the SurrealDB module to build container configuration via composable testcontainers.With* options and run containers using testcontainers.Run. Replaces direct request/env mutations with WithEnv wrappers, updates Run to assemble options (ports, wait strategy, cmd), adjusts error messages, and returns a wrapped SurrealDBContainer.
Changes
| Cohort / File(s) | Summary |
|---|---|
SurrealDB module refactormodules/surrealdb/surrealdb.go |
Replace direct env/request mutations with testcontainers.WithEnv and other With* options; refactor Run to assemble moduleOpts and call testcontainers.Run; switch construction to wrap returned container; update error messages; keep public APIs unchanged while altering internal flow. |
Sequence Diagram(s)
sequenceDiagram
autonumber
actor Dev as Caller
participant Mod as SurrealDB (module)
participant TC as testcontainers.Run
participant DK as Docker Engine
participant C as SurrealDBContainer
Dev->>Mod: Run(ctx, opts...)
Mod->>Mod: Build moduleOpts (WithEnv/WithExposedPorts/WithWaitStrategy/WithCmd)
Mod->>TC: Run(ctx, image, moduleOpts...)
TC->>DK: Create & start container
DK-->>TC: Container started / error
alt success
TC-->>Mod: Container handle
Mod->>Mod: Wrap handle as SurrealDBContainer
Mod-->>Dev: SurrealDBContainer
else failure
TC-->>Mod: Error
Mod-->>Dev: return error ("run surrealdb: ...")
end
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
- chore(cockroachDB): use Run function #3326 — Similar migration to testcontainers.Run with a moduleOpts pipeline and ContainerCustomizer-based configuration.
- chore(rabbitmq)!: use Run function #3428 — Refactors another module to use WithEnv/WithExposedPorts/WithWaitStrategy and testcontainers.Run, mirroring this change.
- chore(pulsar): use Run function #3426 — Replaces GenericContainerRequest mutations with composable With* options and updates error handling, analogous to this PR.
Poem
I twitch my whiskers, flip and run,
New opts aligned, the work is done.
No more mutating fields by hand—
We stack our Withs, a tidy band.
Hop in a box, then back we come,
Surreal and swift—containers spun! 🐇🧪
Pre-merge checks and finishing touches
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title Check | ✅ Passed | The title clearly and concisely describes the main change of the pull request, namely switching the SurrealDB module to use the new Run function, and it follows the conventional commit style without extraneous details. |
| Description Check | ✅ Passed | The description clearly states what the PR does and why it’s important, and it references the related issue, making it directly relevant to the changes in the pull request. |
| 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
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.