Documentation ¶
Overview ¶
Package db contains test helper functions dealing with a database.
Index ¶
- Variables
- func DbWithSetupFile(filename string) (*sql.DB, error)
- func DbWithSetupString(setupSql string) (*sql.DB, error)
- func EmptyDb() (*sql.DB, error)
- func ExecMulti(db *sql.DB, sql string) error
- func ExecSegment(db *sql.DB, segment string) error
- func LoadSetupFile(db *sql.DB, filename string) error
- func LoadSetupString(db *sql.DB, setupSql string) error
- type Tester
Constants ¶
This section is empty.
Variables ¶
var ( DbType = "sqlite3" DbName = ":memory:" )
Functions ¶
func DbWithSetupFile ¶
DbWithSetupFile creates a new database and executes SQL commands from the given file.
func DbWithSetupString ¶
DbWithSetupFile creates a new database and executes SQL commands from the given string.
func EmptyDb ¶
EmptyDb creates an empty database from the values in our variables DbType and DbName.
func ExecMulti ¶
ExecMulti executes multiple sql statements from a string. It strips out all carriage returns, breaks the string into segments at double-newlines, removes lines starting with a "#" (as comments), and separately executes each segment. If any segment returns an error, it stop executing and returns that error.
func ExecSegment ¶
ExecSegment executes a single sql statement from a string. It removes lines starting with "#" (as comments).
func LoadSetupFile ¶
LoadSetupFile reads and executes SQL commands from the specified file.
Types ¶
type Tester ¶
type Tester struct { base.Tester // Base name for the test setup file; if not set, uses BaseName. SetupBaseName string // Path to the test setup file; if not set, uses SetupBaseName. SetupPath string DB *sql.DB }
Tester provides the structure for running unit tests with database setup files.
func NewTester ¶
NewTester creates a new instance of a Tester that will call the specified callback as the test function.
func (*Tester) SetupFilePath ¶
SetupFilePath returns the complete path to the setup file.