Documentation
¶
Index ¶
- func CreateSpannerDatabaseFromMigrations(logger log.Logger, cfg database.DatabaseConfig, migrations fs.FS) (database.DatabaseConfig, func(), error)
- func NewMySQLDatabase(t *testing.T, cfg database.DatabaseConfig) error
- func NewPostgresDatabase(t *testing.T, cfg database.DatabaseConfig) error
- func NewPostgresDatabaseFromTemplate(tb testing.TB, logger log.Logger, cfg database.DatabaseConfig, ...) (database.DatabaseConfig, func())
- func NewSpannerDatabase(databaseName string, spannerCfg *database.SpannerConfig) (database.DatabaseConfig, error)
- func NewSpannerDatabaseFromMigrations(tb testing.TB, logger log.Logger, cfg database.DatabaseConfig, ...) (database.DatabaseConfig, func())
- func SetSpannerEmulator(hostOverride *string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateSpannerDatabaseFromMigrations ¶ added in v0.61.3
func CreateSpannerDatabaseFromMigrations( logger log.Logger, cfg database.DatabaseConfig, migrations fs.FS, ) (database.DatabaseConfig, func(), error)
CreateSpannerDatabaseFromMigrations is the error-returning variant of NewSpannerDatabaseFromMigrations. It is safe to call from contexts that cannot use tb.Fatal (e.g. inside sync.Once.Do).
func NewMySQLDatabase ¶ added in v0.44.0
func NewMySQLDatabase(t *testing.T, cfg database.DatabaseConfig) error
func NewPostgresDatabase ¶ added in v0.53.0
func NewPostgresDatabase(t *testing.T, cfg database.DatabaseConfig) error
func NewPostgresDatabaseFromTemplate ¶ added in v0.61.3
func NewPostgresDatabaseFromTemplate( tb testing.TB, logger log.Logger, cfg database.DatabaseConfig, migrations fs.FS, ) (database.DatabaseConfig, func())
NewPostgresDatabaseFromTemplate creates an isolated test database by cloning a template database that has already been migrated. The template is created once per unique migration set (content-addressed by SHA256) and reused across all tests in the process. This avoids running migrations for every test.
The template database is marked IS_TEMPLATE=true and ALLOW_CONNECTIONS=false so no test can accidentally connect to it. Each test gets its own clone with full isolation.
func NewSpannerDatabase ¶
func NewSpannerDatabase(databaseName string, spannerCfg *database.SpannerConfig) (database.DatabaseConfig, error)
func NewSpannerDatabaseFromMigrations ¶ added in v0.61.3
func NewSpannerDatabaseFromMigrations( tb testing.TB, logger log.Logger, cfg database.DatabaseConfig, migrations fs.FS, ) (database.DatabaseConfig, func())
NewSpannerDatabaseFromMigrations creates a Spanner test database with all migrations applied in a single batched DDL update, instead of running each migration file individually through golang-migrate. The spanner_schema_migrations table is pre-populated with the latest version so subsequent RunMigrations calls are no-ops (ErrNoChange).
If the batched DDL fails or cannot be parsed, the function falls back to creating a fresh empty database and lets the caller run migrations normally.
func SetSpannerEmulator ¶
func SetSpannerEmulator(hostOverride *string)
Must be called if using the docker spanner emulator
Types ¶
This section is empty.