Documentation
¶
Overview ¶
Package mysql. helpers.go - Internal helpers for the MySQL driver: io helpers, container file copy, and the wait-strategy builder. Kept separate so the main mysql.go file stays focused on the DatabaseDriver contract.
Package mysql. mysql.go - MySQL backend for dbtestkit. Boots a MySQL 8.x test container using testcontainers-go, with a tmpfs-backed data directory and an optimized entrypoint that re-hydrates a pre-baked empty database tarball (skipping the multi-second initdb phase).
Index ¶
- func New() dbtestkit.DatabaseDriver
- type MySQLDriver
- func (d *MySQLDriver) Driver() dbtestkit.Driver
- func (d *MySQLDriver) GenerateDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
- func (d *MySQLDriver) ResetStrategy() dbtestkit.ResetStrategy
- func (d *MySQLDriver) RestoreDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
- func (d *MySQLDriver) Start(ctx context.Context, env *dbtestkit.Environment) (string, error)
- func (d *MySQLDriver) Stop(ctx context.Context, _ *dbtestkit.Environment) error
- func (d *MySQLDriver) Truncate(_ context.Context, _ *dbtestkit.Environment) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New() dbtestkit.DatabaseDriver
New returns a fresh MySQL driver instance.
Pass the result to dbtestkit.WithDriver:
dbtestkit.Run(m,
dbtestkit.WithDriver(mysql.New()),
...
)
Types ¶
type MySQLDriver ¶ added in v0.3.2
type MySQLDriver struct {
// contains filtered or unexported fields
}
MySQLDriver implements dbtestkit.DatabaseDriver for MySQL.
func (*MySQLDriver) Driver ¶ added in v0.3.2
func (d *MySQLDriver) Driver() dbtestkit.Driver
Driver returns the dbtestkit.Driver constant this implementation serves.
func (*MySQLDriver) GenerateDump ¶ added in v0.3.2
func (d *MySQLDriver) GenerateDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
GenerateDump dumps the current database to dumpPath via mysqldump.
The dump is generated with --add-drop-table so restores are idempotent and do not require a separate TRUNCATE pass.
func (*MySQLDriver) ResetStrategy ¶ added in v0.3.2
func (d *MySQLDriver) ResetStrategy() dbtestkit.ResetStrategy
ResetStrategy returns RestoreDump to utilize the fast-path CLI pipe.
func (*MySQLDriver) RestoreDump ¶ added in v0.3.2
func (d *MySQLDriver) RestoreDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
RestoreDump pipes the pristine SQL dump into the MySQL CLI client inside the container. This is the fast-path reset (~ms).
func (*MySQLDriver) Start ¶ added in v0.3.2
func (d *MySQLDriver) Start(ctx context.Context, env *dbtestkit.Environment) (string, error)
Start boots the MySQL container and returns the DSN.
The container is configured with:
- tmpfs at /var/lib/mysql for in-memory storage (fast + ephemeral)
- an optimized entrypoint that re-hydrates a pre-baked empty DB tarball (skipping initdb's slow first-run sequence)
- no wait strategy — the entrypoint guarantees readiness before exec returns control
func (*MySQLDriver) Stop ¶ added in v0.3.2
func (d *MySQLDriver) Stop(ctx context.Context, _ *dbtestkit.Environment) error
Stop terminates the container.
func (*MySQLDriver) Truncate ¶ added in v0.3.2
func (d *MySQLDriver) Truncate(_ context.Context, _ *dbtestkit.Environment) error
Truncate is a no-op for MySQL — the pristine dump's DROP TABLE IF EXISTS statements make truncation redundant on the fast path.