Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the integration-test helper utilities and server startup flow by (1) expanding the pkg/test.Main entrypoint to support optional suite setup/teardown and (2) simplifying port handling by treating ports as strings (removing explicit nat.Port usage). It also refactors server startup to register HTTP handlers via the server’s own router and removes an obsolete benchmark.
Changes:
- Extend
pkg/test.Mainto accept an optionalsetupfunction that can return acleanupfunction, and update allTestMaincall sites accordingly. - Remove explicit
natusage in test container option code and adjust Postgres readiness URL creation to strip protocol suffixes (e.g.,"5432/tcp"→"5432"), with updated tests. - Refactor
cmd/pgmanagerandcmd/pgqueueto register HTTP handlers after server construction viaserver.Router(), and delete an unused benchmark file.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pool_test.go | Updates TestMain to use the new test.Main(m, &conn, nil) signature. |
| pkg/test/opt_test.go | Updates port assertions to strings and adds coverage for Postgres URL port-suffix stripping. |
| pkg/test/opt.go | Switches port handling to strings and updates OptPostgres URL builder to cut "/tcp" suffix. |
| pkg/test/main.go | Adds setup/cleanup hook and refactors to ensure defers run before os.Exit. |
| pkg/test/doc.go | Updates documentation example to new Main signature. |
| pkg/test/container.go | Uses string ports when mapping exposed ports. |
| pkg/test/README.md | Updates README example to new Main signature. |
| pkg/queue/manager_test.go | Updates TestMain to new signature. |
| pkg/manager/database_test.go | Updates TestMain to new signature. |
| pkg/broadcaster/broadcaster_test.go | Updates TestMain to new signature. |
| cmd/pgqueue/server.go | Constructs server first, then registers handlers via server.Router(). |
| cmd/pgmanager/server.go | Constructs server first, then registers handlers via server.Router(). |
| bind_benchmark_test.go | Removes unused benchmark file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| strategyValue := reflect.ValueOf(multi.Strategies[1]).Elem() | ||
| urlField := strategyValue.FieldByName("URL") | ||
| require.True(urlField.IsValid()) | ||
|
|
||
| urlFn, ok := urlField.Interface().(func(string, string) string) | ||
| require.True(ok) |
There was a problem hiding this comment.
Test_Opt_003 relies on reflection to reach into a wait strategy’s internal struct field ("URL") and calls .Elem()/Interface() without checking Kind/CanInterface. This is brittle against upstream changes (field rename/unexported, non-pointer strategy) and can cause the test to panic. Prefer asserting the concrete strategy type (if available) and accessing its exported API directly, or factor the URL-building logic out of OptPostgres into a small helper and unit-test that helper instead of reflecting into testcontainers internals.
This pull request makes several improvements to the test infrastructure and server handler registration logic, focusing on simplifying the test container setup and streamlining how HTTP handlers are registered in the server startup code. The changes remove an unnecessary dependency on the
natpackage, improve the flexibility of test setup by allowing custom setup/teardown logic, and update server initialization to better encapsulate handler registration.Test infrastructure improvements:
test.Mainfunction now accepts an optional setup function for additional test initialization and cleanup, and all test entrypoints are updated to use the new signature. This allows for more flexible test setups and resource management. [1] [2] [3] [4] [5] [6] [7]natpackage fromgithub.com/docker/go-connections/natis removed throughout the test container code, and all port handling is done using plain strings. This simplifies the code and reduces external dependencies. [1] [2] [3] [4] [5] [6] [7]OptPostgresoption and its tests are updated to handle port strings directly, including parsing the port string to remove protocol suffixes when constructing the connection URL. [1] [2]Server startup and handler registration:
cmd/pgmanager/server.goandcmd/pgqueue/server.gois refactored so that handlers are registered after the HTTP server is created, using the server's provided router. This encapsulates router management within the server and clarifies the server setup flow. [1] [2] [3] [4] [5] [6]Test cleanup:
bind_benchmark_test.gofile is removed, cleaning up obsolete benchmarks.