Skip to content

Conversation

@mdelapenya
Copy link
Member

  • chore(gcloud): use Run in deprecated constructors
  • chore(bigquery): use Run function
  • chore(bigtable): use Run function
  • chore(datastore): use Run function
  • chore: extract ports to constants
  • chore(firestore): use Run function
  • chore(pubsub): use Run function
  • chore(spanner): use Run function

What does this PR do?

Use Run function in the GCloud module

Why is it important?

Migrate modules to the new API

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner October 3, 2025 05:40
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Oct 3, 2025
@mdelapenya mdelapenya self-assigned this Oct 3, 2025
@netlify
Copy link

netlify bot commented Oct 3, 2025

Deploy Preview for testcontainers-go ready!

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

@coderabbitai
Copy link

coderabbitai bot commented Oct 3, 2025

Summary by CodeRabbit

  • Refactor

    • Standardized emulator startup across BigQuery, Bigtable, Datastore, Firestore, Pub/Sub, and Spanner using a modular options approach.
    • Unified default ports and readiness checks for more reliable startup.
    • Streamlined command configuration and improved error messages for clearer diagnostics.
    • Consolidated option handling for consistent behavior across modules.
  • Tests

    • Relaxed error assertions to be content-based rather than exact matches.
    • Updated test helpers to align with the new options model.

Walkthrough

Refactors all gcloud emulator modules to build containers via accumulated ContainerCustomizer options and testcontainers.Run, replacing GenericContainerRequest usage. Introduces default port constants, unified wait strategies, option application via applyOptions(opts), and command/file argument wiring through WithCmd/WithCmdArgs/WithFiles. Updates error messages and port endpoint retrieval accordingly. One core signature change in newGCloudContainer and applyOptions.

Changes

Cohort / File(s) Summary
Core gcloud runtime
modules/gcloud/gcloud.go
Refactors newGCloudContainer to use Run(ctx, img, opts...). Changes applyOptions signature to accept only []ContainerCustomizer and wrap errors. Removes GenericContainerRequest construction.
BigQuery module
modules/gcloud/bigquery.go, modules/gcloud/bigquery/bigquery.go, modules/gcloud/bigquery/options.go
Migrates to moduleOpts with WithExposedPorts/WithWaitStrategy/WithCmdArgs/WithFiles; uses default port constants; switches to Run; updates error messages and PortEndpoint usage; accumulates CLI args and files via With* helpers.
Bigtable module
modules/gcloud/bigtable.go, modules/gcloud/bigtable/bigtable.go
Replaces GenericContainerRequest with moduleOpts; introduces default port constants; uses WithExposedPorts, composite wait, and WithCmd; switches to Run and updates PortEndpoint.
Datastore module
modules/gcloud/datastore.go, modules/gcloud/datastore/datastore.go
Moves to moduleOpts and Run; introduces defaultPortNumber/defaultPort; configures wait/exposed ports via constants; builds command via WithCmd; updates error messages and PortEndpoint.
Firestore module
modules/gcloud/firestore.go, modules/gcloud/firestore/firestore.go
Refactors to options-based Run flow; adds default port constants; applies composite wait; builds emulator command with WithCmd; updates error text and PortEndpoint.
Pub/Sub module
modules/gcloud/pubsub.go, modules/gcloud/pubsub/pubsub.go
Switches to moduleOpts + Run; adds defaultPort constants; uses WithExposedPorts/WithWaitStrategy/WithCmd; updates error messages and PortEndpoint; removes direct request customization.
Spanner module
modules/gcloud/spanner.go, modules/gcloud/spanner/spanner.go
Refactors to options-based Run; adds defaultPort constants; composite wait; updates error text and PortEndpoint; removes GenericContainerRequest path.
Tests (BigQuery)
modules/gcloud/bigquery/bigquery_test.go
Loosens error assertions to ErrorContains; updates helper to return ContainerCustomizer; switches to WithCmdArgs usage.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant T as Test/Caller
  participant M as Module Run(...)
  participant AO as applyOptions(opts)
  participant TC as testcontainers.Run
  participant C as Container
  participant H as Host

  T->>M: Run(ctx, img, opts...)
  M->>AO: Apply module options
  AO-->>M: settings (project, etc.)
  M->>M: Build moduleOpts (WithExposedPorts, WithWaitStrategy, WithCmd/Args, WithFiles)
  M->>TC: Run(ctx, img, moduleOpts...)
  TC-->>M: ctr
  M->>C: Wrap ctr, store settings/URI
  M->>C: PortEndpoint(defaultPort)
  C-->>M: host:port
  M-->>T: GCloudContainer (URI, port, cleanup)

  rect rgba(224,248,234,0.6)
    note over M,TC: New flow using ContainerCustomizer options
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • stevenh

Poem

I hop through ports—8080 to 9010—glee!
Stitching WithCmd and waits like clover tea.
Goodbye, old requests; hello, Run parade—
Options in a bundle, neatly laid.
Onward to emulators, carrots held high,
A rabbit refactor, nimble and spry. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly indicates a chore in the gcloud module to adopt the new Run function, which accurately reflects the broad refactoring performed across multiple submodules to migrate to the Run-based API.
Description Check ✅ Passed The description specifies the exact modules affected, explains that the Run function is being adopted across gcloud components, and includes the rationale of migrating to the new API, demonstrating clear relevance to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 94.12% which is sufficient. The required threshold is 80.00%.
✨ 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.

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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
modules/gcloud/spanner/spanner.go (1)

37-66: Restore emulator command and include user customizers.

The refactor drops two essential behaviors: we no longer pass the emulator start command, and we ignore caller-provided ContainerCustomizers. As written, the container boots with the image default entrypoint (so the emulator never starts) and any customization such as testcontainers.WithEnv or WithFiles is lost. Both are regressions from the previous implementation.

Please restore the command and ensure we append opts to moduleOpts before running the container. For example:

@@
 	}
 
+	moduleOpts = append(moduleOpts, testcontainers.WithCmd(
+		"/bin/sh",
+		"-c",
+		"gcloud beta emulators spanner start --host-port 0.0.0.0:"+defaultPortNumber+" --project="+settings.ProjectID,
+	))
+
+	moduleOpts = append(moduleOpts, opts...)
+
 	ctr, err := testcontainers.Run(ctx, img, moduleOpts...)

This keeps the emulator behavior intact and preserves user overrides.

modules/gcloud/pubsub/pubsub.go (1)

37-67: Preserve caller-supplied container options.

We no longer append opts to moduleOpts before calling testcontainers.Run. Any caller-provided ContainerCustomizer (env vars, bind mounts, providers, etc.) is now ignored, which is a regression from the previous behavior and breaks consumers depending on those overrides.

Please append opts back before invoking Run, e.g.:

@@
 	moduleOpts = append(moduleOpts, testcontainers.WithCmd(
 		"/bin/sh",
 		"-c",
 		"gcloud beta emulators pubsub start --host-port 0.0.0.0:"+defaultPortNumber+" --project="+settings.ProjectID,
 	))
 
+	moduleOpts = append(moduleOpts, opts...)
+
 	ctr, err := testcontainers.Run(ctx, img, moduleOpts...)

This ensures existing customizations continue to work.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46d68aa and 2dd1124.

📒 Files selected for processing (15)
  • modules/gcloud/bigquery.go (1 hunks)
  • modules/gcloud/bigquery/bigquery.go (2 hunks)
  • modules/gcloud/bigquery/bigquery_test.go (1 hunks)
  • modules/gcloud/bigquery/options.go (1 hunks)
  • modules/gcloud/bigtable.go (1 hunks)
  • modules/gcloud/bigtable/bigtable.go (3 hunks)
  • modules/gcloud/datastore.go (1 hunks)
  • modules/gcloud/datastore/datastore.go (3 hunks)
  • modules/gcloud/firestore.go (1 hunks)
  • modules/gcloud/firestore/firestore.go (3 hunks)
  • modules/gcloud/gcloud.go (2 hunks)
  • modules/gcloud/pubsub.go (1 hunks)
  • modules/gcloud/pubsub/pubsub.go (3 hunks)
  • modules/gcloud/spanner.go (1 hunks)
  • modules/gcloud/spanner/spanner.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (15)
modules/gcloud/pubsub.go (4)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmd (462-467)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/log.go (1)
  • ForLog (118-120)
modules/gcloud/bigquery/options.go (2)
options.go (2)
  • WithCmdArgs (470-475)
  • WithFiles (524-529)
container.go (1)
  • ContainerFile (110-115)
modules/gcloud/pubsub/pubsub.go (7)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmd (462-467)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/log.go (1)
  • ForLog (118-120)
modules/gcloud/spanner/spanner.go (2)
  • Run (36-71)
  • Container (19-22)
modules/gcloud/firestore/firestore.go (2)
  • Run (36-84)
  • Container (19-22)
modules/gcloud/datastore/datastore.go (2)
  • Run (36-79)
  • Container (19-22)
modules/gcloud/bigquery.go (3)
options.go (5)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmdArgs (470-475)
  • WithFiles (524-529)
wait/http.go (1)
  • ForHTTP (149-151)
container.go (1)
  • ContainerFile (110-115)
modules/gcloud/gcloud.go (2)
options.go (1)
  • ContainerCustomizer (22-24)
modules/gcloud/spanner/spanner.go (2)
  • Run (36-71)
  • Container (19-22)
modules/gcloud/firestore/firestore.go (6)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmd (462-467)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/log.go (1)
  • ForLog (118-120)
modules/gcloud/spanner/spanner.go (2)
  • Run (36-71)
  • Container (19-22)
modules/gcloud/pubsub/pubsub.go (2)
  • Run (36-77)
  • Container (19-22)
modules/gcloud/datastore/datastore.go (4)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmd (462-467)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/http.go (1)
  • ForHTTP (149-151)
modules/gcloud/datastore.go (2)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmd (462-467)
wait/http.go (1)
  • ForHTTP (149-151)
modules/gcloud/bigtable.go (4)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmd (462-467)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/log.go (1)
  • ForLog (118-120)
modules/gcloud/firestore.go (4)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmd (462-467)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/log.go (1)
  • ForLog (118-120)
modules/gcloud/bigquery/bigquery_test.go (2)
modules/gcloud/bigquery/bigquery.go (1)
  • Run (43-84)
options.go (2)
  • ContainerCustomizer (22-24)
  • WithCmdArgs (470-475)
modules/gcloud/bigquery/bigquery.go (6)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmdArgs (470-475)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/http.go (1)
  • ForHTTP (149-151)
modules/gcloud/spanner/spanner.go (2)
  • Run (36-71)
  • Container (19-22)
modules/gcloud/pubsub/pubsub.go (2)
  • Run (36-77)
  • Container (19-22)
modules/gcloud/spanner/spanner.go (5)
options.go (3)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/log.go (1)
  • ForLog (118-120)
modules/gcloud/pubsub/pubsub.go (2)
  • Run (36-77)
  • Container (19-22)
modules/gcloud/bigtable/bigtable.go (5)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
  • WithCmd (462-467)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/log.go (1)
  • ForLog (118-120)
modules/gcloud/spanner/spanner.go (2)
  • Run (36-71)
  • Container (19-22)
modules/gcloud/spanner.go (4)
options.go (3)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithWaitStrategy (366-368)
wait/all.go (1)
  • ForAll (44-48)
wait/host_port.go (1)
  • ForListeningPort (67-69)
wait/log.go (1)
  • ForLog (118-120)
⏰ 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). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (8)
modules/gcloud/bigquery/options.go (1)

31-47: LGTM! Modular option application is correct.

The refactor correctly replaces direct mutation with wrapper calls to testcontainers.WithCmdArgs and testcontainers.WithFiles, propagating errors appropriately. The guard against duplicate data YAML remains in place.

modules/gcloud/bigquery.go (1)

20-49: LGTM! Deprecation path correctly migrated to modular options.

The deprecated RunBigQuery function correctly accumulates options in moduleOpts and delegates to newGCloudContainer. Port constants, wait strategies, and command argument application are all correct.

modules/gcloud/bigquery/bigquery_test.go (2)

79-79: LGTM! Error assertion loosened appropriately.

Changing from require.EqualError to require.ErrorContains is appropriate for the refactor, as error messages may now include additional wrapping context.


83-85: LGTM! Test helper updated to match new option type.

The noValueOption helper correctly returns testcontainers.ContainerCustomizer and uses the WithCmdArgs wrapper, aligning with the modular options pattern.

modules/gcloud/bigquery/bigquery.go (2)

19-22: LGTM! Port constants defined correctly.

The port constants are defined consistently with the pattern used across other gcloud modules.


44-84: LGTM! Run function correctly refactored to modular options pattern.

The Run function correctly:

  • Initializes moduleOpts with exposed ports and a composite wait strategy (ForAll with ForListeningPort and ForHTTP)
  • Applies incoming Option-type customizers to settings
  • Accumulates all options in moduleOpts
  • Calls testcontainers.Run with accumulated options
  • Wraps errors with appropriate context
  • Uses port constants for endpoint retrieval

The refactor aligns with the pattern used in other gcloud modules (pubsub, spanner, datastore).

modules/gcloud/datastore/datastore.go (2)

13-15: LGTM! Port constants defined correctly.

The port constants are defined consistently with the pattern used across other gcloud modules.


37-79: LGTM! Run function correctly refactored to modular options pattern.

The Run function correctly:

  • Initializes moduleOpts with exposed ports and a composite wait strategy (ForAll with ForListeningPort and ForHTTP)
  • Applies incoming Option-type customizers to settings
  • Appends the gcloud datastore start command via WithCmd, referencing the new port constant and project ID
  • Accumulates all options in moduleOpts
  • Calls testcontainers.Run with accumulated options
  • Wraps errors with appropriate context ("run datastore")
  • Uses port constants for endpoint retrieval

The refactor aligns with the pattern used in other gcloud modules.

@mdelapenya
Copy link
Member Author

Closing, as this PR was sent from wrong branch

@mdelapenya mdelapenya closed this Oct 3, 2025
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