Skip to content

Update tests and ports configuration#43

Merged
djthorpe merged 4 commits intomainfrom
djt/0416/test
Apr 16, 2026
Merged

Update tests and ports configuration#43
djthorpe merged 4 commits intomainfrom
djt/0416/test

Conversation

@djthorpe
Copy link
Copy Markdown
Member

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 nat package, improve the flexibility of test setup by allowing custom setup/teardown logic, and update server initialization to better encapsulate handler registration.

Test infrastructure improvements:

  • The test.Main function 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]
  • The dependency on the nat package from github.com/docker/go-connections/nat is 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]
  • The OptPostgres option 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:

  • The registration of HTTP handlers in cmd/pgmanager/server.go and cmd/pgqueue/server.go is 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:

  • The now-unused bind_benchmark_test.go file is removed, cleaning up obsolete benchmarks.

Copilot AI review requested due to automatic review settings April 16, 2026 07:58
@djthorpe djthorpe self-assigned this Apr 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Main to accept an optional setup function that can return a cleanup function, and update all TestMain call sites accordingly.
  • Remove explicit nat usage 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/pgmanager and cmd/pgqueue to register HTTP handlers after server construction via server.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.

Comment thread pkg/test/opt_test.go Outdated
Comment on lines +85 to +90
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)
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@djthorpe djthorpe merged commit 84b2192 into main Apr 16, 2026
1 check passed
@djthorpe djthorpe deleted the djt/0416/test branch April 16, 2026 08:07
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