Documentation
¶
Index ¶
- func CreateServer(t *testing.T, database string) (context.Context, *pgx.Conn, *svcs.Controller)
- func GetUnusedPort(t *testing.T) int
- func NormalizeRow(row sql.Row) sql.Row
- func NormalizeRows(rows []sql.Row) []sql.Row
- func ReadRows(rows pgx.Rows) (readRows []sql.Row, err error)
- func RunScript(t *testing.T, script ScriptTest)
- func RunScripts(t *testing.T, scripts []ScriptTest)
- type ScriptTest
- type ScriptTestAssertion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateServer ¶
CreateServer creates a server with the given database, returning a connection to the server. The server will close when the connection is closed (or loses its connection to the server). The accompanying WaitGroup may be used to wait until the server has closed.
func NormalizeRow ¶
NormalizeRow normalizes each value's type, as the tests only want to compare values. Returns a new row.
func NormalizeRows ¶
NormalizeRows normalizes each value's type within each row, as the tests only want to compare values. Returns a new set of rows in the same order.
func ReadRows ¶
ReadRows reads all of the given rows into a slice, then closes the rows. This also normalizes all of the rows.
func RunScripts ¶
func RunScripts(t *testing.T, scripts []ScriptTest)
RunScripts runs the given collection of scripts.
Types ¶
type ScriptTest ¶
type ScriptTest struct {
// Name of the script.
Name string
// The database to create and use. If not provided, then it defaults to "postgres".
Database string
// The SQL statements to execute as setup, in order. Results are not checked, but statements must not error.
SetUpScript []string
// The set of assertions to make after setup, in order
Assertions []ScriptTestAssertion
// When using RunScripts, setting this on one (or more) tests causes RunScripts to ignore all tests that have this
// set to false (which is the default value). This allows a developer to easily "focus" on a specific test without
// having to comment out other tests, pull it into a different function, etc. In addition, CI ensures that this is
// false before passing, meaning this prevents the commented-out situation where the developer forgets to uncomment
// their code.
Focus bool
// Skip is used to completely skip a test including setup
Skip bool
}
ScriptTest defines a consistent structure for testing queries.
type ScriptTestAssertion ¶
type ScriptTestAssertion struct {
Query string
Expected []sql.Row
ExpectedErr bool
// SkipResultsCheck is used to skip assertions on the expected rows returned from a query. For now, this is
// included as some messages do not have a full logical implementation. Skipping the results check allows us to
// force the test client to not send of those messages.
SkipResultsCheck bool
// Skip is used to completely skip a test, not execute its query at all, and record it as a skipped test
// in the test suite results.
Skip bool
}
ScriptTestAssertion are the assertions upon which the script executes its main "testing" logic.