Test::Postgresql58 - PostgreSQL runner for tests
use DBI; use Test::Postgresql58; use Test::More; # optionally # (if not already set at shell): # # $ENV{POSTGRES_HOME} = '/path/to/my/pgsql/installation'; my $pgsql = Test::Postgresql58->new() or plan skip_all => $Test::Postgresql58::errstr; plan tests => XXX; my $dbh = DBI->connect($pgsql->dsn);
Test::Postgresql58 automatically setups a PostgreSQL instance in a temporary directory, and destroys it when the perl script exits.
Test::Postgresql58
This module is a fork of Test::PostgreSQL, to retain support for Perl 5.8 and other scenarios. This is intended to be a lightly maintained module designed to support the existing projects that used Test::Postgresql or Test::PostgreSQL. If you believe there is a fundamental design problem with this module start a new one or contribute to an alternative existing module. The primary motivation for this fork is simply to avoid changes to existing modules (except the module name change).
Bug fixes, and fixes to ensure it continues to work with newer versions of Postgres should still be welcome.
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::Postgresql58::errstr.
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.
new
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
postmaster
Arguments passed to initdb and postmaster. Following example adds --encoding=utf8 option to initdb_args.
initdb_args
my $pgsql = Test::Postgresql58->new( initdb_args => $Test::Postgresql58::Defaults{initdb_args} . ' --encoding=utf8' ) or plan skip_all => $Test::Postgresql58::errstr;
Builds and returns dsn by using given parameters (if any). Default username is 'postgres', and dbname is 'test' (an empty database).
Builds and returns a connection URI using the given parameters (if any). See URI::db for details about the format.
Default username is 'postgres', and dbname is 'test' (an empty database).
Returns process id of PostgreSQL (or undef if not running).
Returns TCP port number on which postmaster is accepting connections (or undef if not running).
Starts postmaster.
Stops postmaster.
Setups the PostgreSQL instance.
If your postgres installation is not located in a well known path, or you have many versions installed and want to run your tests against particular one, set this environment variable to the desired path. For example:
export POSTGRES_HOME='/usr/local/pgsql94beta'
This is the same idea and variable name which is used by the installer of DBD::Pg.
Colin Newell, Toby Corkindale, Kazuho Oku, and various contributors.
Current version copyright © 2016 Colin Newell
Previous versions copyright © 2012-2014 Toby Corkindale.
Previous versions copyright (C) 2009 Cybozu Labs, Inc.
This module is free software, released under the Perl Artistic License 2.0. See http://www.perlfoundation.org/artistic_license_2_0 for more information.
To install Test::Postgresql58, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Postgresql58
CPAN shell
perl -MCPAN -e shell install Test::Postgresql58
For more information on module installation, please visit the detailed CPAN module installation guide.