testutil

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package testutil provides shared test utilities for pgschema

Package testutil provides shared test utilities for pgschema

Index

Constants

View Source
const LatestPostgresVersion = 18

LatestPostgresVersion is the most recent PostgreSQL major version pgschema targets. It is the single point of indirection for the test strategy:

  • The full test suite runs only against this version.
  • Older versions (14 .. LatestPostgresVersion-1) run only the essential smoke-test subset defined in essentialTests.

When a new PostgreSQL major version ships, bump this constant (and add the new version to the CI matrix); the full suite automatically moves to it and the previous latest drops down to the essential subset — a single-line change.

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.

Strategy:

  • Tests requiring an unavailable extension are skipped on every version.
  • The full suite runs only against LatestPostgresVersion.
  • Older versions run only the essential smoke-test subset (essentialTests).

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)

Types

This section is empty.

Jump to

Keyboard shortcuts

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