Better 'list tables' display, tweak the tests.
authorGreg Sabino Mullane <greg@endpoint.com>
Wed, 30 Nov 2011 15:50:40 +0000 (10:50 -0500)
committerGreg Sabino Mullane <greg@endpoint.com>
Wed, 30 Nov 2011 15:50:40 +0000 (10:50 -0500)
bucardo
t/02-bctl-table.t

diff --git a/bucardo b/bucardo
index 8d9d29d1e0c4c89466f7caec39402baf09267ae5..c8df062489673598237dfb5eb527f4b06167575f 100755 (executable)
--- a/bucardo
+++ b/bucardo
@@ -3640,7 +3640,7 @@ sub list_tables {
     }
 
     ## Figure out the length of each item for a pretty display
-    my ($maxid,$maxname,$maxdb) = (1,1,1);
+    my ($maxid,$maxname,$maxdb,$maxpk) = (1,1,1,1);
     for my $row (values %$TABLE) {
         my $id = $row->{id};
         next if @nouns and ! exists $matchtable{$id};
@@ -3648,23 +3648,28 @@ sub list_tables {
         my $name = "$row->{schemaname}.$row->{tablename}";
         $maxname = length $name if length $name > $maxname;
         $maxdb = length $row->{db} if length $row->{db} > $maxdb;
+        $row->{ppk} = $row->{pkey} ? "$row->{pkey} ($row->{pkeytype})" : 'none';
+        $maxpk = length $row->{ppk} if length $row->{ppk} > $maxpk;
     }
     ## Now do the actual printing
     ## Sort by schemaname then tablename
-    for my $row (sort {
-        $a->{schemaname} cmp $b->{schemaname}
-        or
-        $a->{tablename} cmp $b->{tablename}
-        } values %$TABLE) {
+    for my $row (sort numbered_relations values %$TABLE) {
         next if @nouns and ! exists $matchtable{$row->{id}};
-        printf '%-*s Table: %-*s  Database: %-*s',
+        printf '%-*s Table: %-*s  DB: %-*s  PK: %-*s',
             1+$maxid, "$row->{id}.",
             $maxname, "$row->{schemaname}.$row->{tablename}",
-            $maxdb, $row->{db};
+            $maxdb, $row->{db},
+            $maxpk, $row->{ppk};
         if ($row->{sync}) {
-            printf ' Syncs: ';
+            printf '  Syncs: ';
             print join ',' => sort keys %{ $row->{sync} };
         }
+        if (defined $row->{ping}) {
+            printf '  ping:%s', $row->{ping} ? 'true' : 'false';
+        }
+        if ($row->{rebuild_index}) {
+            print '  rebuild_index:true';
+        }
         print "\n";
 
         $VERBOSE >= 2 and show_all_columns($row);
index fa2211d5dc6179bb8d52cf0208473604b80ce4f8..25d14aeac867cc6954a409a3baade44817db4223 100644 (file)
@@ -131,20 +131,20 @@ is ($res, qq{$addtable_msg:\n  public.bucardo_test10\n}, $t);
 $t = q{'bucardo list tables' returns expected result};
 $res = $bct->ctl('bucardo list tables');
 $expected =
-q{Table: public.bucardo_test1   DB: A  PK: id (int2)
-Table: public.bucardo_test2   DB: A  PK: id|data1 (int4|text)
-Table: public.bucardo_test3   DB: A  PK: id (int8)
-Table: public.bucardo_test4   DB: A  PK: id (text)
-Table: public.bucardo_test5   DB: A  PK: id space (date)
-Table: public.bucardo_test6   DB: A  PK: id (timestamp)
-Table: public.bucardo_test7   DB: A  PK: id (numeric)
-Table: public.bucardo_test8   DB: A  PK: id (bytea)
-Table: public.bucardo_test9   DB: A  PK: id (int_unsigned)
-Table: public.bucardo_test10  DB: A  PK: id (timestamptz)
-Table: public.droptest        DB: A  PK: none
-Table: tschema.bucardo_test3  DB: A  PK: none
+qr{\d+\.\s* Table: public.bucardo_test1   DB: A  PK: id \(int2\)\s+
+\d+\.\s* Table: public.bucardo_test2   DB: A  PK: id\|data1 \(int4\|text\)
+\d+\.\s* Table: public.bucardo_test3   DB: A  PK: id \(int8\)\s+
+\d+\.\s* Table: public.bucardo_test4   DB: A  PK: id \(text\)\s+
+\d+\.\s* Table: public.bucardo_test5   DB: A  PK: id space \(date\)\s+
+\d+\.\s* Table: public.bucardo_test6   DB: A  PK: id \(timestamp\)\s+
+\d+\.\s* Table: public.bucardo_test7   DB: A  PK: id \(numeric\)\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: tschema.bucardo_test3  DB: A  PK: none\s+
 };
-is ($res, $expected, $t);
+like ($res, $expected, $t);
 
 ## Remove them all, then try adding in various combinations
 empty_goat_table();
@@ -159,12 +159,12 @@ is ($res, qq{$addtable_msg:\n  public.bucardo_test4\n}, $t);
 $t = q{'bucardo list tables' returns expected result};
 $res = $bct->ctl('bucardo list tables');
 $expected =
-q{Table: public.bucardo_test1  DB: A  PK: id (int2)
-Table: public.bucardo_test2  DB: A  PK: id|data1 (int4|text)
-Table: public.bucardo_test4  DB: A  PK: id (text) ping:true
-Table: public.bucardo_test9  DB: A  PK: id (int_unsigned)
+qr{\d+\.\s* Table: public.bucardo_test1  DB: A  PK: id \(int2\)\s*
+\d+\.\s* Table: public.bucardo_test2  DB: A  PK: id\|data1 \(int4\|text\)\s*
+\d+\.\s* Table: public.bucardo_test4  DB: A  PK: id \(text\)\s* ping:true\s*
+\d+\.\s* Table: public.bucardo_test9  DB: A  PK: id \(int_unsigned\)\s*
 };
-is ($res, $expected, $t);
+like ($res, $expected, $t);
 
 $t = q{Add table works when specifying the rebuild_index and ping options};
 $res = $bct->ctl('bucardo add table bucardo_test5 ping=false rebuild_index=1');
@@ -173,13 +173,13 @@ is ($res, qq{$addtable_msg:\n  public.bucardo_test5\n}, $t);
 $t = q{'bucardo list tables' returns expected result};
 $res = $bct->ctl('bucardo list tables');
 $expected =
-q{Table: public.bucardo_test1  DB: A  PK: id (int2)
-Table: public.bucardo_test2  DB: A  PK: id|data1 (int4|text)
-Table: public.bucardo_test4  DB: A  PK: id (text) ping:true
-Table: public.bucardo_test5  DB: A  PK: id space (date) ping:false rebuild_index:1
-Table: public.bucardo_test9  DB: A  PK: id (int_unsigned)
+qr{\d+\.\s* Table: public.bucardo_test1  DB: A  PK: id \(int2\)\s*
+\d+\.\s* Table: public.bucardo_test2  DB: A  PK: id|data1 \(int4\|text\)\s*
+\d+\.\s* Table: public.bucardo_test4  DB: A  PK: id \(text\)\s* ping:true\s*
+\d+\.\s* Table: public.bucardo_test5  DB: A  PK: id space \(date\)\s* ping:false\s* rebuild_index:true\s*
+\d+\.\s* Table: public.bucardo_test9  DB: A  PK: id \(int_unsigned\)\s*
 };
-is ($res, $expected, $t);
+like ($res, $expected, $t);
 
 empty_goat_table();