testing

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const TraceCallbackSQL = `` /* 283-byte string literal not displayed */

TraceCallbackSQL defines a PostgreSQL function that emits NOTICE messages in a parseable format for test sequence verification.

Format: [TRACE]event|path|directory|depth|ordinal

RAISE NOTICE is non-transactional - notices are sent to the client immediately and survive savepoint rollbacks. This makes it ideal for verifying the complete test execution sequence including events that happen inside savepoints.

Variables

This section is empty.

Functions

func CleanupTestDB

func CleanupTestDB(t *testing.T, connString, dbName string)

CleanupTestDB drops the test database. Safe to call multiple times (uses DROP DATABASE IF EXISTS).

func CreateTestDB

func CreateTestDB(t *testing.T, connString, dbName string) func()

CreateTestDB creates a test database with the given name. Returns a cleanup function that should be called with t.Cleanup().

func GetTestConnectionString

func GetTestConnectionString(t *testing.T) string

GetTestConnectionString returns the test database connection string. Priority: PGMI_TEST_CONN env var > auto-started testcontainer > skip test.

func GetTestPool

func GetTestPool(t *testing.T, connString, dbName string) *pgxpool.Pool

GetTestPool creates a connection pool to the specified database for testing. The pool is automatically closed when the test completes.

func NewTestDeployer

func NewTestDeployer(t *testing.T) pgmi.Deployer

NewTestDeployer creates a Deployer instance configured for testing. Uses the standard connector factory and a force-approving test approver.

func NewTestDeployerWithFS

func NewTestDeployerWithFS(t *testing.T, fsProvider filesystem.FileSystemProvider) pgmi.Deployer

NewTestDeployerWithFS creates a Deployer instance configured for testing with a custom filesystem provider. This allows testing with embedded filesystems or in-memory filesystems.

func RequireDatabase

func RequireDatabase(t *testing.T) string

RequireDatabase combines SkipIfShort and GetTestConnectionString for convenience. Returns the test connection string if available, otherwise skips the test.

func SkipIfShort

func SkipIfShort(t *testing.T)

SkipIfShort skips the test if running in short mode (-short flag).

Types

type ForceApprover

type ForceApprover struct{}

ForceApprover is a test approver that always approves overwrite requests.

func (*ForceApprover) RequestApproval

func (a *ForceApprover) RequestApproval(ctx context.Context, dbName string) (bool, error)

RequestApproval always returns true (auto-approves).

type NoticeCapture added in v0.9.0

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

NoticeCapture collects and parses test events from PostgreSQL NOTICE messages. Thread-safe for concurrent use.

func NewNoticeCapture added in v0.9.0

func NewNoticeCapture() *NoticeCapture

NewNoticeCapture creates a new NoticeCapture instance. Looks for NOTICE messages matching: [TRACE]event|path|dir|depth|ordinal

func (*NoticeCapture) Count added in v0.9.0

func (nc *NoticeCapture) Count() int

Count returns the number of captured events.

func (*NoticeCapture) EventSequence added in v0.9.0

func (nc *NoticeCapture) EventSequence() []string

EventSequence returns just the event names in order.

func (*NoticeCapture) Events added in v0.9.0

func (nc *NoticeCapture) Events() []TestEvent

Events returns a copy of all captured test events.

func (*NoticeCapture) FindEvents added in v0.9.0

func (nc *NoticeCapture) FindEvents(eventType string) []TestEvent

FindEvents returns all events matching the specified event type.

func (*NoticeCapture) Handler added in v0.9.0

func (nc *NoticeCapture) Handler() func(*pgconn.PgConn, *pgconn.Notice)

Handler returns a function suitable for pgx's OnNotice callback. The handler parses [TRACE] messages and stores them as TestEvents.

func (*NoticeCapture) RawNotices added in v0.9.0

func (nc *NoticeCapture) RawNotices() []string

RawNotices returns all raw NOTICE messages received.

func (*NoticeCapture) Reset added in v0.9.0

func (nc *NoticeCapture) Reset()

Reset clears all captured events and raw notices.

type PoolWithNoticeCapture added in v0.9.0

type PoolWithNoticeCapture struct {
	*pgxpool.Pool
	Capture *NoticeCapture
}

PoolWithNoticeCapture wraps a pgxpool.Pool with notice capture support.

func GetTestPoolWithNoticeCapture added in v0.9.0

func GetTestPoolWithNoticeCapture(t *testing.T, connString, dbName string) *PoolWithNoticeCapture

GetTestPoolWithNoticeCapture creates a connection pool with notice capture enabled. The pool is automatically closed when the test completes.

type TestEvent added in v0.9.0

type TestEvent struct {
	Event     string // suite_start, fixture_start, etc.
	Path      string // Script path (empty for suite/teardown)
	Directory string // e.g., ./__test__/child/
	Depth     int
	Ordinal   int
}

TestEvent represents a parsed test lifecycle event from NOTICE messages.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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