testutil

package
v1.0.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: PostgreSQL Imports: 8 Imported by: 0

Documentation

Overview

Package testutil provides utilities for integration testing.

Index

Constants

View Source
const (
	// DefaultTestConnString is the default connection string for tests.
	// Override with PGEDGE_TEST_CONN environment variable.
	DefaultTestConnString = "postgres://postgres@localhost:5432/postgres"

	// TestDBPrefix is the prefix for test databases.
	TestDBPrefix = "loadgen_test_"
)

Variables

This section is empty.

Functions

func ConnectTestDB

func ConnectTestDB(t *testing.T, connStr string) *pgxpool.Pool

ConnectTestDB connects to a test database.

func CreateTestDB

func CreateTestDB(t *testing.T, baseConnStr, appName string) string

CreateTestDB creates a test database and returns the connection string.

func DropTestDB

func DropTestDB(t *testing.T, baseConnStr, dbName string)

DropTestDB drops the test database.

func GetDBNameFromConnStr

func GetDBNameFromConnStr(connStr string) string

GetDBNameFromConnStr extracts the database name from a connection string.

func HasPgvector

func HasPgvector(t *testing.T, pool *pgxpool.Pool) bool

HasPgvector checks if the pgvector extension is available.

func PostgresAvailable

func PostgresAvailable() string

PostgresAvailable checks if PostgreSQL is available for testing. Returns the connection string if available, empty string otherwise.

func SkipIfNoPgvector

func SkipIfNoPgvector(t *testing.T, pool *pgxpool.Pool)

SkipIfNoPgvector skips the test if pgvector is not available.

func SkipIfNoPostgres

func SkipIfNoPostgres(t *testing.T) string

SkipIfNoPostgres skips the test if PostgreSQL is not available.

Types

type TestCleanup

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

TestCleanup is a helper that cleans up test resources.

func NewTestCleanup

func NewTestCleanup(t *testing.T, baseConnStr, dbName string) *TestCleanup

NewTestCleanup creates a new test cleanup helper.

func (*TestCleanup) Cleanup

func (tc *TestCleanup) Cleanup()

Cleanup performs the cleanup. The database is only dropped if the test passed; on failure it remains for diagnostic purposes.

func (*TestCleanup) SetPool

func (tc *TestCleanup) SetPool(pool *pgxpool.Pool)

SetPool sets the pool to close on cleanup.

Jump to

Keyboard shortcuts

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