[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[3417] trunk/t/89-dropdb.t



Revision: 3417
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3417&view=rev
Author:   einhverfr
Date:     2011-07-03 09:59:43 +0000 (Sun, 03 Jul 2011)

Log Message:
-----------
t/89-dropdb.t tests now leave installation clean

Modified Paths:
--------------
    trunk/t/89-dropdb.t

Modified: trunk/t/89-dropdb.t
===================================================================
--- trunk/t/89-dropdb.t	2011-07-03 08:21:06 UTC (rev 3416)
+++ trunk/t/89-dropdb.t	2011-07-03 09:59:43 UTC (rev 3417)
@@ -1,6 +1,7 @@
 use Test::More;
 use strict;
-
+use DBI;
+    
 my $temp = $ENV{TEMP} || '/tmp/';
 my $run_tests = 6;
 for my $evar (qw(LSMB_NEW_DB LSMB_TEST_DB PG_CONTRIB_DIR)){
@@ -10,14 +11,16 @@
   }
 }
 if ($ENV{LSMB_INSTALL_DB}){
+   $run_tests = 0;
    plan skip_all => 'LSMB_INSTALL_DB SET';
 }
 
 if ($run_tests){
-	plan tests => 6;
+	plan tests => $run_tests;
 	$ENV{PGDATABASE} = $ENV{LSMB_NEW_DB};
 }
 
+print STDERR "tests to run: $run_tests\n";
 ok(open (DBLOCK, '<', "$temp/LSMB_TEST_DB"), 'Opened db lock file');
 my $db = <DBLOCK>;
 chomp($db);
@@ -26,15 +29,24 @@
 ok(close (DBLOCK), 'Closed db lock file');
 ok(unlink ("$temp/LSMB_TEST_DB"), 'Removed test db lockfile');
 
-# We clean up the test DB roles.
-open (PSQL, '|-', "psql");
 
-(open (ROLES, '<', 'sql/modules/test/Drop_Roles.sql') && pass("Roles description found"))
-|| fail("Roles description found");
+my $dbh = DBI->connect("dbi:Pg:dbname=template1",
+                                       undef, undef, { AutoCommit => 0 });
 
-for my $roleline (<ROLES>){
-        $roleline =~ s/<\?lsmb dbname \?>/$ENV{LSMB_NEW_DB}/;
-            print PSQL $roleline;
-        }
+my $sth_getroles = $dbh->prepare(
+                           "select quote_ident(rolname) as role 
+                              FROM pg_roles 
+                             WHERE rolname LIKE ?");
 
-close (PSQL);
+$sth_getroles->execute("lsmb_$ENV{LSMB_NEW_DB}__%");
+
+my $rc = 0;
+while (my $ref = $sth_getroles->fetchrow_hashref('NAME_lc')){
+    print STDERR "Dropping role $ref->{role}\n";
+    $dbh->do("drop role ".$ref->{role}) || ++$rc;
+}
+
+$dbh->commit;
+
+is($rc, 0, 'Roles dropped');
+


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.