ct

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvVarNameBase_NetProtocol = "PROTO"  // E.g. "tcp".
	EnvVarNameBase_Driver      = "DRIVER" // E.g. "mysql".
	EnvVarNameBase_Host        = "HOST"   // E.g. "localhost".
	EnvVarNameBase_Port        = "PORT"   // E.g. "3306".
	EnvVarNameBase_Database    = "DB"
	EnvVarNameBase_User        = "USER"
	EnvVarNameBase_Password    = "PWD"
)
View Source
const (
	ErrTestedFunctionsAreNotSet = "tested functions are not set"
	ErrUnknownSqlDriver         = "unknown SQL driver: %v"
	ErrConnectionIsNull         = "connection is null"
)
View Source
const (
	DriverMySQL      = "mysql"
	DriverPostgreSQL = "postgres"
)

List of supported SQL drivers.

Variables

This section is empty.

Functions

This section is empty.

Types

type IntroFunction

type IntroFunction func(*TestSuite) error

type OutroFunction

type OutroFunction func(*TestSuite) error

type TestDbParameters

type TestDbParameters struct {
	NetworkProtocol string // E.g. "tcp".
	Driver          string // E.g. "mysql".
	Host            string // E.g. "localhost".
	Port            string // E.g. "3306".
	DB              string
	User            string
	Pwd             string
}

TestDbParameters are parameters of a test database.

func NewTestDbParameters

func NewTestDbParameters(envVarNamePrefix string) (p *TestDbParameters, err error)

type TestSuite

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

TestSuite is a suite of several tests. To run the tests create a test suite and use the 'Run' method.

Test suite automatically connects to and disconnects from the test database, runs an "intro" function, then runs all the tests (tested functions), and then runs the "outro" function. Intro-function is used to prepare tested database objects, e.g. to create tables and data. Outro-function is used to clean up the mess in the database after the tests, e.g. to delete data and tables.

func NewTestSuite

func NewTestSuite(
	t *testing.T,
	envVarNamePrefix string,
	intro []IntroFunction,
	testedFunctions []*TestedFunction,
	outro []OutroFunction,
) (ts *TestSuite, err error)

func (*TestSuite) GetHandle

func (ts *TestSuite) GetHandle() (db *sql.DB)

GetHandle returns the SQL database handle.

func (*TestSuite) GetSchema

func (ts *TestSuite) GetSchema() (schema string)

GetSchema returns the database schema.

func (*TestSuite) Run

func (ts *TestSuite) Run()

Run runs all the tests (tested functions).

type TestedFunction

type TestedFunction struct {
	Name string
	Func func(t *testing.T)
}

Jump to

Keyboard shortcuts

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