Documentation
¶
Overview ¶
Package testdb spins up a real database instance (TiDB, MySQL, or PostgreSQL) for integration tests.
Tests use CHETTER_TEST_DSN to point at an existing database (e.g. a CI service container). When that env var is unset, the package starts a one-shot Docker container for the test run and tears it down on exit.
Set CHETTER_TEST_DB_DIALECT to "mysql" or "postgres" to use that container instead of the default TiDB container.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PackageDB ¶
type PackageDB struct {
// contains filtered or unexported fields
}
PackageDB manages a single database Docker container shared across all tests in one package. Use StartPackageDB in TestMain for fast integration tests.
func StartPackageDB ¶
StartPackageDB starts a database container once per package. Call from TestMain. Pass *testing.M so cleanup runs after all tests complete via os.Exit.
type TestDB ¶
TestDB owns a connection to a real database instance plus the cleanup hooks the test should defer.
func NewForTesting ¶
NewForTesting prepares a fresh, isolated database on a TiDB instance. The returned TestDB is ready to use and the cleanup func drops the database and tears down the Docker container when one was started.
func PostgresSchemaParityDBs ¶
PostgresSchemaParityDBs creates two PostgreSQL databases on the same server: one with the runtime bootstrap schema (via store.ApplySchema) and one with Goose migrations. Use this to compare the two schema paths for drift.
func (*TestDB) DatabaseName ¶
DatabaseName returns the per-run database name.