Documentation
¶
Overview ¶
Package tmpmysql provides the ability to spin up temporary mysqld instances for testing purposes.
Example ¶
if !IsMySQLInstalled() {
panic("MySQL not installed")
}
server, err := NewMySQLServer("tmpmysqld_test")
if err != nil {
panic(err)
}
defer server.Stop()
if _, err := server.DB.Exec(`
CREATE TABLE things (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL
)
`); err != nil {
panic(err)
}
if _, err := server.DB.Exec(`
INSERT INTO things (name) VALUES ("one"), ("two")
`); err != nil {
panic(err)
}
rows, err := server.DB.Query(`SELECT id, name FROM things ORDER BY id`)
if err != nil {
panic(err)
}
defer rows.Close()
for rows.Next() {
var id int64
var name string
if err := rows.Scan(&id, &name); err != nil {
panic(err)
}
fmt.Printf("%d=%s\n", id, name)
}
Output: 1=one 2=two
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsMySQLInstalled ¶
func IsMySQLInstalled() bool
IsMySQLInstalled returns true if the various required components of MySQL are available.
tmpmysqld requires mysqld, mysql_install_db, and mysql_config to be on the path of the running process.
Types ¶
type MySQLServer ¶
A MySQLServer is a temporary instance of mysqld.
func NewMySQLServer ¶
func NewMySQLServer(name string) (*MySQLServer, error)
NewMySQLServer returns a new mysqld instance running on the given port, with the given database created and selected as the current database.
func (*MySQLServer) Stop ¶
func (s *MySQLServer) Stop() error
Stop terminates the mysqld instance and deletes the temporary directory which contains the database files.
Click to show internal directories.
Click to hide internal directories.