-
-
Notifications
You must be signed in to change notification settings - Fork 590
chore(inbucket|influxdb|mongodb|k3s): use Run function #3413
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
chore(inbucket|influxdb|mongodb|k3s): use Run function #3413
Conversation
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Summary by CodeRabbit
WalkthroughReplaces per-module ContainerRequest/GenericContainer construction with composed testcontainers.ContainerCustomizer options passed to testcontainers.Run for inbucket, influxdb, k3s, and mongodb; MongoDB additionally moves auth/replica-set setup to option-based customizers with post-run inspection and deferred initialization. (42 words) Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor U as Caller
participant M as Module (inbucket/influxdb/k3s)
participant TC as testcontainers.Run
participant C as Container
U->>M: Run(ctx, img, opts...)
M->>M: Build moduleOpts (WithExposedPorts/WithEnv/WithWaitStrategy + opts)
M->>TC: Run(ctx, img, moduleOpts...)
TC-->>C: Create & start container
C-->>M: Return container handle
M-->>U: Return wrapper
sequenceDiagram
autonumber
actor U as Caller
participant MM as MongoDB Module
participant TC as testcontainers.Run
participant C as Container
participant I as Inspect
U->>MM: Run(ctx, img, opts...)
MM->>MM: Compose moduleOpts (env/auth/entrypoint/replica-set customizers)
MM->>TC: Run(ctx, img, moduleOpts...)
TC-->>C: Container ready (wait strategies satisfied)
MM->>I: Inspect container for env/credentials/state
I-->>MM: Derived credentials/state
alt Replica set requested
MM->>C: Trigger deferred replica-set init (via option/lifecycle)
C-->>MM: Replica state updated
end
MM-->>U: Return MongoDB wrapper
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)modules/influxdb/influxdb.go (4)
🔇 Additional comments (11)
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 |
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
modules/influxdb/influxdb.go (2)
254-258: Don’t clobber existing wait strategies in WithInitDbWithInitDb overwrites req.WaitingFor, dropping any waits set earlier (including user-supplied ones). Compose with the existing strategy instead.
Apply:
- req.WaitingFor = wait.ForAll( - wait.ForLog("Server shutdown completed"), - waitForHTTPHealth(), - ) + req.WaitingFor = wait.ForAll( + req.WaitingFor, + wait.ForLog("Server shutdown completed"), + waitForHTTPHealth(), + )
72-91: Prevent potential nil map writes in env helper optionsHelpers (WithUsername/WithPassword/WithDatabase) assign to req.Env without ensuring it’s initialized. Guard req.Env to avoid panics if these are used without a preceding WithEnv.
Example fix:
return func(req *testcontainers.GenericContainerRequest) error { - req.Env["INFLUXDB_USER"] = username + if req.Env == nil { + req.Env = map[string]string{} + } + req.Env["INFLUXDB_USER"] = username return nil }Apply similarly to password and database helpers.
Also applies to: 79-84
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
modules/inbucket/inbucket.go(1 hunks)modules/influxdb/influxdb.go(1 hunks)modules/k3s/k3s.go(1 hunks)modules/mongodb/mongodb.go(5 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
modules/influxdb/influxdb.go (3)
options.go (4)
ContainerCustomizer(22-24)WithExposedPorts(454-459)WithEnv(75-85)WithWaitStrategy(366-368)modules/k3s/k3s.go (1)
Run(58-99)modules/inbucket/inbucket.go (1)
Run(38-60)
modules/inbucket/inbucket.go (3)
options.go (3)
ContainerCustomizer(22-24)WithExposedPorts(454-459)WithWaitStrategy(366-368)wait/host_port.go (1)
ForListeningPort(67-69)modules/k3s/k3s.go (1)
Run(58-99)
modules/mongodb/mongodb.go (3)
options.go (8)
WithExposedPorts(454-459)WithWaitStrategy(366-368)WithEnv(75-85)CustomizeRequestOption(28-28)WithFiles(524-529)WithEntrypoint(438-443)WithCmdArgs(470-475)WithAdditionalLifecycleHooks(497-502)container.go (2)
Container(41-73)ContainerFile(110-115)lifecycle.go (2)
ContainerLifecycleHooks(43-55)ContainerHook(38-38)
modules/k3s/k3s.go (3)
options.go (6)
ContainerCustomizer(22-24)WithExposedPorts(454-459)WithHostConfigModifier(88-94)WithCmd(462-467)WithEnv(75-85)WithWaitStrategy(366-368)modules/inbucket/inbucket.go (1)
Run(38-60)generic.go (1)
Run(122-149)
⏰ 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). (2)
- GitHub Check: lint (modules/k3s) / lint: modules/k3s
- GitHub Check: Analyze (go)
🔇 Additional comments (5)
modules/inbucket/inbucket.go (1)
39-50: Migration to Run() looks correctPorts and waits are set appropriately, and user options are appended after module defaults. Error wrapping is consistent.
Also applies to: 55-57
modules/influxdb/influxdb.go (1)
31-46: Run() migration LGTMOptions assembly, waits, and error context look good. Health check strategy matches v1.8 /health behavior.
Also applies to: 51-53
modules/k3s/k3s.go (1)
64-96: Run()-based initialization looks solidPrivileged host config, cmd/env, waits, and option composition are correct. Error context updated appropriately.
modules/mongodb/mongodb.go (2)
43-50: Run() migration and post‑run env refresh look goodOption composition, waits, and error contexts are consistent. Post‑run inspect to populate credentials/replicaSet is a nice touch.
Also applies to: 52-65
75-84: go.mod version OK for strings.CutPrefix
go.mod specifiesgo 1.24.0, which meets the ≥1.20 requirement forstrings.CutPrefix.
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
modules/influxdb/influxdb.go (1)
115-125: Simplify the error handling.The error check and return can be simplified by directly returning the result of
withV2.Apply this diff:
func WithV2(org, bucket string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) error { - err := withV2(req, org, bucket) - if err != nil { - return err - } - - return nil + return withV2(req, org, bucket) } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
modules/influxdb/influxdb.go(9 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
modules/influxdb/influxdb.go (1)
options.go (7)
ContainerCustomizer(22-24)WithExposedPorts(454-459)WithEnv(75-85)WithWaitStrategy(366-368)CustomizeRequestOption(28-28)WithFiles(524-529)WithAdditionalWaitStrategy(371-373)
⏰ 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). (6)
- GitHub Check: test (1.24.x, modules/inbucket) / test: modules/inbucket/1.24.x
- GitHub Check: test (1.24.x, modules/k3s) / test: modules/k3s/1.24.x
- GitHub Check: test (1.25.x, modules/k3s) / test: modules/k3s/1.25.x
- GitHub Check: test (1.24.x, modules/mongodb) / test: modules/mongodb/1.24.x
- GitHub Check: test (1.24.x, modules/influxdb) / test: modules/influxdb/1.24.x
- GitHub Check: Analyze (go)
🔇 Additional comments (3)
modules/influxdb/influxdb.go (3)
30-56: LGTM! Clean migration to the new Run API.The refactoring correctly:
- Builds a slice of default options (exposed ports, environment variables, wait strategy)
- Appends user-provided options to allow customization/override
- Delegates container creation to
testcontainers.Run- Maintains proper error handling with a descriptive error message
72-96: LGTM! Consistent refactoring of option functions.All four functions (
WithUsername,WithPassword,WithDatabase,WithConfigFile) correctly migrate to the new API by returningtestcontainers.WithEnv()ortestcontainers.WithFiles()instead of directly modifying the request. The refactoring is clean and preserves the original behavior.
98-113: LGTM! All V2 configuration options correctly refactored.All the V2-related option functions (
withV2,WithV2Auth,WithV2SecretsAuth,WithV2Retention,WithV2AdminToken,WithV2SecretsAdminToken,WithInitDb) have been correctly migrated to the new API:
- Input validation logic is preserved
- Conflict detection between mutually exclusive options (e.g., direct auth vs. file-based auth) works correctly since options are applied sequentially
- All functions now return
testcontainers.WithEnv()or compose multiple helpers (WithFiles,WithAdditionalWaitStrategy)- Error handling is consistent throughout
Also applies to: 135-160, 163-188, 191-201, 204-235, 241-256
What does this PR do?
Use the Run function in Inbucket, Influxdb, MongoDB and K3s modules
Why is it important?
Migrate modules to the new API
Related issues