Skip to content

Conversation

@mdelapenya
Copy link
Member

What does this PR do?

Use the Run function in rabbitmq

Why is it important?

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

Related issues

🤖 Generated with Claude Code

🤖 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 8, 2025 06:00
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Oct 8, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 8, 2025

Summary by CodeRabbit

  • New Features
    • Options now return errors to surface configuration issues.
    • Improved SSL configuration handling and startup logic.
  • Refactor
    • Unified container setup via modular configuration pipeline.
    • Clearer error message when starting RabbitMQ.
  • Tests
    • Added test validating custom admin credentials and AMQP connectivity.

Walkthrough

Reworks RabbitMQ module Run to assemble container customizers (moduleOpts) and call testcontainers.Run; moves env, ports, files, wait strategies, and SSL handling into testcontainers.With* customizers; changes Option builders to return errors; adds a test for custom credentials. No exported symbols removed.

Changes

Cohort / File(s) Summary of changes
RabbitMQ runtime refactor
modules/rabbitmq/rabbitmq.go
Replaces GenericContainerRequest usage with a moduleOpts slice of testcontainers.ContainerCustomizer and calls testcontainers.Run(ctx, img, moduleOpts...); migrates env, exposed ports, and wait strategy setup to WithEnv, WithExposedPorts, WithWaitStrategy; integrates withConfig and applySSLSettings into the customizer pipeline; updates startup error text to “run rabbitmq”.
Options signature change
modules/rabbitmq/options.go
Changes public Option type to return error; updates option constructors (WithAdminPassword, WithAdminUsername, WithSSL, etc.) to func(*options) error and return nil on success.
Tests
modules/rabbitmq/rabbitmq_test.go
Adds TestRunContainer_withCustomCredentials verifying custom admin username/password, AMQP URL formation, and connection using those credentials.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant RabbitMQ as modules/rabbitmq.Run
  participant Config as withConfig
  participant SSL as applySSLSettings
  participant TC as testcontainers.Run

  Caller->>RabbitMQ: Run(ctx, req)
  RabbitMQ->>RabbitMQ: build moduleOpts (WithEnv, WithExposedPorts, WithWaitStrategy)
  alt req.Config present
    RabbitMQ->>Config: withConfig(req.Config)
    Config-->>RabbitMQ: append WithEnv/WithFiles or return error
  end
  alt req.SSLSettings present
    RabbitMQ->>SSL: applySSLSettings(req.SSLSettings)
    SSL-->>RabbitMQ: append WithFiles + WithAdditionalWaitStrategy
  end
  RabbitMQ->>TC: Run(ctx, image, moduleOpts...)
  TC-->>RabbitMQ: container handle or error ("run rabbitmq")
  RabbitMQ-->>Caller: return container or error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

breaking change

Suggested reviewers

  • stevenh

Poem

"A rabbit packs the container hops,
env and files in tidy crops.
WithEnv, WithFiles, waits aligned,
credentials snug, the queues combined.
I wink — RabbitMQ starts on time." 🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly identifies the primary change of migrating the RabbitMQ module to use the Run function and follows a concise, conventional commit style that communicates the intent without unnecessary detail.
Description Check ✅ Passed The description succinctly explains what the PR does, why the change is important, and links to the related issue, making it clearly relevant to the changeset.
✨ 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.

@netlify
Copy link

netlify bot commented Oct 8, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit dba32b6
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68e62fffa0bfc20008a103ab
😎 Deploy Preview https://deploy-preview-3428--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.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d901d9 and ef27fed.

📒 Files selected for processing (1)
  • modules/rabbitmq/rabbitmq.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
modules/rabbitmq/rabbitmq.go (3)
options.go (7)
  • ContainerCustomizer (22-24)
  • WithEnv (75-85)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • CustomizeRequestOption (28-28)
  • WithFiles (524-529)
  • WithAdditionalWaitStrategy (371-373)
container.go (2)
  • Container (41-73)
  • ContainerFile (110-115)
generic.go (1)
  • GenericContainerRequest (21-27)
⏰ 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/rabbitmq) / test: modules/rabbitmq/1.24.x
  • GitHub Check: test (1.25.x, modules/rabbitmq) / test: modules/rabbitmq/1.25.x
  • GitHub Check: Analyze (go)

- Use settings.AdminUsername and settings.AdminPassword instead of hardcoded defaults
- Change Option type to return error for proper error handling
- Update for-loop to check and return errors when applying options
- Fixes credential handling bug identified in code review

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

Co-Authored-By: Claude <[email protected]>
@mdelapenya mdelapenya changed the title chore(rabbitmq): use Run function chore(rabbitmq)!: use Run function Oct 8, 2025
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: 0

♻️ Duplicate comments (1)
modules/rabbitmq/rabbitmq.go (1)

104-117: Credential fix confirmed and implementation looks solid.

Lines 106-107 correctly use settings.AdminUsername and settings.AdminPassword instead of hardcoded defaults, resolving the bug flagged in previous reviews. The moduleOpts construction properly configures environment variables, exposed ports, wait strategy, and config.

🧹 Nitpick comments (1)
modules/rabbitmq/options.go (1)

44-44: Option signature change improves flexibility.

Changing Option to return an error aligns with similar modules (opensearch, gcloud, elasticsearch) and enables future input validation. The current implementations correctly return nil after applying settings.

Consider adding validation in future iterations. For example:

 func WithAdminUsername(username string) Option {
 	return func(o *options) error {
+		if username == "" {
+			return errors.New("admin username cannot be empty")
+		}
 		o.AdminUsername = username
 		return nil
 	}
 }

Also applies to: 54-56, 62-64, 70-72

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef27fed and dba32b6.

📒 Files selected for processing (3)
  • modules/rabbitmq/options.go (2 hunks)
  • modules/rabbitmq/rabbitmq.go (3 hunks)
  • modules/rabbitmq/rabbitmq_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
modules/rabbitmq/rabbitmq_test.go (3)
modules/rabbitmq/rabbitmq.go (1)
  • Run (82-140)
modules/rabbitmq/options.go (2)
  • WithAdminUsername (61-66)
  • WithAdminPassword (53-58)
testing.go (1)
  • CleanupContainer (91-97)
modules/rabbitmq/options.go (5)
modules/opensearch/options.go (1)
  • Option (22-22)
modules/gcloud/gcloud.go (1)
  • Option (65-65)
modules/elasticsearch/options.go (1)
  • Option (27-27)
modules/redpanda/options.go (1)
  • Option (87-87)
modules/couchbase/options.go (1)
  • Option (7-7)
modules/rabbitmq/rabbitmq.go (3)
options.go (7)
  • ContainerCustomizer (22-24)
  • WithEnv (75-85)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • CustomizeRequestOption (28-28)
  • WithFiles (524-529)
  • WithAdditionalWaitStrategy (371-373)
container.go (2)
  • Container (41-73)
  • ContainerFile (110-115)
generic.go (1)
  • GenericContainerRequest (21-27)
⏰ 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/rabbitmq) / test: modules/rabbitmq/1.24.x
  • GitHub Check: test (1.25.x, modules/rabbitmq) / test: modules/rabbitmq/1.25.x
  • GitHub Check: Analyze (go)
🔇 Additional comments (6)
modules/rabbitmq/rabbitmq_test.go (1)

262-290: LGTM! Test validates the custom credentials fix.

The test properly verifies that custom admin credentials work end-to-end:

  • Container fields reflect the custom credentials
  • AMQP URL includes the credentials
  • Actual connection succeeds using those credentials

This addresses the issue flagged in previous reviews where credentials were hardcoded.

modules/rabbitmq/rabbitmq.go (5)

87-89: LGTM! Proper error handling for option application.

The error check correctly propagates failures from option functions that now return errors.


119-123: LGTM! Clean conditional SSL handling and option merging.

SSL settings are conditionally appended when present, and user-provided options are merged last, allowing proper override behavior.


125-139: LGTM! Proper container lifecycle and error handling.

The code correctly:

  • Calls testcontainers.Run with the constructed options
  • Creates the RabbitMQContainer wrapper only when ctr is non-nil
  • Returns the container even on error (enabling cleanup)
  • Wraps errors with meaningful context

142-154: LGTM! Proper error propagation in config setup.

The function correctly chains WithEnv and WithFiles, returning early on error and propagating the final result.


157-189: LGTM! Batched file mounts and proper wait strategy.

The SSL settings function efficiently batches all three certificate files in a single WithFiles call and adds the TLS listener wait strategy. Error handling is proper throughout.

@mdelapenya mdelapenya added breaking change Causing compatibility issues. and removed chore Changes that do not impact the existing functionality labels Oct 8, 2025
@mdelapenya mdelapenya merged commit da9df18 into testcontainers:main Oct 8, 2025
18 checks passed
@mdelapenya mdelapenya deleted the use-run-claude-rabbitmq branch October 8, 2025 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Causing compatibility issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant