Documentation
¶
Index ¶
- Constants
- func CleanupTestDB(t *testing.T, connString, dbName string)
- func CreateTestDB(t *testing.T, connString, dbName string) func()
- func GetTestConnectionString(t *testing.T) string
- func GetTestPool(t *testing.T, connString, dbName string) *pgxpool.Pool
- func NewTestDeployer(t *testing.T) pgmi.Deployer
- func NewTestDeployerWithFS(t *testing.T, fsProvider filesystem.FileSystemProvider) pgmi.Deployer
- func RequireDatabase(t *testing.T) string
- func SkipIfShort(t *testing.T)
- type ForceApprover
- type NoticeCapture
- func (nc *NoticeCapture) Count() int
- func (nc *NoticeCapture) EventSequence() []string
- func (nc *NoticeCapture) Events() []TestEvent
- func (nc *NoticeCapture) FindEvents(eventType string) []TestEvent
- func (nc *NoticeCapture) Handler() func(*pgconn.PgConn, *pgconn.Notice)
- func (nc *NoticeCapture) RawNotices() []string
- func (nc *NoticeCapture) Reset()
- type PoolWithNoticeCapture
- type TestEvent
Constants ¶
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 ¶
CleanupTestDB drops the test database. Safe to call multiple times (uses DROP DATABASE IF EXISTS).
func CreateTestDB ¶
CreateTestDB creates a test database with the given name. Returns a cleanup function that should be called with t.Cleanup().
func GetTestConnectionString ¶
GetTestConnectionString returns the test database connection string. Priority: PGMI_TEST_CONN env var > auto-started testcontainer > skip test.
func GetTestPool ¶
GetTestPool creates a connection pool to the specified database for testing. The pool is automatically closed when the test completes.
func NewTestDeployer ¶
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 ¶
RequireDatabase combines SkipIfShort and GetTestConnectionString for convenience. Returns the test connection string if available, otherwise skips the test.
func SkipIfShort ¶
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 ¶
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.