Documentation
¶
Overview ¶
Package testutil provides utilities for integration testing.
Index ¶
- Constants
- func ConnectTestDB(t *testing.T, connStr string) *pgxpool.Pool
- func CreateTestDB(t *testing.T, baseConnStr, appName string) string
- func DropTestDB(t *testing.T, baseConnStr, dbName string)
- func GetDBNameFromConnStr(connStr string) string
- func HasPgvector(t *testing.T, pool *pgxpool.Pool) bool
- func PostgresAvailable() string
- func SkipIfNoPgvector(t *testing.T, pool *pgxpool.Pool)
- func SkipIfNoPostgres(t *testing.T) string
- type TestCleanup
Constants ¶
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 ¶
ConnectTestDB connects to a test database.
func CreateTestDB ¶
CreateTestDB creates a test database and returns the connection string.
func DropTestDB ¶
DropTestDB drops the test database.
func GetDBNameFromConnStr ¶
GetDBNameFromConnStr extracts the database name from a connection string.
func HasPgvector ¶
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 ¶
SkipIfNoPgvector skips the test if pgvector is not available.
func SkipIfNoPostgres ¶
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.