Documentation
¶
Overview ¶
Package postgrestest creates a temporary Postgres instance. Tests should call New(). Other code should call NewInstance() or NewInstanceWithOptions().
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New creates a new Postgres instance and returns a connection string URL in the form "postgresql:..." to connect to using sql.Open(). After the test completes, the Postgres instance will be shut down. New will call t.Fatal if an error happens initializing Postgres. See NewInstanceWithOptions for more details.
Types ¶
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance contains the state of a new temporary Postgres instance.
func NewInstance ¶
NewInstance calls NewInstanceWithOptions() with the default options. The caller must call Close() to ensure it is stopped and the temporary space is deleted. Tests should prefer to call New().
func NewInstanceWithOptions ¶
NewInstanceWithOptions creates a new Postgres instance in a temporary directory. The caller must call Close() to ensure it is stopped and the temporary space is deleted. Tests should prefer to call New().
Postgres will use the "C" locale to ensure that tests don't depend on the local environment.
func (*Instance) BinPath ¶
BinPath returns the absolute path to commandName in the Postgres binary directory.
func (*Instance) LocalhostURL ¶
LocalhostURL returns the Postgres connection URL using a localhost IP address. This will only work if using Options.ListenOnLocalhost=true. Most callers should use URL() instead.
func (*Instance) RemoteURL ¶
RemoteURL returns the first Postgres connection URL using an IP address that is not localhost. This will only work if using Options.InsecureGlobalPort is set. Most callers should use URL() instead.
func (*Instance) RemoteURLForAddress ¶
func (*Instance) URL ¶
URL returns the Postgres connection URL using a Unix socket in the form "postgresql://...". See: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
type Options ¶
type Options struct { // If true, Postgres will listen on localhost for network connections. ListenOnLocalhost bool // If not nil, verbose information will be logged. Logger *slog.Logger // If not 0, listen globally on InsecureGlobalPort. This is insecure because it will allow // connections from any IP address, although it generates and requires a password. The default // Postgres port is 5432. When setting InsecureGlobalPort, leave ListenOnLocalhost=false: this // option will listen on localhost addresses as well. InsecureGlobalPort int // https://www.postgresql.org/docs/current/runtime-config-resource.html SharedBuffers int // Create or use Postgres in this directory. If empty, it will create a temporary directory // that will be deleted when done. If this is set, the directory will not be deleted. DirPath string }
Options configures the Postgres instance.