pgtest

package
v0.0.0-...-1b6ad0c Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunTest

func RunTest(t *testing.T, path, addr, user string)

RunTest executes PGTest commands, connecting to the database specified by addr and user. Supported commands:

"send": Sends messages to a server. Takes a newline-delimited list of pgproto3.FrontendMessage types. Can fill in values by adding a space then a JSON object. No output.

"until": Receives all messages from a server until messages of the given types have been seen. Converts them to JSON one per line as output. Takes a newline-delimited list of pgproto3.BackendMessage types. An ignore option can be used to specify types to ignore. ErrorResponse messages are immediately returned as errors unless they are the expected type, in which case they will marshal to an empty ErrorResponse message since our error detail specifics differ from Postgres.

"receive": Like "until", but only output matching messages instead of all messages.

If the argument crdb_only is given and the server is non-crdb (e.g. posrgres), then the exchange is skipped. With noncrdb_only, the inverse happens.

func WalkWithNewServer

func WalkWithNewServer(
	t *testing.T, path string, newServer func() (addr, user string, cleanup func()),
)

WalkWithNewServer walks path for datadriven files and calls RunTest on them, but creates a new server for each test file.

func WalkWithRunningServer

func WalkWithRunningServer(t *testing.T, path, addr, user string)

WalkWithRunningServer walks path for datadriven files and calls RunTest on them. It is used when an existing server is desired for each test.

Types

type PGTest

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

PGTest can be used to send and receive arbitrary pgwire messages on Postgres-compatible servers.

func NewPGTest

func NewPGTest(ctx context.Context, addr, user string) (*PGTest, error)

NewPGTest connects to a Postgres server at addr with username user.

func (*PGTest) Close

func (p *PGTest) Close() error

Close sends a Terminate message and closes the connection.

func (*PGTest) Receive

func (p *PGTest) Receive(
	keepErrMsg bool, typs ...pgproto3.BackendMessage,
) ([]pgproto3.BackendMessage, error)

Receive reads messages until messages of the given types have been found in the specified order (with any number of messages in between). It returns matched messages.

func (*PGTest) Send

func (p *PGTest) Send(msg pgproto3.FrontendMessage) error

Send sends msg to the serrver.

func (*PGTest) Until

func (p *PGTest) Until(
	keepErrMsg bool, typs ...pgproto3.BackendMessage,
) ([]pgproto3.BackendMessage, error)

Until is like Receive except all messages are returned instead of only matched messages.

Jump to

Keyboard shortcuts

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