Skip to content

chore!: wait.ForSQL: change url callback to accept network.Network#3650

Open
thaJeztah wants to merge 1 commit intotestcontainers:mainfrom
thaJeztah:wait_sql_signature
Open

chore!: wait.ForSQL: change url callback to accept network.Network#3650
thaJeztah wants to merge 1 commit intotestcontainers:mainfrom
thaJeztah:wait_sql_signature

Conversation

@thaJeztah
Copy link
Copy Markdown
Contributor

@thaJeztah thaJeztah commented Apr 15, 2026

Commit 3e56fb9 updated this code to use the moby modules, and changed signatures to accept a string for ports ("<port>[/<protocol>]"), handling conversion to strong types (network.Port) internally.

In this case, however, the url callback function gets passed the host and port that's already parsed internally, so downgrading the parsed network.Port to a string means that a custom callback would have to parse the string again.

Change it to a strong-typed network.Port, which keeps all options open; callbacks that want to use the port in its string-format can call port.String(), but if only the port or proto is needed, they can use the port.Port(), port.Proto() or other methods.

What does this PR do?

Why is it important?

Related issues

@thaJeztah thaJeztah requested a review from a team as a code owner April 15, 2026 21:42
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 15, 2026

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 88fdff7
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/69e011f94ca3a70008c494da
😎 Deploy Preview https://deploy-preview-3650--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
Copy Markdown

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7cc90a66-2868-41b4-920f-a59a19a46e2b

📥 Commits

Reviewing files that changed from the base of the PR and between aa620fe and 88fdff7.

📒 Files selected for processing (4)
  • modules/cockroachdb/cockroachdb.go
  • modules/postgres/postgres_test.go
  • wait/sql.go
  • wait/sql_test.go
✅ Files skipped from review due to trivial changes (2)
  • modules/postgres/postgres_test.go
  • wait/sql_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • modules/cockroachdb/cockroachdb.go

Summary by CodeRabbit

  • Refactor
    • Standardized how database ports are handled across connection and readiness checks for CockroachDB/Postgres. Improves reliability and consistency of DB startup/wait flows with no change to external behavior.

Walkthrough

This PR changes SQL port handling to use the typed network.Port instead of string across the wait strategy and CockroachDB container code, passing ports directly into connection builders and removing intermediate parsing steps.

Changes

Cohort / File(s) Summary
CockroachDB Container
modules/cockroachdb/cockroachdb.go
connString and connConfig now accept network.Port (instead of string); removed network.ParsePort usage and construct host:port with net.JoinHostPort(host, port.Port()).
SQL Wait Strategy
wait/sql.go
wait.ForSQL callback signature and waitForSQL.URL changed to func(host string, port network.Port) string; WaitUntilReady passes network.Port directly to the URL callback.
Tests
modules/postgres/postgres_test.go, wait/sql_test.go
Updated test callbacks/mocks to accept network.Port instead of string; removed local network.MustParsePort conversions and adjusted ForSQL usages accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble ports now typed and neat,
No parsing crumbs beneath my feet.
I join host and port with a hop and a twirl,
network.Port makes the dance unfurl.
Hooray — tidy hops across the code-world!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore!: wait.ForSQL: change url callback to accept network.Network' is specific and accurately describes the main change—updating the ForSQL callback to use a strong-typed network.Port instead of a string.
Description check ✅ Passed The description is related to the changeset, explaining the rationale for changing the callback signature from string to network.Port and referencing a related discussion in PR #3591.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@thaJeztah thaJeztah force-pushed the wait_sql_signature branch from 992afa3 to a979eb2 Compare April 15, 2026 21:44
@thaJeztah thaJeztah changed the title refactor(wait)!: ForSQL: change url callback to accept network.Network chore(wait)!: ForSQL: change url callback to accept network.Network Apr 15, 2026
@thaJeztah
Copy link
Copy Markdown
Contributor Author

Are that conventional commit check is picky; looks like it doesn't support "scope"? https://www.conventionalcommits.org/en/v1.0.0/#commit-message-with-scope-and--to-draw-attention-to-breaking-change

Commit message with scope and ! to draw attention to breaking change

feat(api)!: send an email to the customer when a product is shipped

@thaJeztah thaJeztah force-pushed the wait_sql_signature branch from a979eb2 to 415c99f Compare April 15, 2026 21:48
@thaJeztah thaJeztah changed the title chore(wait)!: ForSQL: change url callback to accept network.Network chore!: wait.ForSQL: change url callback to accept network.Network Apr 15, 2026
Copy link
Copy Markdown

@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: 2

Caution

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

⚠️ Outside diff range comments (1)
modules/cockroachdb/cockroachdb.go (1)

123-123: ⚠️ Potential issue | 🔴 Critical

Type mismatch: passing string where network.Port is expected.

Line 123 calls c.connConfig(host, port.String()), but the updated connConfig signature at line 238 now expects port network.Port. This will cause a compilation error.

Since port is already a network.Port from MappedPort, pass it directly without conversion.

🐛 Proposed fix
-	return c.connConfig(host, port.String())
+	return c.connConfig(host, port)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@modules/cockroachdb/cockroachdb.go` at line 123, The call to connConfig is
passing a string but connConfig now expects a network.Port; update the call at
the site using the MappedPort variable (currently named port) to pass it
directly (i.e., pass port instead of port.String()) so the types match; locate
the call to c.connConfig(...) in cockroachdb.go and replace the port.String()
argument with the port MappedPort variable itself to satisfy the
connConfig(host, port network.Port) signature.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@wait/sql_test.go`:
- Around line 56-58: The PrepareContext method on mockSQLConn has the wrong
second parameter type; change mockSQLConn.PrepareContext to match
database/sql/driver.ConnPrepareContext by accepting (ctx context.Context, query
string) and returning (driver.Stmt, error) — keep returning &mockSQLStmt{}, nil
but update the parameter name/type from network.Port to string so the signature
matches the interface.
- Around line 42-44: The mock implementations use the wrong parameter types due
to an accidental refactor: change mockSQLDriver.Open to match
database/sql/driver.Driver by taking a string (Open(name string) (driver.Conn,
error)) instead of network.Port, and change mockSQLConn.PrepareContext to match
database/sql/driver.ConnPrepareContext by taking (ctx context.Context, query
string) and returning (driver.Stmt, error) instead of using network.Port; update
the function signatures and any call sites or tests in this file to use the
correct types and imports (context and database/sql/driver) and remove the
incorrect network.Port parameter usage.

---

Outside diff comments:
In `@modules/cockroachdb/cockroachdb.go`:
- Line 123: The call to connConfig is passing a string but connConfig now
expects a network.Port; update the call at the site using the MappedPort
variable (currently named port) to pass it directly (i.e., pass port instead of
port.String()) so the types match; locate the call to c.connConfig(...) in
cockroachdb.go and replace the port.String() argument with the port MappedPort
variable itself to satisfy the connConfig(host, port network.Port) signature.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 782bd351-070c-424a-81ba-8de4dc8bc870

📥 Commits

Reviewing files that changed from the base of the PR and between c251392 and a979eb2.

📒 Files selected for processing (4)
  • modules/cockroachdb/cockroachdb.go
  • modules/postgres/postgres_test.go
  • wait/sql.go
  • wait/sql_test.go

Comment thread wait/sql_test.go Outdated
Comment thread wait/sql_test.go Outdated
Copy link
Copy Markdown

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@modules/cockroachdb/cockroachdb.go`:
- Around line 238-239: The caller of CockroachDBContainer.connConfig is still
passing port.String(), causing a type mismatch after connConfig now expects
network.Port; locate the call site that invokes connConfig (the call that
currently passes port.String()) and remove the .String() so the raw network.Port
value is passed instead, ensuring types align with connConfig(host string, port
network.Port) and update any intermediate variables to use network.Port rather
than string if necessary.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 438a1efd-165e-432e-8697-63928658867a

📥 Commits

Reviewing files that changed from the base of the PR and between a979eb2 and 415c99f.

📒 Files selected for processing (4)
  • modules/cockroachdb/cockroachdb.go
  • modules/postgres/postgres_test.go
  • wait/sql.go
  • wait/sql_test.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • modules/postgres/postgres_test.go
  • wait/sql.go
  • wait/sql_test.go

Comment thread modules/cockroachdb/cockroachdb.go
@thaJeztah thaJeztah force-pushed the wait_sql_signature branch from 415c99f to aa620fe Compare April 15, 2026 22:30
Commit 3e56fb9 updated this code to use
the moby modules, and changed signatures to accept a string for ports
("<port>[/<protocol>]"), handling conversion to strong types (`network.Port`)
internally.

In this case, however, the url callback function gets passed the host and
port that's already parsed internally, so downgrading the parsed `network.Port`
to a string means that a custom callback would have to parse the string again.

Change it to a strong-typed `network.Port`, which keeps all options open;
callbacks that want to use the port in its string-format can call `port.String()`,
but if only the port or proto is needed, they can use the `port.Port()`, `port.Proto()`
or other methods.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah thaJeztah force-pushed the wait_sql_signature branch from aa620fe to 88fdff7 Compare April 15, 2026 22:32
@ShawnToubeau
Copy link
Copy Markdown

Thank you for this!! 🙌

@thaJeztah
Copy link
Copy Markdown
Contributor Author

cc @mdelapenya PTAL 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants