pgtest

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pgtest starts a real PostgreSQL with a schema.sql applied, for testing the database side of an application (views, functions, triggers, constraints) from Go the same way the checker's oracle does. Nothing persists: the server lives in a temporary directory and dies with Close.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadSchema

func ReadSchema(path string) (string, error)

ReadSchema reads a schema.sql file, or a directory of *.sql files applied in name order, the same way the checker does, for passing to Start.

Types

type DB

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

DB is a running PostgreSQL with the schema applied.

func Start

func Start(ctx context.Context, schemaSQL string) (*DB, error)

Start launches PostgreSQL (embedded binary, downloaded on first use) and applies schemaSQL.

func (*DB) Close

func (d *DB) Close() error

Close stops the server and removes its data.

func (*DB) Conn

func (d *DB) Conn() *pgx.Conn

Conn is a connection to the database; it satisfies sqlshape.DB.

func (*DB) ConnString

func (d *DB) ConnString() string

ConnString connects other clients (a pgxpool.Pool, psql) to the same server.

func (*DB) Verify

func (d *DB) Verify(ctx context.Context, stmts ...Statement) error

Verify checks that the analyzer agrees with this PostgreSQL about each statement: every expansion of the template (each combination of its branches) is prepared by PG, and PG's parameter types, result column names and types, or its rejection, are compared with what the checker concluded. A disagreement means the checker's verdict on that statement cannot be trusted; the error lists each one with the SQL and both descriptions. Put it in a test next to Start so the application carries the evidence that its static checks hold for the PostgreSQL it runs on.

type Statement

type Statement interface{ SQLTemplate() string }

Statement is what Verify accepts: sqlshape.Stmt and sqlshape.Single.

Jump to

Keyboard shortcuts

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