[DBD::Pg] Add table_info() materialized view testing.
dbdpg-commits-gENoVmVU/[email protected] Sun, 27 Jul 2014 05:34:40 +0000
| Newsgroups | gmane.comp.db.postgresql.dbdpg.cvs |
|---|---|
| Message-ID | <[email protected]> |
Committed by Greg Sabino Mullane <greg-O9fzpki4YnJWk0Htik3J/[email protected]> Add table_info() materialized view testing. --- t/03dbmethod.t | 18 +++++++++++++++++- t/dbdpg_test_setup.pl | 11 +++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/t/03dbmethod.t b/t/03dbmethod.t index 108e0c5..ffcab48 100644 --- a/t/03dbmethod.t +++ b/t/03dbmethod.t @@ -26,7 +26,7 @@ my $dbh = connect_database(); if (! $dbh) { plan skip_all => 'Connection to database failed, cannot continue testing'; } -plan tests => 543; +plan tests => 545; isnt ($dbh, undef, 'Connect to database for database handle method testing'); @@ -539,6 +539,22 @@ $rows = $sth->rows(); cmp_ok ($rows, '<', $number, $t); cmp_ok ($rows, '>', 0, $t); +$t=q{DB handle method "table_info" returns correct number of rows when given a 'MATERIALIZED VIEW' type argument}; +$sth = $dbh->table_info(undef,undef,undef,'MATERIALIZED VIEW'); +$rows = $sth->rows(); +is ($rows, 0, $t); + +SKIP: { + if ($pgversion < 90300) { + skip 'Postgres version 9.3 or better required to create materialized views', 1; + } + $dbh->do('CREATE MATERIALIZED VIEW dbd_pg_matview (a) AS SELECT count(*) FROM pg_class'); + $t=q{DB handle method "table_info" returns correct number of rows when given a 'MATERIALIZED VIEW' type argument}; + $sth = $dbh->table_info(undef,undef,undef,'MATERIALIZED VIEW'); + $rows = $sth->rows(); + is ($rows, 1, $t); +} + # Test listing catalog names $t='DB handle method "table_info" works when called with a catalog of %'; $sth = $dbh->table_info('%', '', ''); diff --git a/t/dbdpg_test_setup.pl b/t/dbdpg_test_setup.pl index 6bae63c..e31ac55 100644 --- a/t/dbdpg_test_setup.pl +++ b/t/dbdpg_test_setup.pl @@ -17,6 +17,11 @@ if (exists $ENV{TEST_OUTPUT}) { Test::More->builder->todo_output($testfh); } +my @matviews = + ( + 'dbd_pg_matview', + ); + my @schemas = ( 'dbd_pg_testschema', @@ -796,6 +801,12 @@ sub cleanup_database { $dbh->rollback() if ! $dbh->{AutoCommit}; + for my $name (@matviews) { + my $schema = ($name =~ s/(.+)\.(.+)/$2/) ? $1 : $S; + next if ! relation_exists($dbh,$schema,$name); + $dbh->do("DROP MATERIALIZED VIEW $schema.$name"); + } + for my $name (@tables) { my $schema = ($name =~ s/(.+)\.(.+)/$2/) ? $1 : $S; next if ! relation_exists($dbh,$schema,$name); -- 1.8.4