_go

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateServer

func CreateServer(t *testing.T, database string) (context.Context, *pgx.Conn, *svcs.Controller)

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 GetUnusedPort

func GetUnusedPort(t *testing.T) int

GetUnusedPort returns an unused port.

func NormalizeRow

func NormalizeRow(row sql.Row) sql.Row

NormalizeRow normalizes each value's type, as the tests only want to compare values. Returns a new row.

func NormalizeRows

func NormalizeRows(rows []sql.Row) []sql.Row

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 NormalizeRowsOnlyNumeric added in v0.5.0

func NormalizeRowsOnlyNumeric(rows []sql.Row) []sql.Row

NormalizeRowsOnlyNumeric normalizes Numeric values only. There are an infinite number of ways to represent the same value in-memory, so we must at least normalize Numeric values.

func Numeric added in v0.5.0

func Numeric(str string) pgtype.Numeric

Numeric creates a numeric value from a string.

func ReadRows

func ReadRows(rows pgx.Rows, normalizeRows bool) (readRows []sql.Row, err error)

ReadRows reads all of the given rows into a slice, then closes the rows. If `normalizeRows` is true, then the rows will be normalized such that all integers are int64, etc.

func RunScript

func RunScript(t *testing.T, script ScriptTest, normalizeRows bool)

RunScript runs the given script.

func RunScripts

func RunScripts(t *testing.T, scripts []ScriptTest)

RunScripts runs the given collection of scripts. This normalizes all rows before comparing them.

func RunScriptsWithoutNormalization added in v0.5.0

func RunScriptsWithoutNormalization(t *testing.T, scripts []ScriptTest)

RunScriptsWithoutNormalization runs the given collection of scripts, without normalizing any rows.

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

	BindVars []any

	// 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.

Jump to

Keyboard shortcuts

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