Enable testing of trigger and rule disabling again.
authorGreg Sabino Mullane <greg@endpoint.com>
Wed, 11 Mar 2015 03:18:20 +0000 (23:18 -0400)
committerGreg Sabino Mullane <greg@endpoint.com>
Wed, 11 Mar 2015 03:18:20 +0000 (23:18 -0400)
Very necessary as the trigger disabling code is about to be rewritten.

t/02-bctl-table.t
t/20-postgres.t
t/BucardoTesting.pm

index c31a9a7e3cfd61ee6b2a11ab337d260c0bf676d9..80dd12d25c7d0feb92b4df5a2c4a95e57f069d9d 100644 (file)
@@ -90,7 +90,7 @@ is ($res, qq{$addtable_msg:\n  public.bucardo_test5\n}, $t);
 
 $t = q{Add table works for a single valid ending wildcard entry};
 $res = $bct->ctl('bucardo add table drop%');
-is ($res, qq{$addtable_msg:\n  public.droptest\n}, $t);
+is ($res, qq{$addtable_msg:\n  public.droptest_bucardo\n}, $t);
 
 $t = q{Add table works for a single valid middle wildcard entry};
 $res = $bct->ctl('bucardo add table b%_test6');
@@ -142,7 +142,7 @@ qr{\d+\.\s* Table: public.Bucardo_test3       DB: A  PK: id \(bigint\)\s+
 \d+\.\s* Table: public.bucardo_test8       DB: A  PK: id \(bytea\)\s+
 \d+\.\s* Table: public.bucardo_test9       DB: A  PK: id \(int_unsigned\)\s+
 \d+\.\s* Table: public.bucardo_test10      DB: A  PK: id \(timestamptz\)\s+
-\d+\.\s* Table: public.droptest            DB: A  PK: none\s+
+\d+\.\s* Table: public.droptest_bucardo    DB: A  PK: none\s+
 \d+\.\s* Table: tschema.bucardo_test4      DB: A  PK: none\s+
 };
 like ($res, $expected, $t);
@@ -218,7 +218,7 @@ like ($res, qr{New tables added: 12\n}, $t);
 ## Remove them all, then try 'all tables' with exclude table
 empty_goat_table();
 $t = q{Add all tables with exclude table};
-$res = $bct->ctl('bucardo add all tables -T droptest -vv --debug');
+$res = $bct->ctl('bucardo add all tables -T droptest_bucardo -vv --debug');
 like ($res, qr{New tables added: 12}, $t);
 
 ## Remove them all, then try 'all tables' with exclude schema
index 631c3cc14167ec42084e85e679fe5eff5df83ba6..1e2e12da89e5a49971bd34ac7cbf374e02730dd8 100644 (file)
@@ -25,7 +25,7 @@ my $bct = BucardoTesting->new({location => 'postgres'})
 ## The above runs one test for each passed in database x the number of test tables
 my $numtables = keys %tabletype;
 my $numsequences = keys %sequences;
-my $single_tests = 61;
+my $single_tests = 62;
 my $check_for_row_1 = 1;
 my $check_for_row_2 = 2;
 my $check_for_row_3 = 3;
@@ -179,6 +179,10 @@ like ($res, qr/Added sync "msync"/, $t);
 ## Add a row to A, to make sure it does not go anywhere with inactive syncs
 $bct->add_row_to_database('A', 1);
 
+## Clean out the droptest table for later testing
+$dbhA->do('TRUNCATE TABLE droptest_bucardo');
+$dbhA->commit();
+
 sub d {
     my $msg = shift || '?';
     my $time = scalar localtime;
@@ -217,6 +221,17 @@ $SQL = 'SELECT inty FROM bucardo_test1_copy';
 $res = $dbhA->selectall_arrayref($SQL);
 is_deeply($res, [[1]], $t);
 
+## Make sure triggers and rules did not fire
+$SQL = 'SELECT * FROM droptest_bucardo';
+$sth = $dbhB->prepare($SQL);
+$count = $sth->execute();
+if ($count >= 1) {
+    diag Dumper $sth->fetchall_arrayref({});
+    BAIL_OUT "Found rows ($count) in the droptest table!";
+}
+$sth->finish();
+ok ('No rows found in the droptest table: triggers and rules were disabled');
+
 ## Switch to a 2 source sync
 is $bct->ctl('bucardo update sync pgtest1 status=inactive'), '', 'Set pgtest1 status=inactive';
 is $bct->ctl('bucardo update sync pgtest5 status=active'), '', 'Set pgtest5 status=active';
index 9bea12d3c45e9db262f4b2b15bd97fb7ceef5816..e2a9bf91bcb27643f5d2aacbc102a383713a47b1 100644 (file)
@@ -151,7 +151,7 @@ our %tabletypesqlite =
      );
 
 
-our @tables2empty = (qw/droptest/);
+our @tables2empty = (qw/droptest_bucardo/);
 
 our %sequences =
     (
@@ -749,13 +749,13 @@ sub add_test_schema {
     my ($tcount,$scount,$fcount) = (0,0,0);
 
     ## Empty out or create the droptest table
-    if (table_exists($dbh => 'droptest')) {
-        $dbh->do('TRUNCATE TABLE droptest');
+    if (table_exists($dbh => 'droptest_bucardo')) {
+        $dbh->do('TRUNCATE TABLE droptest_bucardo');
     }
     else {
         $tcount++;
         $dbh->do(q{
-            CREATE TABLE droptest (
+            CREATE TABLE droptest_bucardo (
               name TEXT NOT NULL,
               type TEXT NOT NULL
             )
@@ -776,7 +776,7 @@ sub add_test_schema {
                 RETURNS trigger
                 LANGUAGE plpgsql
                 AS $_$ BEGIN
-                INSERT INTO droptest(name,type)
+                INSERT INTO droptest_bucardo(name,type)
                     VALUES (TG_RELNAME, 'trigger');
                 RETURN NULL;
                 END;
@@ -790,7 +790,7 @@ sub add_test_schema {
                 RETURNS trigger
                 LANGUAGE plpgsql
                 AS $_$ BEGIN
-                INSERT INTO droptest(name,type)
+                INSERT INTO droptest_bucardo(name,type)
                     VALUES (TG_RELNAME, 'trigger');
                 RETURN NULL;
                 END;
@@ -849,7 +849,7 @@ sub add_test_schema {
         $SQL = qq{
             CREATE OR REPLACE RULE "bcrule_$table"
             AS ON INSERT TO "$table"
-            DO ALSO INSERT INTO droptest(name,type) VALUES ('$table','rule')
+            DO ALSO INSERT INTO droptest_bucardo(name,type) VALUES ('$table','rule')
             };
         $table =~ /0/ and $SQL =~ s/NEW.inty/0/;
         $dbh->do($SQL);