testutil

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package testutil provides shared test utilities for pgschema

Package testutil provides shared test utilities for pgschema

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToPostgres

func ConnectToPostgres(t testing.TB, embeddedPG *postgres.EmbeddedPostgres) (conn *sql.DB, host string, port int, dbname, user, password string)

ConnectToPostgres connects to an embedded PostgreSQL instance and returns connection details. This is a helper for tests that need database connection information. The caller is responsible for closing the returned *sql.DB connection.

func GetMajorVersion

func GetMajorVersion(db *sql.DB) (int, error)

GetMajorVersion detects the major version of a PostgreSQL database connection. It queries the database using SHOW server_version_num and extracts the major version. For example, version 170005 (17.5) returns 17.

func ParseSQLToIR

func ParseSQLToIR(t *testing.T, embeddedPG *postgres.EmbeddedPostgres, sqlContent string, schema string) *ir.IR

ParseSQLToIR is a test helper that parses SQL and returns its IR representation. It applies the SQL to an embedded PostgreSQL instance, inspects it, and returns the IR. The schema will be reset (dropped and recreated) to ensure clean state between test calls. This ensures tests use the same code path as production (database inspection) rather than parsing.

func ParseSQLToIRWithSetup

func ParseSQLToIRWithSetup(t *testing.T, embeddedPG *postgres.EmbeddedPostgres, sqlContent string, schema string, setupSQL string) *ir.IR

ParseSQLToIRWithSetup is like ParseSQLToIR but accepts optional setup SQL. The setupSQL is executed AFTER schema recreation but BEFORE the main SQL. This is useful for tests that need to install extensions in the target schema (e.g., citext in public schema) which would otherwise be dropped during schema reset.

func SetupPostgres

func SetupPostgres(t testing.TB) *postgres.EmbeddedPostgres

SetupPostgres creates a PostgreSQL instance for testing. It uses the production postgres.EmbeddedPostgres implementation. PostgreSQL version is determined from PGSCHEMA_POSTGRES_VERSION environment variable.

func ShouldSkipTest

func ShouldSkipTest(t *testing.T, testName string, majorVersion int)

ShouldSkipTest checks if a test should be skipped for the given PostgreSQL major version. If the test should be skipped, it calls t.Skipf() which stops test execution.

Test name format examples:

  • "create_view_add_view" (from TestDiffFromFiles subtests - underscores separate all parts)
  • "create_view/add_view" (skip list patterns - underscores in category, slash before test)
  • "TestDumpCommand_Employee" (from dump tests - starts with Test)

Matching uses exact string match with flexible slash/underscore handling: Pattern "create_view/add_view" matches test name "create_view_add_view" (underscores)

Types

This section is empty.

Jump to

Keyboard shortcuts

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