_go

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUnusedPort

func GetUnusedPort(t *testing.T) int

GetUnusedPort returns an unused port.

func NormalizeArrayType added in v0.12.0

func NormalizeArrayType(dt *types.DoltgresType, arr []any) any

NormalizeArrayType normalizes array types by normalizing its elements first, then to a string using the type IoOutput method.

func NormalizeExpectedRow added in v0.12.0

func NormalizeExpectedRow(fds []pgconn.FieldDescription, rows []sql.Row) []sql.Row

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

func NormalizeIntsAndFloats added in v0.12.0

func NormalizeIntsAndFloats(v any) any

NormalizeIntsAndFloats normalizes all int and float types to int64 and float64, respectively.

func NormalizeRow

func NormalizeRow(fds []pgconn.FieldDescription, row sql.Row, normalize bool) sql.Row

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

func NormalizeRows

func NormalizeRows(fds []pgconn.FieldDescription, rows []sql.Row, normalize bool) []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 NormalizeVal added in v0.12.0

func NormalizeVal(dt *types.DoltgresType, v any) any

NormalizeVal normalizes values to the Doltgres type expects, so it can be used to convert the values using the given Doltgres type. This is used to normalize array types as the type conversion expects certain type values.

func NormalizeValToString added in v0.12.0

func NormalizeValToString(dt *types.DoltgresType, v any) any

NormalizeValToString normalizes values into types that can be compared. JSON types, any pg types and time and decimal type values are converted into string value. |normalizeNumeric| defines whether to normalize Numeric values into either Numeric type or string type. 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.

func UnmarshalAndMarshalJsonString added in v0.12.0

func UnmarshalAndMarshalJsonString(val string) string

UnmarshalAndMarshalJsonString is used to normalize expected json type value to compare the actual value. JSON type value is in string format, and since Postrges JSON type preserves the input string if valid, it cannot be compared to the returned map as json.Marshal method space padded key value pair. To allow result matching, we unmarshal and marshal the expected string. This causes missing check for the identical format as the input of the json string.

Types

type Connection added in v0.13.0

type Connection struct {
	Default  *pgx.Conn
	Current  *pgx.Conn
	Username string
	Password string
}

Connection contains the default and current connections.

func CreateServer

func CreateServer(t *testing.T, database string) (context.Context, *Connection, *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 (*Connection) Close added in v0.13.0

func (conn *Connection) Close(ctx context.Context)

Close closes the connections.

func (*Connection) Connect added in v0.13.0

func (conn *Connection) Connect(ctx context.Context, username string, password string) error

Connect replaces the Current connection with a new one, using the given username and password. If the username is empty, then the default connection is used. If the username and password match the existing connection, then no new connection is made.

func (*Connection) Exec added in v0.13.0

func (conn *Connection) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)

Exec calls Exec on the current connection.

func (*Connection) Query added in v0.13.0

func (conn *Connection) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

Query calls Query on the current connection.

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 string

	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

	// Username specifies the user's name to use for the command. This creates a new connection, using the given name.
	// By default (when the string is empty), the `postgres` superuser account is used. Any consecutive queries that
	// have the same username and password will reuse the same connection. The `postgres` superuser account will always
	// reuse the same connection. Do note that specifying the `postgres` account manually will create a connection
	// that is different from the primary one.
	Username string
	// Password specifies the password that will be used alongside the given username. This field is essentially ignored
	// when no username is given. If a username is given and the password is empty, then it is assumed that the password
	// is the empty string.
	Password string

	// ExpectedTag is used to check the command tag returned from the server.
	// This is checked only if no Expected is defined
	ExpectedTag string

	// Cols is used to check the column names returned from the server.
	Cols []string

	// CopyFromSTDIN is used to test the COPY FROM STDIN command.
	CopyFromStdInFile string
}

ScriptTestAssertion are the assertions upon which the script executes its main "testing" logic.

Directories

Path Synopsis
regression

Jump to

Keyboard shortcuts

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