Skip to content

Conversation

@mdelapenya
Copy link
Member

What does this PR do?

Use Run function in the socat 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 September 26, 2025 14:25
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Sep 26, 2025
@mdelapenya mdelapenya self-assigned this Sep 26, 2025
@netlify
Copy link

netlify bot commented Sep 26, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit ddd33d3
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68d6a262d7bf570008272b38
😎 Deploy Preview https://deploy-preview-3312--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 Sep 26, 2025

Summary by CodeRabbit

  • New Features

    • Added support to specify an initial command for the Socat module, enabling custom startup behavior.
  • Refactor

    • Streamlined container startup using a modular configuration approach.
    • Consolidated port exposure handling for more predictable configuration.
    • Preserved existing readiness checks while updating the startup flow.
    • Improved error messages when container startup fails.

Walkthrough

Refactors socat module container creation from GenericContainer/ContainerRequest to the Run + functional options API, building options for entrypoint, exposed ports, and optional command. Updates error messaging and preserves readiness checks with the new flow.

Changes

Cohort / File(s) Summary of Changes
Socat module: switch to Run(options...) API
modules/socat/socat.go
Replaced GenericContainerRequest with option builders (WithEntrypoint, WithExposedPorts, WithCmdArgs). Aggregated exposed ports from settings.targets. Switched to testcontainers.Run and updated error strings. Kept readiness checks aligned with new construction flow.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor T as Test/Caller
  participant S as Socat Module
  participant TC as testcontainers.Run
  participant C as Container
  participant W as Wait Strategy

  T->>S: Start(ctx, settings, opts...)
  S->>S: Build module options (entrypoint, exposed ports, cmd)
  S->>TC: Run(ctx, image, moduleOpts..., opts...)
  TC-->>C: Create and start container
  S->>W: Apply readiness checks
  W-->>S: Ready or error
  S-->>T: Container handle or error ("run socat")
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • stevenh

Poem

A rabbit taps the Run command, hop-hop, then waits,
Ports in a tidy basket, options on their plates.
Entrypoint set, a whisper of cmd,
Socat stirs awake—onward we ascend.
Carrots for logs, paws crossed for green—
Ready checks pass; the burrow runs clean. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the core change—migrating the socat module to use the Run function—without extraneous details, making it clear and directly related to the changeset.
Description Check ✅ Passed The description clearly states that the PR updates the socat module to use the Run function and explains that this is part of migrating modules to the new API, directly reflecting the changes made.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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

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

@mdelapenya mdelapenya merged commit 7eb93bb into testcontainers:main Sep 26, 2025
15 of 16 checks passed
@mdelapenya mdelapenya deleted the run-function-socat branch September 26, 2025 14:32
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

🧹 Nitpick comments (3)
modules/socat/socat.go (3)

42-44: Gate entrypoint with command to avoid starting an idle shell and unintended overrides

Only set /bin/sh when you also set "-c ". This prevents starting a shell with no args when there are no targets and avoids unnecessarily overriding a user-provided entrypoint.

-moduleOpts := []testcontainers.ContainerCustomizer{
-	testcontainers.WithEntrypoint("/bin/sh"),
-}
+moduleOpts := []testcontainers.ContainerCustomizer{}
@@
-if settings.targetsCmd != "" {
-	moduleOpts = append(moduleOpts, testcontainers.WithCmdArgs("-c", settings.targetsCmd))
-}
+if settings.targetsCmd != "" {
+	moduleOpts = append(moduleOpts,
+		testcontainers.WithEntrypoint("/bin/sh"),
+		testcontainers.WithCmdArgs("-c", settings.targetsCmd),
+	)
+}

Also applies to: 54-54


46-47: Make exposed ports deterministic and skip no-op customizer

Preallocate and sort for determinism; avoid appending a WithExposedPorts option when there are no ports.

-exposedPorts := []string{}
-
-for k := range settings.targets {
-	exposedPorts = append(exposedPorts, fmt.Sprintf("%d/tcp", k))
-}
-moduleOpts = append(moduleOpts, testcontainers.WithExposedPorts(exposedPorts...))
+exposedPorts := make([]string, 0, len(settings.targets))
+ports := make([]int, 0, len(settings.targets))
+for k := range settings.targets {
+	ports = append(ports, k)
+}
+sort.Ints(ports)
+for _, p := range ports {
+	exposedPorts = append(exposedPorts, fmt.Sprintf("%d/tcp", p))
+}
+if len(exposedPorts) > 0 {
+	moduleOpts = append(moduleOpts, testcontainers.WithExposedPorts(exposedPorts...))
+}

Add import:

-import (
+import (
 	"context"
 	"fmt"
 	"net/url"
+	"sort"

Also applies to: 49-51


66-66: Align error prefix with other modules

For consistency with dockermodelrunner ("socat run: %w"), prefer the same prefix ordering.

-		return c, fmt.Errorf("run socat: %w", err)
+		return c, fmt.Errorf("socat run: %w", err)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f0e4cd and ddd33d3.

📒 Files selected for processing (1)
  • modules/socat/socat.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
modules/socat/socat.go (2)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithEntrypoint (448-453)
  • WithExposedPorts (464-469)
  • WithCmdArgs (480-485)
modules/dockermodelrunner/dockermodelrunner.go (2)
  • Run (28-71)
  • Container (20-25)
⏰ 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). (2)
  • GitHub Check: test (1.24.x, modules/socat) / test: modules/socat/1.24.x
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
modules/socat/socat.go (2)

59-60: Migration to Run API looks good

Switching to testcontainers.Run with functional options is clean and aligns with the new API.


57-60: No override risk from socat.Option
Option implements ContainerCustomizer but its Customize method is a no-op, so appending opts after defaults won’t double-apply or override Entrypoint/Cmd/ExposedPorts.

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