Documentation
¶
Overview ¶
Package postgres provides test helpers for integration tests that require a real PostgreSQL database. It is intended to be imported only from _test.go files or test binaries.
Usage:
func TestSomething(t *testing.T) {
db := testpostgres.Open(t)
// db is closed and all connections released when t ends.
}
Index ¶
Constants ¶
View Source
const ( // EnvDatabaseURL is the environment variable used to locate the test database. // Set it to a postgres:// DSN before running integration tests. // Example: postgres://user:pass@localhost:5432/testdb?sslmode=disable EnvDatabaseURL = "TEST_DATABASE_URL" )
Variables ¶
This section is empty.
Functions ¶
func NewIsolatedDatabase ¶
NewIsolatedDatabase creates a fresh PostgreSQL database for the test and returns a pool connected to it. The database is dropped when t ends.
This gives each test a clean, isolated schema so tests can run in parallel without interfering with each other.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.