Documentation ¶
Overview ¶
Package baloon is a setup and teardown test fixture library for end-to-end testing of HTTP APIs written in Go.
Index ¶
- Constants
- type App
- type DB
- type DBConn
- type Fixture
- func (fixture *Fixture) AddUnitTestSetup(setup UnitTest)
- func (fixture *Fixture) AddUnitTestTeardown(teardown UnitTest)
- func (fixture *Fixture) Close()
- func (fixture *Fixture) Setup() error
- func (fixture *Fixture) Teardown() error
- func (fixture *Fixture) UnitTestSetup(t *testing.T)
- func (fixture *Fixture) UnitTestTeardown(t *testing.T)
- type FixtureConfig
- type Script
- type UnitTest
Constants ¶
const ( // ScriptTypeLiteral specifies literal database command text ScriptTypeLiteral = 1 // ScriptTypePath specifies a glob file pattern for // database commands stored in files ScriptTypePath = 2 )
These consts represent the 2 types of database scripts we can use, either literal or file path
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct { // BuildArguments is a list of build arguments to include when baloon // tries to buld your App executable. They are run via "go build yourArgsHere..." BuildArguments []string // RunArguments is a list of command line arguments to // include when your Go executable is run. RunArguments []string // WaitForOutputLine specifies a line of text that baloon should wait // to appear in either stdout or stderr in order to signal that the App is // ready to start excepting HTTP requests. WaitForOutputLine string // WaitTimeout is how long baloon should wait for the // 'WaitForOutputLine' to appear. WaitTimeout time.Duration }
App represents settings and arguments for your Go HTTP API executable.
type DB ¶
type DB struct { // Connection stores database connection details including driver and connection // string. Uses sql.DB so make sure your driver is imported correctly. Connection DBConn // Script represents a Script to run on your database Script Script // Scripts represents multiple scripts to run on your database Scripts []Script }
DB represents a series of database scripts to run against a database given its Connection. It uses database/sql behind the scenes so your database driver will need to support it.
type DBConn ¶
type DBConn struct { // Driver is your database driver name, passed as the first // argument to sql.Open Driver string // String is the database connection string, passed as the // second argument to sql.Open String string }
DBConn represents a database connection including the driver and connection string. Uses sql.DB, so make sure your database driver package supports it and is imported.
type Fixture ¶
type Fixture struct {
// contains filtered or unexported fields
}
Fixture represents a test fixture. You usually have one per test suite.
func NewFixture ¶
func NewFixture(config FixtureConfig) (Fixture, error)
NewFixture returns a Fixture, but also verifies that everything has been set up correctly.
func (*Fixture) AddUnitTestSetup ¶
AddUnitTestSetup adds a UnitTest setup routine to the test Fixture
func (*Fixture) AddUnitTestTeardown ¶
AddUnitTestTeardown adds a UnitTest teardown routine to the test Fixture
func (*Fixture) Close ¶
func (fixture *Fixture) Close()
Close will attempt to free up any resources created by the Fixture. Make sure to call this before any log.Fatal() or os.Exit() calls.
func (*Fixture) Setup ¶
Setup runs the fixture setup. Call this only once before running all your tests, usually in func MainTest()
func (*Fixture) Teardown ¶
Teardown runs the fixture teardown routines. Call this only once after running all your tests, usually in func MainTest() after the call to m.Run()
func (*Fixture) UnitTestSetup ¶
UnitTestSetup will run all UnitTest setup routines. This is run at the start of each individual test, e.g. func TestSomething(t *testing.T), within your test suite.
func (*Fixture) UnitTestTeardown ¶
UnitTestTeardown will run all UnitTest teardown routines. This is run at the end of each individual test, e.g. func TestSomething(t *testing.T), within your test suite.
type FixtureConfig ¶
type FixtureConfig struct { // AppRoot is an absolute path to the root of your Go application directory, // where your main.go file is located. AppRoot string // DatabaseSetups is a list of one or more database setup commands to run // before the test suite is run. DatabaseSetups []DB // AppSetup specifies configuration settings for your Go app executable. AppSetup App // DatabaseTeardowns is a list of one or more database teardown // commands to run after the test suite has run. DatabaseTeardowns []DB }
FixtureConfig is a configuration object for your test Fixture.
type Script ¶
type Script struct { // Type is the Script type to use. Type int // Command is either a literal database command, or a file // glob pattern, depending on the 'Type'. Command string }
Script represents a database script run either as a setup or teardown routine. Command can either be a literal script, or a path (using globbing patterns) to a script file or files.
func NewScriptPath ¶
NewScriptPath returns a Script that represents a glob path to a script files or files to run.
type UnitTest ¶
type UnitTest struct { // DatabaseRoutines is a list of one or more database setup commands to // run before each unit, or at the end of each unit test. DatabaseRoutines []DB // Func is a function to run before each unit test is run. Func func(t *testing.T) }
UnitTest represents database commands and a func to run at the beginning or end of each unit test.