testdb

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2018 License: Apache-2.0 Imports: 12 Imported by: 6

Documentation

Overview

Package testdb creates new databases for tests.

Created databases may use either sqlite (default) or mysql as the database driver. The default driver can be overridden via the TRILLIAN_SQL_DRIVER environment variable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context) (*sql.DB, error)

New creates a new, empty database with a randomly generated name. New is equivalent to Default().New(ctx).

func NewTrillianDB

func NewTrillianDB(ctx context.Context) (*sql.DB, error)

NewTrillianDB creates an empty database with the Trillian schema. The database name is randomly generated. NewTrillianDB is equivalent to Default().NewTrillianDB(ctx).

Types

type Provider

type Provider struct {
	// Driver is the SQL driver name used for sql.Open (e.g.: "mysql" or "sqlite3").
	Driver string

	// DataSourceName is the data source name used for sql.Open (e.g., the database URL).
	DataSourceName string

	// CreateDataSource controls whether a new, random data source is created.
	// If set the true, New() firstly connects to DataSourceName, creates a randomly-generated
	// database (via "CREATE DATABASE") and then connects to the new database.
	// Useful to create random databases via a "main" data source name.
	CreateDataSource bool
}

Provider is an object capable of creating new test databases.

func Default

func Default() *Provider

Default returns the default database provider.

func MySQL

func MySQL() *Provider

MySQL returns a MySQL database provider. The database must be running locally and have a root user without password.

func SQLite

func SQLite() *Provider

SQLite returns a SQLite database provider.

func (*Provider) IsMySQL

func (p *Provider) IsMySQL() bool

IsMySQL returns true if Provider uses the mysql driver.

func (*Provider) New

func (p *Provider) New(ctx context.Context) (*sql.DB, error)

New creates a new, empty database.

func (*Provider) NewTrillianDB

func (p *Provider) NewTrillianDB(ctx context.Context) (*sql.DB, error)

NewTrillianDB creates an empty database with the Trillian schema.

Jump to

Keyboard shortcuts

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