pg

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package pg starts the throwaway Postgres the nova-config functional tests share, the way pkg/nsprint/testutil starts a throwaway Redis: initdb and pg_ctl from the binaries on PATH (or the well-known install directories, or NOVA_PG_BIN), a free loopback port, everything under the test's temporary directory, trust authentication, and the cleanup stops it. The process is private. It is not the fleet store, and this file names no bench address.

A runner without the binaries FAILS the test with one line naming the binary: no evidence is not negative evidence, and a skip here would let a green run be a run that never executed the store.

Index

Constants

View Source
const BinEnv = "NOVA_PG_BIN"

BinEnv names a directory holding initdb, pg_ctl and postgres, for a machine whose install is somewhere the search below does not look.

Variables

This section is empty.

Functions

func Binaries

func Binaries() (string, error)

Binaries finds initdb, pg_ctl and postgres: in NOVA_PG_BIN when set, else on PATH, else in the well-known directories. It returns the directory holding all three, or an error naming the first binary it could not find and where it looked.

Types

type Server

type Server struct {
	Dir  string
	Bin  string
	Port string
	// User is the superuser initdb made; trust authentication, no password.
	User string
	// contains filtered or unexported fields
}

Server is one running throwaway Postgres.

func Start

func Start(t testing.TB) *Server

Start is the per-test form: a server under t.TempDir(), stopped by the cleanup, its DSN returned. A missing binary fails the test with the line Binaries returns.

func StartServer

func StartServer(dir string) (*Server, error)

StartServer runs initdb and pg_ctl start under dir on a free loopback port. The caller stops it with Stop. It is the TestMain form: one server for a package, one database per test through Database.

func (*Server) DSN

func (s *Server) DSN(database string) string

DSN is the connection string of one database on the server, for pgx: a loopback address, trust authentication, no password anywhere.

func (*Server) Database

func (s *Server) Database(t testing.TB) string

Database creates a fresh, empty database on the server and returns its DSN. Each call is its own database, so parallel tests share the server and nothing else.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the server (immediate mode: nothing here is kept).

Jump to

Keyboard shortcuts

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