tstmysql

package
v0.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Docker repository.
	Repository = "mysql"

	// Default tag.
	DefaultTag = "8.0.19"

	// Default database name.
	DefaultDBName = "tst"

	// Default root password.
	DefaultRootPassword = "123456"

	// Default container expire time.
	DefaultExpire uint = 120
)

Functions

This section is empty.

Types

type Options

type Options struct {
	// Tag of the repository. Default: DefaultTag.
	Tag string

	// The database created when MySQL server starts. Default: DefaultDBName.
	DBName string

	// The root password. Default: DefaultRootPassword.
	RootPassword string

	// If specified, MySQL data will be mount to this host directory. Default: "".
	// NOTE: The directory must be either contain an existing MySQL database or completely empty.
	HostDataPath string

	// If specified, SQL files inside this host directory will be loaded when MySQL server initialize. Default: "".
	// NOTE: These files will not be loaded if HostDataPath is specified and contains an existing database.
	HostInitSQLPath string

	// If specified, the port 3306/tcp will be mapped to it. Default: random port.
	HostPort uint16

	// Expire time (in seconds) of the container. Default: DefaultExpire.
	Expire uint

	// BaseRunOptions is the base options, will be overrided by above.
	BaseRunOptions dockertest.RunOptions
}

Options is options to run a MySQL test server.

type Resource

type Resource struct {
	// MySQL docker container.
	*dockertest.Resource

	// Actual options.
	Options
}

Resource represents a test MySQL server.

func Run

func Run(opts *Options) (*Resource, error)

Run is equivalent to RunFromPool(nil, opts).

func RunFromPool

func RunFromPool(pool *dockertest.Pool, opts *Options) (*Resource, error)

RunFromPool runs a test MySQL server. If pool is nil, tstsvc.DefaultPool() will be used. If opts is nil, the default options will be used.

func (*Resource) Client

func (res *Resource) Client() (*sql.DB, error)

Client returns a client to the test MySQL server.

func (*Resource) DSN

func (res *Resource) DSN() string

DSN returns the data source name of the test MySQL server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL