testutil

package
v0.0.0-...-03d6fc4 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// String to open a local database for testing. The string formatting
	// parameters are: username, password, database.
	MYSQL_DB_OPEN = "%s:%s@tcp(localhost:3306)/%s?parseTime=true"

	// Name of the MySQL lock
	SQL_LOCK = "mysql_testlock"

	// Name of the shared test database.
	TEST_DB_HOST = "localhost"
	TEST_DB_PORT = 3306
	TEST_DB_NAME = "sk_testing"

	// Names of test users. These users should have no password and be
	// limited to accessing the sk_testing database.
	USER_ROOT = "test_root"
	USER_RW   = "test_rw"

	// Empty password for testing.
	TEST_PASSWORD = ""
)

Connection string to the local MySQL database for testing.

Variables

This section is empty.

Functions

func ClearMySQLTables

func ClearMySQLTables(t testutils.TestingT, vdb *database.VersionedDB)

Remove all tables from the database.

func LocalTestDatabaseConfig

func LocalTestDatabaseConfig(m []database.MigrationStep) *database.DatabaseConfig

LocalTestDatabaseConfig returns a DatabaseConfig appropriate for local testing.

func LocalTestRootDatabaseConfig

func LocalTestRootDatabaseConfig(m []database.MigrationStep) *database.DatabaseConfig

LocalTestRootDatabaseConfig returns a DatabaseConfig appropriate for local testing, with root access.

func MySQLVersioningTests

func MySQLVersioningTests(t testutils.TestingT, dbName string, migrationSteps []database.MigrationStep)

Creates an MySQL test database and runs migration tests against it using the given migration steps. See Get for required credentials. The test assumes that the database is empty and that the readwrite user is not allowed to create/drop/alter tables.

Types

type LockDB

type LockDB struct {
	DB *sqlx.DB
}

func GetMySQlLock

func GetMySQlLock(t testutils.TestingT, conf *database.DatabaseConfig) *LockDB

Get a lock from MySQL to serialize DB tests.

func (*LockDB) Close

func (l *LockDB) Close(t testutils.TestingT)

Release the MySQL lock.

type MySQLTestDatabase

type MySQLTestDatabase struct {
	// contains filtered or unexported fields
}

MySQLTestDatabase is a convenience struct for using a test database which starts in a clean state.

func SetupMySQLTestDatabase

func SetupMySQLTestDatabase(t testutils.TestingT, migrationSteps []database.MigrationStep) *MySQLTestDatabase

SetupMySQLTestDatabase returns a MySQLTestDatabase in a clean state. It must be closed after use.

Example usage:

db := SetupMySQLTestDatabase(t, migrationSteps) defer util.Close(db) ... Tests here ...

func (*MySQLTestDatabase) Close

func (d *MySQLTestDatabase) Close(t testutils.TestingT)

Jump to

Keyboard shortcuts

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