[DBD::Pg 1/2] Expose superuser status to tests.

[email protected] Sun, 4 Jan 2015 17:55:46 +0000
Newsgroups perl.dbd.pg.changes
Message-ID <[email protected]>
Committed by Greg Sabino Mullane <[email protected]>

Subject: [DBD::Pg 1/2] Expose superuser status to tests.

---
 t/dbdpg_test_setup.pl | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/t/dbdpg_test_setup.pl b/t/dbdpg_test_setup.pl
index bebd833..2846dc0 100644
--- a/t/dbdpg_test_setup.pl
+++ b/t/dbdpg_test_setup.pl
@@ -9,6 +9,8 @@ use Cwd;
 use 5.006;
 select(($|=1,select(STDERR),$|=1)[1]);
 
+my $superuser = 1;
+
 my $testfh;
 if (exists $ENV{TEST_OUTPUT}) {
 	my $file = $ENV{TEST_OUTPUT};
@@ -103,17 +105,21 @@ version: $version
 
 	## Did we fail last time? Fail this time too, but quicker!
 	if ($testdsn =~ /FAIL!/) {
+		$debug and diag 'Previous failure detected';
 		return $helpconnect, "Previous failure ($error)", undef;
 	}
 
 	## We may want to force an initdb call
 	if (!$helpconnect and $ENV{DBDPG_TESTINITDB}) {
+		$debug and diag 'Jumping to INITDB';
 		goto INITDB;
 	}
 
 	## Got a working DSN? Give it an attempt
 	if ($testdsn and $testuser) {
 
+		$debug and diag "Trying with $testuser and $testdsn";
+
 		## Used by t/01connect.t
 		if ($arg->{dbreplace}) {
 			$testdsn =~ s/$alias\s*=/$arg->{dbreplace}=/;
@@ -128,6 +134,8 @@ version: $version
 			1;
 		};
 
+		$debug and diag "Connection failed: $@";
+
 		if ($@ =~ /invalid connection option/ or $@ =~ /dbbarf/) {
 			return $helpconnect, $@, undef;
 		}
@@ -641,13 +649,16 @@ version: $version
 	$ENV{DBI_DSN} = $testdsn;
 	$ENV{DBI_USER} = $testuser;
 
+	$debug and diag "Got a database handle ($dbh)";
+
 	if ($arg->{quickreturn}) {
+		$debug and diag 'Returning via quickreturn';
 		return $helpconnect, '', $dbh;
 	}
 
 	my $SQL = 'SELECT usesuper FROM pg_user WHERE usename = current_user';
-	my $bga = $dbh->selectall_arrayref($SQL)->[0][0];
-	if ($bga) {
+	$superuser = $dbh->selectall_arrayref($SQL)->[0][0];
+	if ($superuser) {
 		$dbh->do(q{SET LC_MESSAGES = 'C'});
 	}
 
@@ -657,11 +668,13 @@ version: $version
 	}
 	else {
 
+		$debug and diag 'Attempting to cleanup database';
 		cleanup_database($dbh);
 
 		eval {
 			$dbh->do("CREATE SCHEMA $S");
 		};
+		$@ and $debug and diag "Create schema error: $@";
 		if ($@ =~ /Permission denied/ and $helpconnect != 16) {
 			## Okay, this ain't gonna work, let's try initdb
 			goto INITDB;
@@ -709,6 +722,12 @@ return $helpconnect, '', $dbh;
 } ## end of connect_database
 
 
+sub is_super {
+
+	return $superuser;
+
+}
+
 sub find_tempdir {
 
 	if (eval { require File::Temp; 1; }) {
-- 
1.8.4