Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PostgresContainer ¶
type PostgresContainer struct {
Container testcontainers.Container
Config *database.Config
DB *database.Connection
}
PostgresContainer wraps a testcontainers PostgreSQL instance.
func RequirePostgresContainer ¶
func RequirePostgresContainer(ctx context.Context, t *testing.T) *PostgresContainer
RequirePostgresContainer starts a PostgreSQL test container for t, skipping the test only when this environment has no usable Docker provider and failing loudly for every other error.
Drawing that line is the whole point (issue #1597). "No usable Docker daemon" is an environment fact and the one legitimate reason to skip, so it is probed explicitly before anything is started. Past that probe the daemon answered a health check, which makes a container that still refuses to come up -- a missing image, a database that never accepts connections -- a real failure. Reporting it as a skip would turn a broken run green, which is indistinguishable from a run that had nothing to say.
The probe owns the whole environment side of that line, so a daemon that is present but unhealthy skips too, rather than failing.
Callers remain responsible for Cleanup, matching SetupPostgresContainer.
func SetupPostgresContainer ¶
SetupPostgresContainer creates and starts a PostgreSQL test container.
func (*PostgresContainer) Cleanup ¶
func (c *PostgresContainer) Cleanup(ctx context.Context) error
Cleanup terminates the test container and closes database connection.
func (*PostgresContainer) ResetDatabase ¶
func (c *PostgresContainer) ResetDatabase(ctx context.Context) error
ResetDatabase drops and recreates all tables (useful for clean state).
func (*PostgresContainer) TruncateTables ¶
func (c *PostgresContainer) TruncateTables(ctx context.Context, tables ...string) error
TruncateTables removes all data from tables (useful between tests).