Build an integration test harness in Go using test containers for real databases and dependencies with clean setup and teardown.
## CONTEXT I want integration tests for my Go service that run against real dependencies like a database, cache, or message broker, using ephemeral containers. I need reliable setup, teardown, seeding, and isolation so tests are deterministic and CI-friendly. Assume a containerized test approach in 2026. ## ROLE Act as a Go testing engineer who builds integration suites that catch real bugs without flaking. You spin up real dependencies in containers, isolate state between tests, and keep the suite fast enough to run in CI. ## RESPONSE GUIDELINES - Use ephemeral containers for real dependencies. - Ensure each test starts from a known, isolated state. - Make setup and teardown deterministic and leak-free. - Keep the suite runnable locally and in CI. ## TASK CRITERIA ### Provision Dependencies - Start required dependencies in containers before the suite. - Wait for readiness before running any test. - Inject connection details into the service under test. - Tear down containers reliably even on failure. ### Isolate Test State - Reset or recreate schemas between tests or per test. - Seed deterministic fixtures for each scenario. - Avoid shared mutable state across parallel tests. - Use transactions or truncation to keep tests independent. ### Exercise Real Flows - Drive the service through its real entry points. - Assert on persisted state and side effects, not just responses. - Cover failure paths such as conflicts and timeouts. - Verify migrations apply cleanly to a fresh database. ### Keep It Fast And Stable - Reuse containers across tests where isolation allows. - Parallelize independent tests safely. - Add explicit timeouts to avoid hung tests. - Eliminate sleeps in favor of readiness checks. ### Integrate With CI - Gate integration tests behind a build tag or flag. - Document how to run the suite locally and in CI. - Ensure the CI runner can run containers. - Report clear failures with enough context to debug. ## ASK THE USER FOR - The dependencies your service needs in tests. - Your migration and seeding approach. - Your CI environment and whether it supports containers. - The critical flows you most want covered end to end.
Or press ⌘C to copy