Documentation
¶
Overview ¶
Package pgtest runs a throwaway PostgreSQL server for one test binary.
A suite that claims to hold on PostgreSQL has to have run on PostgreSQL. So this finds the server binaries installed on the machine, makes a cluster in a fresh temporary directory, and starts it listening on a Unix socket in that directory and nowhere else. Nothing is mocked and nothing is shared with another run.
When a machine has no server to find, Start says so instead of failing: a suite reports the backend it did not reach by name, which is a fact a reader can act on, and still runs everything else.
A store built on orm/tenant runs its own tests on both engines with this — start one server in TestMain, make its login with tenant.Provision, and open the store on a schema of the test's own:
func TestMain(m *testing.M) {
pg, why = pgtest.Start()
code := m.Run()
if pg != nil {
pg.Stop()
}
os.Exit(code)
}
Index ¶
Constants ¶
const Super = "postgres"
Super is the cluster's superuser. Tests use it only to make roles and databases; a statement under test never runs as it, because a superuser ignores row-level security and would prove nothing.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
// Major is the server's major version.
Major int
// contains filtered or unexported fields
}
Server is one running cluster.
func Start ¶
Start makes and starts a cluster from the newest PostgreSQL on this machine. It returns the reason instead when there is none, or when it will not start.