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 Driver
- func (d *Driver) Driver() dbtestkit.Driver
- func (d *Driver) GenerateDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
- func (d *Driver) RestoreDump(ctx context.Context, env *dbtestkit.Environment, dumpPath string) error
- func (d *Driver) Start(ctx context.Context, env *dbtestkit.Environment) (string, error)
- func (d *Driver) Stop(ctx context.Context, _ *dbtestkit.Environment) error
- func (d *Driver) 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 Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver implements dbtestkit.DatabaseDriver for MySQL.
func (*Driver) GenerateDump ¶
func (d *Driver) 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 (*Driver) RestoreDump ¶
func (d *Driver) 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 (*Driver) Start ¶
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