feat(azure): reduce time/memory by running specific sub-services by NathanBaulch ยท Pull Request #3451 ยท testcontainers/testcontainers-go

Summary by CodeRabbit

Release Notes

  • New Features

    • Added WithEnabledServices option to Azurite for selective Azure Storage service configuration (Blob, Queue, Table)
    • Added examples demonstrating service-specific configurations
  • Documentation

    • Updated Azurite documentation with WithEnabledServices usage details

Summary by CodeRabbit

  • New Features

    • Added WithEnabledServices option to selectively enable specific Azure Storage services (Blob, Queue, Table), reducing resource consumption and exposed ports.
  • Documentation

    • Updated documentation for Azurite container configuration options.

Walkthrough

Run accepts Azurite-specific Options, validates enabled services, builds per-service entrypoint/flags, aggregates exposed ports and wait strategies, and starts the container via testcontainers.Run. Service-to-port resolution was centralized in servicePort; ServiceURL now uses it and per-service URL helpers delegate to ServiceURL.

Changes

Cohort / File(s) Change summary
Core runtime
modules/azure/azurite/azurite.go
Added servicePort(Service) (nat.Port, error); updated ServiceURL to use it and return via PortEndpoint; removed internal serviceURL helper; refactored Run() to apply Options, compute per-service entrypoint/CLI flags, aggregate WithCmd, WithExposedPorts, and WithWaitStrategy, then call testcontainers.Run.
Options API
modules/azure/azurite/options.go
Introduced exported Option type (func(*options) error) with Customize to satisfy testcontainers.ContainerCustomizer; added WithEnabledServices(...) with validation, duplicate check, and defaulting to Blob/Queue/Table; changed options.EnabledServices to []Service.
Service types
modules/azure/azurite/services.go
Simplified to type Service string; exported BlobService, QueueService, TableService as Service constants; removed old alias types and internal constants.
Tests & examples
modules/azure/azurite/azurite_test.go, modules/azure/azurite/examples_test.go
Added TestAzurite_enabledServices to verify enabling/disabling services and ServiceURL behavior; examples updated to call WithEnabledServices(...) for specific services.
Docs / compile assertions
modules/azure/eventhubs/options.go, modules/azure/servicebus/options.go, docs/modules/azure.md
Updated comments and compile-time assertions to reference testcontainers.ContainerCustomizer; docs add WithEnabledServices subsection describing selective service enabling.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Dev as Caller
    participant Run as azurite.Run
    participant Opts as Option funcs
    participant Builder as module opts builder
    participant TC as testcontainers.Run
    participant Container as started container

    Dev->>Run: Call Run(opts...)
    Run->>Opts: Iterate & apply Option funcs (Customize)
    Note right of Run #bfe1d6: validate enabled services\n(default blob,queue,table)
    Run->>Builder: Build entrypoint/cmd, per-service flags, exposed ports, wait strategies
    Builder-->>Run: module customizers (WithCmd, WithExposedPorts, WithWaitStrategy)
    Run->>TC: Call testcontainers.Run(module customizers + remaining opts)
    TC-->>Container: Return running container or error
    Run->>Dev: Return container or wrapped error
Loading

Estimated code review effort

๐ŸŽฏ 3 (Moderate) | โฑ๏ธ ~25 minutes

Possibly related PRs

Suggested labels

feature

Suggested reviewers

  • mdelapenya

Poem

"I hopped into code with a twitchy nose,
Turned knobs for services that Azurite knows.
Ports aligned and commands in queue,
Containers wake โ€” a bright debut.
Hop, test, and run โ€” a rabbit's bravo ๐Ÿ‡"

Pre-merge checks and finishing touches

โŒ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 0.00% 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 PR title "feat(azure): reduce time/memory by running specific sub-services" directly and clearly summarizes the main objective of the changeset. The primary change is the introduction of the WithEnabledServices option that allows consumers to select which Azure Storage services (blob, queue, table) to run, rather than always running all three. This enables reduced startup time and memory usage when only specific services are needed. The title is concise, specific, and accurately captures this core improvement without extraneous details.
Description Check โœ… Passed The PR description is well-related to the changeset and provides meaningful context. It clearly explains what the PR does (exposing service selection via the options pattern), how it works (using specific entrypoints like azurite-blob or azurite-queue for individual services), and why it matters (faster startup, lower memory, fewer exposed ports). The description includes concrete details such as the 30% startup improvement observed by the author and acknowledges the limitation with azurite-table. The content aligns well with the actual code changes across multiple files, including the new WithEnabledServices option, refactored service URL methods, and updated documentation.
โœจ Finishing touches
  • ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • 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 c67652c and 2d6e5fb.

๐Ÿ“’ Files selected for processing (2)
  • docs/modules/azure.md (1 hunks)
  • modules/azure/azurite/azurite_test.go (1 hunks)
๐Ÿšง Files skipped from review as they are similar to previous changes (2)
  • modules/azure/azurite/azurite_test.go
  • docs/modules/azure.md
โฐ 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.25.x, modules/azure) / test: modules/azure/1.25.x
  • GitHub Check: test (1.24.x, modules/azure) / test: modules/azure/1.24.x
  • GitHub Check: Analyze (go)

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.