Skip to content

Conversation

@mdelapenya
Copy link
Member

  • chore(azurite): use Run function
  • chore(eventhubs): use Run function
  • fix: do not fail the termination if the container is nil
  • chore(servicebus): use Run function

What does this PR do?

Use Run function in the Azure modules

Why is it important?

Migrate modules to the new API

Related issues

We have hit the classic “typed-nil inside an interface” pitfall:
in eventhubs (and probably other modules) "c.Container != nil" is true
because the interface is non-nil, but it holds a nil *DockerContainer.
Calling its method dereferences a nil receiver and panics inside the Terminate method.
@mdelapenya mdelapenya requested a review from a team as a code owner September 29, 2025 11:23
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Sep 29, 2025
@mdelapenya mdelapenya self-assigned this Sep 29, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 29, 2025

Summary by CodeRabbit

  • New Features
    • Enforced EULA validation for Azure Event Hubs and Service Bus containers.
  • Bug Fixes
    • Prevented potential crashes by making container termination nil-safe.
  • Refactor
    • Simplified and modularized container setup for Azurite, Event Hubs, and Service Bus using option-based configuration.
    • Standardized environment handling, wait strategies, networking, and error messages across Azure modules.
    • Streamlined in-memory persistence option construction without changing behavior.
  • Tests
    • Ensured containers are always cleaned up in tests, even on failures.
  • Documentation
    • Clarified comments and aligned terminology for consistency.

Walkthrough

Refactors Azure modules to use testcontainers.Run with option-based configuration, adds EULA validation as a request customizer, updates tests to cleanup containers earlier, and introduces a nil-receiver guard in DockerContainer.Terminate. Azurite, EventHubs, and ServiceBus flows now compose With* options for ports, env, wait strategies, networking, and commands.

Changes

Cohort / File(s) Summary of changes
Docker termination guard
docker.go
Add early return if receiver is nil in Terminate to avoid panic; rest of termination flow unchanged.
Azurite option-based run
modules/azure/azurite/azurite.go, modules/azure/azurite/options.go
Replace GenericContainer with testcontainers.Run and composed options (entrypoint, ports, cmd, wait strategies). Rework WithInMemoryPersistence to return static WithCmdArgs without mutating request. Adjust error messages.
EventHubs refactor + EULA validation
modules/azure/eventhubs/eventhubs.go, modules/azure/eventhubs/options.go, modules/azure/eventhubs/eventhubs_test.go
Migrate to moduleOpts with WithExposedPorts/WithWaitStrategy/WithEnv; run via testcontainers.Run. Introduce validateEula option and switch WithAcceptEULA to use WithEnv. Update error strings and test to always cleanup container.
ServiceBus refactor + EULA validation
modules/azure/servicebus/servicebus.go, modules/azure/servicebus/options.go, modules/azure/servicebus/servicebus_test.go
Adopt option-based Run flow including ports, env, wait strategy, and network wiring to MSSQL via options. Defer EULA checks via validateEula option. Update tests to cleanup container pre-assert.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer Code
  participant Mod as Module.Run (EventHubs/ServiceBus)
  participant Opts as Module Options (With*, validateEula)
  participant TC as testcontainers.Run
  participant Eng as Docker Engine

  Dev->>Mod: Run(ctx, img, userOpts...)
  Mod->>Opts: Build moduleOpts (WithExposedPorts/WithEnv/WithCmd/WithWaitStrategy/WithNetwork)
  Mod->>Opts: Append validateEula
  Mod->>TC: Run(ctx, img, moduleOpts...)
  TC->>TC: Apply options in order
  TC->>TC: validateEula checks ACCEPT_EULA
  alt EULA not accepted
    TC-->>Mod: error ("EULA not accepted")
    Mod-->>Dev: error
  else EULA accepted
    TC->>Eng: Create & start container
    Eng-->>TC: container handle
    TC-->>Mod: container
    Mod-->>Dev: container
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • stevenh

Poem

A whisk of flags, a hop of opts,
I stitch the ports and wait for props.
EULA checked—Y means go!
Azurite hums, the buses flow.
With tidy cleanup, off I run—
Containers launched, refactors done. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title Check ⚠️ Warning The title “chore(azurite): use Run function” only describes the azurite migration and omits the analogous changes to eventhubs and servicebus as well as the nil-guard fix in docker.go, so it does not accurately summarize the primary scope of this pull request. Rename the title to reflect all coordinated changes, for example “chore(azure): migrate modules to Run function and add nil container guard,” so that it clearly conveys the multi-module Run migration and the docker termination fix.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed The description enumerates each module migration to the Run function and the nil-guard fix and explains both the what (“Uses Run function in the Azure modules”) and the why (“Migrates modules to the new API”), directly matching the actual changes in the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 943eeb2 and 57cb271.

📒 Files selected for processing (9)
  • docker.go (1 hunks)
  • modules/azure/azurite/azurite.go (1 hunks)
  • modules/azure/azurite/options.go (1 hunks)
  • modules/azure/eventhubs/eventhubs.go (2 hunks)
  • modules/azure/eventhubs/eventhubs_test.go (1 hunks)
  • modules/azure/eventhubs/options.go (4 hunks)
  • modules/azure/servicebus/options.go (2 hunks)
  • modules/azure/servicebus/servicebus.go (2 hunks)
  • modules/azure/servicebus/servicebus_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (8)
modules/azure/eventhubs/eventhubs.go (8)
options.go (3)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (464-469)
  • WithWaitStrategy (376-378)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/http.go (1)
  • ForHTTP (149-151)
modules/azure/servicebus/options.go (1)
  • Option (30-30)
modules/azure/eventhubs/options.go (1)
  • Option (30-30)
modules/azure/servicebus/servicebus.go (2)
  • Container (36-39)
  • Run (75-143)
modules/azure/azurite/azurite.go (2)
  • Container (31-34)
  • Run (74-119)
modules/azure/servicebus/options.go (2)
options.go (1)
  • CustomizeRequestOption (28-28)
generic.go (1)
  • GenericContainerRequest (21-27)
modules/azure/azurite/options.go (1)
options.go (1)
  • WithCmdArgs (480-485)
modules/azure/servicebus/servicebus.go (3)
modules/azure/eventhubs/eventhubs.go (2)
  • Run (70-133)
  • Container (31-34)
modules/azure/azurite/azurite.go (2)
  • Run (74-119)
  • Container (31-34)
modules/mssql/mssql.go (1)
  • Run (114-153)
modules/azure/eventhubs/options.go (2)
options.go (1)
  • CustomizeRequestOption (28-28)
generic.go (1)
  • GenericContainerRequest (21-27)
modules/azure/servicebus/servicebus_test.go (1)
testing.go (1)
  • CleanupContainer (91-97)
modules/azure/azurite/azurite.go (4)
options.go (5)
  • ContainerCustomizer (22-24)
  • WithEntrypoint (448-453)
  • WithExposedPorts (464-469)
  • WithCmd (472-477)
  • WithWaitStrategy (376-378)
wait/all.go (1)
  • ForAll (44-48)
modules/azure/servicebus/servicebus.go (2)
  • Run (75-143)
  • Container (36-39)
modules/azure/eventhubs/eventhubs.go (2)
  • Run (70-133)
  • Container (31-34)
modules/azure/eventhubs/eventhubs_test.go (1)
testing.go (1)
  • CleanupContainer (91-97)
⏰ 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). (11)
  • GitHub Check: lint (modules/socat) / lint: modules/socat
  • GitHub Check: lint (modules/milvus) / lint: modules/milvus
  • GitHub Check: lint (modules/k3s) / lint: modules/k3s
  • GitHub Check: lint (modules/minio) / lint: modules/minio
  • GitHub Check: lint (modules/postgres) / lint: modules/postgres
  • GitHub Check: lint (modules/artemis) / lint: modules/artemis
  • GitHub Check: lint (modules/couchbase) / lint: modules/couchbase
  • GitHub Check: lint (modules/pulsar) / lint: modules/pulsar
  • GitHub Check: lint (modules/influxdb) / lint: modules/influxdb
  • GitHub Check: lint (modules/nats) / lint: modules/nats
  • GitHub Check: Analyze (go)

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

@netlify
Copy link

netlify bot commented Sep 29, 2025

Deploy Preview for testcontainers-go ready!

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

// Default: timeout is 10 seconds.
func (c *DockerContainer) Terminate(ctx context.Context, opts ...TerminateOption) error {
if c == nil {
return nil
Copy link
Member Author

Choose a reason for hiding this comment

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

I added this nil-guard after finding that we have hit the classic “typed-nil inside an interface” pitfall: in eventhubs (and probably other modules) c.Container != nil is true because the interface is non-nil, but it holds a nil *DockerContainer. Calling its method dereferences a nil receiver and panics inside the Terminate method.

@mdelapenya mdelapenya requested a review from Copilot September 29, 2025 12:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Migrates Azure modules (Azurite, EventHubs, and ServiceBus) from the legacy GenericContainer API to the new Run function API and adds a nil check to prevent failures during container termination.

  • Refactors module initialization code to use testcontainers.Run instead of testcontainers.GenericContainer
  • Simplifies option handling by using new testcontainers helper functions
  • Adds nil safety check in DockerContainer.Terminate method

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
modules/azure/servicebus/servicebus.go Migrates ServiceBus module to use Run function with modular options approach
modules/azure/servicebus/options.go Adds validateEula function and updates imports
modules/azure/servicebus/servicebus_test.go Updates test to use CleanupContainer instead of asserting nil container
modules/azure/eventhubs/eventhubs.go Migrates EventHubs module to use Run function with modular options approach
modules/azure/eventhubs/options.go Adds validateEula function and simplifies WithAcceptEULA using testcontainers.WithEnv
modules/azure/eventhubs/eventhubs_test.go Updates test to use CleanupContainer instead of asserting nil container
modules/azure/azurite/azurite.go Migrates Azurite module to use Run function with modular options approach
modules/azure/azurite/options.go Simplifies WithInMemoryPersistence using testcontainers.WithCmdArgs
docker.go Adds nil check to prevent termination failures when container is nil
Comments suppressed due to low confidence (1)

modules/azure/azurite/azurite.go:1

  • [nitpick] The cmd slice is declared outside the return statement but could be constructed inline. Consider moving the slice construction inside the return statement or declaring it where it's used to improve readability.
package azurite

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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