fix: strip port/proto suffix in wait.ForSQL URL callback#4
Merged
Conversation
testcontainers-go v0.42 (moby-modules migration) changed the signature of wait.ForSQL's URL callback from (host string, port nat.Port) to (host string, port string), and now passes port.String() which returns "<num>/<proto>" (e.g. "5432/tcp"). Embedding that directly into the URL made pgx parse the dbname as "tcp/<configured-db>" — every connect attempt failed with "database tcp/<db> does not exist" and the wait loop timed out at 10s with a misleading "get state: context deadline exceeded" error. Strip the suffix in the callback before composing the DSN, and add testcontainer-backed regression tests.
Add a Test workflow that runs `go test -race` on push and PR. `go vet` (run by `-race`) flags that SlogAdapter.Printf passed its variadic arguments without spreading, so fmt.Sprintf saw a single []any instead of the intended args — fix it by forwarding with `v...`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
chore!: migrate to moby modules, #3591),wait.ForSQL's URL callback receives the port asnetwork.Port.String()("<num>/<proto>", e.g."32769/tcp") instead of the bare numeric port. Our callback atcontainer.gowas splicing that directly into the URL path, making pgx parse the dbname astcp/<configured-db>; every SQL probe failed withdatabase "tcp/<db>" does not existuntil the 10 s wait timeout expired with a misleadingget state: context deadline exceededfrom testcontainers' own container-inspection call./protosuffix viastrings.Cut(port, "/")before formatting the DSN.container_test.gowith a TestMain-scoped container and three tests that cover the exact regression (container comes up, instances are usable, instances are isolated from the template).Testworkflow (go test -raceon push & PR).SlogAdapter.Printfwas passing its variadic args without..., flagged bygo vet(which-raceenables). Forward them correctly sofmt.Sprintfsees the intended values.Root cause reference
github.com/moby/moby/api@v1.54.2/types/network/port.go:Port.String()usesAppendTo, so the port crossing the callback boundary always carries the proto suffix now.