chore(gcloud): use Run function by mdelapenya · Pull Request #3411 · testcontainers/testcontainers-go

Warning

Rate limit exceeded

@mdelapenya has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 23 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2dd1124 and 15f5aa4.

📒 Files selected for processing (3)
  • modules/gcloud/bigquery/bigquery.go (2 hunks)
  • modules/gcloud/pubsub/pubsub.go (3 hunks)
  • modules/gcloud/spanner/spanner.go (3 hunks)

Summary by CodeRabbit

  • Refactor

    • Standardized emulator startup across BigQuery, Bigtable, Datastore, Firestore, Pub/Sub, and Spanner using a modular configuration approach.
    • Unified default ports, wait conditions, and command construction for more consistent, reliable startup.
    • Improved and clarified error messages during container run.
  • Tests

    • Updated tests to align with the new configuration approach and relaxed error assertions to check for message contents instead of exact matches.
  • Notes

    • No public API changes; behavior remains the same for end-users.

Walkthrough

Refactors all gcloud emulator modules to replace direct GenericContainerRequest/GenericContainer usage with a modular options pipeline built from testcontainers.ContainerCustomizer and testcontainers.Run. Introduces defaultPort constants per module, migrates command, files, and wait strategies into moduleOpts, updates newGCloudContainer and applyOptions signatures, and aligns tests with the new option types.

Changes

Cohort / File(s) Summary
Core API and option plumbing
modules/gcloud/gcloud.go, modules/gcloud/options.go
Switches container creation to Run(img, opts...), updates error messages, and changes applyOptions to accept/execute ContainerCustomizer funcs. Moves file/cmd mutations to WithFiles/WithCmdArgs wrappers with error propagation.
BigQuery module
modules/gcloud/bigquery.go, modules/gcloud/bigquery/bigquery.go, modules/gcloud/bigquery/bigquery_test.go
Replaces request struct with moduleOpts; ports/wait moved to WithExposedPorts/WithWaitStrategy; command args and files applied via WithCmdArgs/WithFiles; test adapts to ContainerCustomizer and ErrorContains for YAML-exists case.
Bigtable module
modules/gcloud/bigtable.go, modules/gcloud/bigtable/bigtable.go
Migrates to moduleOpts and Run; introduces defaultPort; composite wait (port+log); command provided via WithCmd; updates error text and PortEndpoint usage.
Datastore module
modules/gcloud/datastore.go, modules/gcloud/datastore/datastore.go
Introduces defaultPort/defaultPortNumber; migrates to moduleOpts and Run; updates command to use constants; adjusts error messages and port endpoint retrieval.
Firestore module
modules/gcloud/firestore.go, modules/gcloud/firestore/firestore.go
Moves to moduleOpts and Run; defines defaultPort constants; sets wait (port+log); injects emulator start command via WithCmd; updates error handling and endpoint lookup.
Pub/Sub module
modules/gcloud/pubsub.go, modules/gcloud/pubsub/pubsub.go
Refactors to moduleOpts + Run; adds defaultPort constants; consolidates wait strategy; starts emulator via WithCmd; updates errors and endpoint resolution.
Spanner module
modules/gcloud/spanner.go, modules/gcloud/spanner/spanner.go
Converts to moduleOpts and Run; adds defaultPort constants; updates wait strategy and endpoint usage; adjusts error text.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant M as Module.Run(...)
  participant AO as applyOptions(opts)
  participant TC as testcontainers.Run
  participant Ctr as Container

  Note over M: New flow (options-based)
  C->>M: Run(ctx, img, opts...)
  M->>M: Build moduleOpts (ports, wait, cmd, files)
  M->>AO: applyOptions(opts)
  AO-->>M: updated settings / moduleOpts
  M->>TC: Run(ctx, img, moduleOpts...)
  TC-->>M: Container
  M->>Ctr: Configure wrapper (endpoint, etc.)
  M-->>C: Return Container
Loading
sequenceDiagram
  autonumber
  participant C as Caller
  participant M as Module.Run(...)
  participant R as (old) GenericContainerRequest
  participant GC as (old) GenericContainer

  Note over M: Old flow (request-based)
  C->>M: Run(ctx, reqOpts...)
  M->>R: Build ContainerRequest (ports, wait, cmd, files)
  M->>R: opt.Customize(&req)
  M->>GC: GenericContainer(ctx, req)
  GC-->>M: Container
  M-->>C: Return Container
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • stevenh

Poem

I hop through ports, 8080 to 9050 bright,
Stitching options snug, from dusk to light.
No more requests heavy and spun—
Just customizers, and off we run!
Carrot-shaped logs say “running” true,
A whisker-twitch, and tests hop through. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly identifies the chore scope and the main change of migrating the gcloud module to use the Run function, matching the PR’s primary objective without extraneous detail.
Description Check ✅ Passed The description enumerates the updated constructors, summarizes the what and why of using Run across gcloud submodules, and directly relates to the changeset and its rationale.
Docstring Coverage ✅ Passed Docstring coverage is 94.12% which is sufficient. The required threshold is 80.00%.

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.