Skip to content

Conversation

@mdelapenya
Copy link
Member

What does this PR do?

Use the Run function in surrealdb

Why is it important?

Migrate modules to the new API, improving consistency and leveraging the latest testcontainers functionality.

Related issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@mdelapenya mdelapenya requested a review from a team as a code owner October 9, 2025 10:22
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Oct 9, 2025
@netlify
Copy link

netlify bot commented Oct 9, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit d671137
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68e78ccb48f5ed00086a4203
😎 Deploy Preview https://deploy-preview-3434--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Oct 9, 2025

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 refactor
modules/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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
modules/surrealdb/surrealdb.go (1)

29-63: Consider simplifying WithXXX functions to avoid double indirection.

Each function creates a wrapper that immediately invokes testcontainers.WithEnv. Since WithEnv already returns a CustomizeRequestOption, the extra wrapper is redundant.

For example, WithUsername can be simplified to:

 func WithUsername(username string) testcontainers.CustomizeRequestOption {
-	return func(req *testcontainers.GenericContainerRequest) error {
-		return testcontainers.WithEnv(map[string]string{"SURREAL_USER": username})(req)
-	}
+	return testcontainers.WithEnv(map[string]string{"SURREAL_USER": username})
 }

Apply the same pattern to WithPassword, WithAuthentication, WithStrictMode, and WithAllowAllCaps.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d256b4b and d671137.

📒 Files selected for processing (1)
  • modules/surrealdb/surrealdb.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
modules/surrealdb/surrealdb.go (3)
options.go (6)
  • WithEnv (75-85)
  • CustomizeRequestOption (28-28)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmd (462-467)
generic.go (1)
  • GenericContainerRequest (21-27)
wait/log.go (1)
  • ForLog (118-120)
⏰ 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). (3)
  • GitHub Check: test (1.24.x, modules/surrealdb) / test: modules/surrealdb/1.24.x
  • GitHub Check: test (1.25.x, modules/surrealdb) / test: modules/surrealdb/1.25.x
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
modules/surrealdb/surrealdb.go (1)

72-98: LGTM! Well-structured refactoring to composable options.

The refactoring correctly implements the composable options pattern:

  • Default configuration built via moduleOpts slice
  • Uses standard testcontainers options (WithEnv, WithExposedPorts, WithWaitStrategy, WithCmd)
  • Properly combines module defaults with user-provided options
  • Error handling correctly wraps container even on error (enables cleanup)
  • Maintains backward compatibility with existing public API

@mdelapenya mdelapenya merged commit 791acab into testcontainers:main Oct 9, 2025
17 checks passed
@mdelapenya mdelapenya deleted the use-run-claude-surrealdb branch October 9, 2025 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Changes that do not impact the existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant