Documentation
¶
Overview ¶
Package mysql provides MySQL container management for testing.
Index ¶
- func Container(ctx context.Context) (*mysql.MySQLContainer, error)
- func MustNew(ctx context.Context) (*sql.DB, func())
- func MustNewWithOptions(ctx context.Context, opts ...Option) (*sql.DB, func())
- func New(ctx context.Context) (*sql.DB, func(), error)
- func NewWithConfig(ctx context.Context, cfg *config.MySQLConfig) (*sql.DB, func(), error)
- func NewWithOptions(ctx context.Context, opts ...Option) (*sql.DB, func(), error)
- func NewWithOptionsContainer(ctx context.Context, opts ...Option) (*mysql.MySQLContainer, error)
- type Option
- func WithDatabase(database string) Option
- func WithHealthCheckInterval(interval time.Duration) Option
- func WithHealthCheckRetry(retries int) Option
- func WithHealthCheckTimeout(timeout time.Duration) Option
- func WithImage(image string) Option
- func WithPassword(password string) Option
- func WithPoolSettings(maxOpen, maxIdle int, maxLifetime time.Duration) Option
- func WithUsername(username string) Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Container ¶
func Container(ctx context.Context) (*mysql.MySQLContainer, error)
Container exposes the underlying testcontainers MySQL module for advanced use.
func MustNew ¶
MustNew starts a new MySQL container and panics on error. Use for quick setup in tests.
func MustNewWithOptions ¶
MustNewWithOptions starts a MySQL container with options and panics on error.
func New ¶
New starts a new MySQL container and returns a connected *sql.DB. Call the returned cleanup function to stop and remove the container.
Example:
ctx := context.Background()
db, cleanup, err := mysql.New(ctx)
if err != nil {
panic(err)
}
defer cleanup()
func NewWithConfig ¶
NewWithConfig starts a MySQL container with custom configuration.
func NewWithOptions ¶
NewWithOptions starts a MySQL container with functional options. This is the preferred way to create a customized MySQL container.
Example:
ctx := context.Background()
db, cleanup, err := mysql.NewWithOptions(ctx,
mysql.WithImage("mysql:8.0"),
mysql.WithUsername("myuser"),
mysql.WithPassword("mypass"),
mysql.WithDatabase("mydb"),
)
if err != nil {
panic(err)
}
defer cleanup()
func NewWithOptionsContainer ¶
NewWithOptionsContainer starts a MySQL container with functional options and returns the raw container.
Types ¶
type Option ¶
type Option func(*config.MySQLConfig)
Option is a functional option for MySQL configuration.
func WithDatabase ¶
WithDatabase sets the MySQL database name.
func WithHealthCheckInterval ¶
WithHealthCheckInterval configures the interval between health check retries.
func WithHealthCheckRetry ¶
WithHealthCheckRetry configures health check retry attempts.
func WithHealthCheckTimeout ¶
WithHealthCheckTimeout sets the timeout for container health checks.
func WithPoolSettings ¶
WithPoolSettings configures connection pool settings.