Allow use of custom PG_CTL, make sure we create test user.
authorGreg Sabino Mullane <[email protected]>
Fri, 24 Apr 2009 22:45:57 +0000 (18:45 -0400)
committerGreg Sabino Mullane <[email protected]>
Fri, 24 Apr 2009 22:45:57 +0000 (18:45 -0400)
t/CP_Testing.pm

index bf8b1a63167103e396e06b4b022d55a7e28d201e..20cbb24d115f07c87c9d8a2ce80a6d3ee21ba8f1 100644 (file)
@@ -119,7 +119,9 @@ sub test_database_handle {
 
                unlink $logfile;
 
-               $com = qq{LC_ALL=en LANG=C pg_ctl -o '-k socket' -l $logfile -D "$dbdir/data" start};
+               my $pg_ctl = $ENV{PG_CTL} || 'pg_ctl';
+
+               $com = qq{LC_ALL=en LANG=C $pg_ctl -o '-k socket' -l $logfile -D "$dbdir/data" start};
                eval {
                        $info = qx{$com};
                };
@@ -155,7 +157,19 @@ sub test_database_handle {
        my $dsn = qq{dbi:Pg:host=$dbhost;dbname=$self->{dbname}};
        my $dbuser = $self->{testuser};
        my @superdsn = ($dsn, $dbuser, '', {AutoCommit=>0,RaiseError=>1,PrintError=>0});
-       my $dbh = DBI->connect(@superdsn);
+       my $dbh;
+       eval {
+               $dbh = DBI->connect(@superdsn);
+       };
+       if ($@) {
+               if ($@ =~ /role .+ does not exist/) {
+                       my @tempdsn = ($dsn, '', '', {AutoCommit=>1,RaiseError=>1,PrintError=>0});
+                       my $tempdbh = DBI->connect(@tempdsn);
+                       $tempdbh->do("CREATE USER $dbuser SUPERUSER");
+                       $tempdbh->disconnect();
+                       $dbh = DBI->connect(@superdsn);
+               }
+       }
        $dbh->ping() or die qq{Failed to ping!\n};
 
        $dbh->{AutoCommit} = 1;