Activator
view release on metacpan or search on metacpan
#!perl
use warnings;
use strict;
use Test::More;
use Test::Exception;
use Data::Dumper;
use DBI;
BEGIN{
$ENV{ACT_REG_YAML_FILE} ||= "$ENV{PWD}/t/data/DB-test.yml";
}
if ( ! ( $ENV{ACT_DB_TEST_ENGINE} && (
( $ENV{ACT_DB_TEST_ENGINE} eq 'mysql' && $ENV{ACT_DB_TEST_USER} && $ENV{ACT_DB_TEST_PASSWORD} ) ||
( $ENV{ACT_DB_TEST_ENGINE} eq 'Pg' && $ENV{ACT_DB_TEST_USER} ) ) ) ) {
plan skip_all => q{
TO ENABLE Activator::DB tests you must set some environment variables as such:
a) set ACT_DB_TEST_ENGINE to "mysql", then set ACT_DB_TEST_USER
and ACT_DB_TEST_PASSWORD to user/password that can 'create database'
OR
b) set ACT_DB_TEST_ENGINE to "Pg", then set ACT_DB_TEST_USER
to a user that has passwordless access to psql and can 'create database'}
}
else {
plan tests => 68;
}
use Activator::DB;
use Activator::Registry;
use Activator::Exception;
my ($dbh, $db, $id, $res, @row, $rowref, $err);
# create test dbs, users, tables
if ( $ENV{ACT_DB_TEST_ENGINE} eq 'mysql' ) {
system( "cat $ENV{PWD}/t/data/DB-create-mysql-test.sql | mysql -u $ENV{ACT_DB_TEST_USER} -p$ENV{ACT_DB_TEST_PASSWORD}");
}
else {
system( "psql template1 $ENV{ACT_DB_TEST_USER} < $ENV{PWD}/t/data/DB-create-Pg-test.sql");
}
# connect/select the old skool way
my $mysql_dsn = 'DBI:mysql:act_db_test1:localhost';
my $pg_dsn = 'DBI:Pg:database=act_db_test1';
my $dsn = ( $ENV{ACT_DB_TEST_ENGINE} eq 'Pg' ? $pg_dsn : $mysql_dsn );
$dbh = DBI->connect( $dsn, $ENV{ACT_DB_TEST_USER}, $ENV{ACT_DB_TEST_PASSWORD} );
ok( !$@, 'test old skool: DBI->connect without $@');
ok( !$DBI::err, 'no $DBI::err');
ok( !$DBI::errstr, 'no $DBI::errstr');
ok( $dbh, 'got dbh with DBI');
lives_ok { $dbh->ping() } 'ping $dbh with DBI';
# make sure we can do the basics with DBI
@row = $dbh->selectrow_array( 'select * from t1' );
ok( $row[0] eq '1' && $row[1] eq 'd1_t1_r1_c1' && $row[2] eq 'd1_t1_r1_c2', 'can select row with DBI');
lives_ok { $dbh->disconnect() } 'disconnect $dbh with DBI';
################################################################################
#
# connnect to the default db
#
# set up all the connections proppa
Activator::Registry->register('Activator::DB->connections->test1_mysql->user', $ENV{ACT_DB_TEST_USER});
( run in 2.464 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )