Permalink
Browse files

adjust testing of PgPir driver (not working yet)

  • Loading branch information...
Martin Berends
Martin Berends committed Jul 1, 2010
1 parent 84a45aa commit db65fed0acd72a5bd62975e5bfe18ad7d950c59c
Showing with 104 additions and 31 deletions.
  1. +7 −1 lib/MiniDBD/PgPir.pm6
  2. +1 −0 lib/MiniDBI.pm6
  3. +43 −0 t/30-PgPir-common.t
  4. +53 −0 t/30-PgPir-specific.t
  5. +0 −30 t/30-pgpir.t
View
@@ -35,6 +35,8 @@ class MiniDBD::PgPir::Connection does MiniDBD::Connection {
class MiniDBD::PgPir:auth<moritz> {
+ has $.Version = 0.01;
+
sub pg_escape($x) {
q[']
~ $x.subst(rx/\\|\'/, -> $m { '\\' ~ $m }, :g)
@@ -44,20 +46,24 @@ class MiniDBD::PgPir:auth<moritz> {
method connect(Str $user, Str $password, Str $params, $RaiseError) {
my $pg = pir::new__pS('Pg');
- my %params = $params.split(';').map({ .split(rx{\s*\=\s*}, 2)}).flat;
+ my %params = $params.split(';').map({ .split(regex {\s*\=\s*}, 2)}).flat;
my %opt =
user => pg_escape($user),
password => pg_escape($password),
+# user => $user,
+# password => $password,
%params;
%opt<application_name> //= 'Perl6MiniDBD';
say "Options: %opt.perl()";
# nearly scary how concise this is in Perl 6 :-)
my $connection_string = %opt.fmt('%s=%s', ';');
+ say "Connection string: $connection_string";
my $con = $pg.connectdb($connection_string);
+ say "con: $con";
}
method finish() {
View
@@ -27,6 +27,7 @@ class MiniDBI:auth<mberends>:ver<0.1.0> {
given $drivername {
when 'CSV' { eval 'use MiniDBD::CSV; $driver = MiniDBD::CSV.new()' }
when 'mysql' { eval 'use MiniDBD::mysql; $driver = MiniDBD::mysql.new()' }
+ when 'PgPir' { eval 'use MiniDBD::PgPir; $driver = MiniDBD::PgPir.new()' }
default { die "driver name '$drivername' is not known"; }
}
return $driver;
View
@@ -0,0 +1,43 @@
+# MiniDBI/t/30-PgPir-common.t
+use v6;
+use Test;
+use MiniDBI;
+
+# Define the only database specific values used by the common tests.
+my ( $mdriver, $test_dsn, $test_user, $test_password );
+{
+ # Define values that are relevant only to MySQL
+ my $hostname = 'localhost';
+ my $database = 'zavolaj';
+ # Set up the common variables with the MySQL specific values
+ $mdriver = 'PgPir';
+ $test_dsn = "MiniDBI:$mdriver" ~ ":database=$database;"
+ ~ "host=$hostname";
+ $test_user = 'testuser';
+ $test_password = 'testpass';
+}
+
+# Detect and report possible errors from eval of the common test script
+warn $! if "ok 99-common.pl6" ne eval slurp 't/99-common.pl6';
+
+=begin pod
+
+=head1 PREREQUISITES
+Your system should already have libpq-dev installed. Change to the
+postgres user and connect to the postgres server as follows:
+
+ sudo -u postgres psql
+
+Then set up a test environment with the following:
+
+ CREATE DATABASE zavolaj;
+ CREATE ROLE testuser LOGIN PASSWORD 'testpass';
+ GRANT ALL PRIVILEGES ON DATABASE zavolaj TO testuser;
+
+The '\l' psql command output should include zavolaj as a database name.
+Exit the psql client with a ^D, then try to use the new account:
+
+ psql --host=localhost --dbname=zavolaj --username=testuser --password
+ SELECT * FROM pg_database;
+
+=end pod
View
@@ -0,0 +1,53 @@
+use v6;
+use Test;
+plan *;
+
+use MiniDBI;
+
+my $mdriver = 'PgPir';
+my $host = 'localhost';
+my $port = 5432;
+my $database = 'testdb';
+my $user = 'testuser';
+my $password = 'testpass';
+# my $password = 'Cho5thae';
+
+my $test_dsn = "FakeDBI:{$mdriver}:dbname=$database;host=$host;port=$port";
+
+my $drh = MiniDBI.install_driver($mdriver);
+ok $drh, 'Install driver';
+
+my $dbh;
+lives_ok { $dbh = MiniDBI.connect($test_dsn, $user, $password,
+ RaiseError => 1, PrintError => 1, AutoCommit => 1) },
+ 'Connecting lives';
+
+ok defined($dbh), 'DBH is defined';
+ok $dbh, 'DBH is true';
+# lives_ok { $dbh.finish }, 'Can finish DBH';
+#nok $dbh, 'finished DBH is false';
+
+
+done_testing;
+
+=begin pod
+
+=head1 PREREQUISITES
+Your system should already have libpq-dev installed. Change to the
+postgres user and connect to the postgres server as follows:
+
+ sudo -u postgres psql
+
+Then set up a test environment with the following:
+
+ CREATE DATABASE testdb;
+ CREATE ROLE testuser LOGIN PASSWORD 'testpass';
+ GRANT ALL PRIVILEGES ON DATABASE testdb TO testuser;
+
+The '\l' psql command output should include testdb as a database name.
+Exit the psql client with a ^D, then try to use the new account:
+
+ psql --host=localhost --dbname=testdb --username=testuser --password
+ SELECT * FROM pg_database;
+
+=end pod
View
@@ -1,30 +0,0 @@
-use v6;
-use Test;
-plan *;
-
-use MiniDBI;
-
-my $mdriver = 'PgPir';
-my $host = 'localhost';
-my $port = 5432;
-my $database = 'testdb';
-my $user = 'testuser';
-my $password = 'Cho5thae';
-
-my $test_dsn = "FakeDBI:{$mdriver}:dbname=$database;host=$host;port=$port";
-
-my $drh = MiniDBI.install_driver($mdriver);
-ok $drh, 'Install driver';
-
-my $dbh;
-lives_ok { $dbh = MiniDBI.connect($test_dsn, $user, $password,
- RaiseError => 1, PrintError => 1, AutoCommit => 1) },
- 'Connecting lives';
-
-ok defined($dbh), 'DBH is defined';
-ok $dbh, 'DBH is true';
-# lives_ok { $dbh.finish }, 'Can finish DBH';
-#nok $dbh, 'finished DBH is false';
-
-
-done_testing;

0 comments on commit db65fed

Please sign in to comment.