NAME
Test::PostgreSQL - PostgreSQL runner for tests
SYNOPSIS
use DBI;
use Test::PostgreSQL;
use Test::More;
my $pgsql = Test::PostgreSQL->new()
or plan skip_all => $Test::PostgreSQL::errstr;
plan tests => XXX;
my $dbh = DBI->connect($pgsql->dsn);
DESCRIPTION
Test::PostgreSQL
automatically setups a PostgreSQL instance in a temporary directory, and destroys it when the perl script exits.
This module is a fork of Test::postgresql, which was abandoned by its author several years ago.
FUNCTIONS
new
Create and run a PostgreSQL instance. The instance is terminated when the returned object is being DESTROYed. If required programs (initdb and postmaster) were not found, the function returns undef and sets appropriate message to $Test::PostgreSQL::errstr.
base_dir
Returns directory under which the PostgreSQL instance is being created. The property can be set as a parameter of the new
function, in which case the directory will not be removed at exit.
initdb
postmaster
Path to initdb
and postmaster
which are part of the PostgreSQL distribution. If not set, the programs are automatically searched by looking up $PATH and other prefixed directories.
initdb_args
postmaster_args
Arguments passed to initdb
and postmaster
. Following example adds --encoding=utf8 option to initdb_args
.
my $pgsql = Test::PostgreSQL->new(
initdb_args
=> $Test::PostgreSQL::Defaults{initdb_args} . ' --encoding=utf8'
) or plan skip_all => $Test::PostgreSQL::errstr;
dsn
Builds and returns dsn by using given parameters (if any). Default username is 'postgres', and dbname is 'test' (an empty database).
pid
Returns process id of PostgreSQL (or undef if not running).
port
Returns TCP port number on which postmaster is accepting connections (or undef if not running).
start
Starts postmaster.
stop
Stops postmaster.
setup
Setups the PostgreSQL instance.
AUTHOR
Toby Corkindale
PREVIOUS AUTHOR
Kazuho Oku
COPYRIGHT
Version 0.10 copyright © 2012 Toby Corkindale.
Previous versions copyright (C) 2009 Cybozu Labs, Inc.
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.