Test various database integrity questions.
This new section of tests verifies that when the database disappears underneath or has other types of problems that the API still functions as expected. The second test committed herein currently fails.
This commit is contained in:
parent
6bbb59c36a
commit
6b8d79553b
2 changed files with 39 additions and 4 deletions
|
@ -37,5 +37,12 @@ sub get_test_dbh {
|
|||
die $dbh->errstr if $dbh->errstr;
|
||||
return $dbh;
|
||||
}
|
||||
sub reopen_test_dbh {
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=test-supporters.db", "", "",
|
||||
{ RaiseError => 1, sqlite_unicode => 1})
|
||||
or die $DBI::errstr;
|
||||
|
||||
return $dbh;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More tests => 53;
|
||||
use Test::More tests => 55;
|
||||
use Test::Exception;
|
||||
|
||||
use Scalar::Util qw(looks_like_number);
|
||||
|
@ -238,15 +238,43 @@ dies_ok { $sp->_verifyId("String") } "_verifyId: dies for non-numeric id";
|
|||
# This is a hacky way to test this; but should work
|
||||
ok(not ($sp->_verifyId($drapperId + 10)), "_verifyId: non-existent id is not found");
|
||||
|
||||
=pod
|
||||
|
||||
=back
|
||||
|
||||
=item Database weirdness tests
|
||||
|
||||
=cut
|
||||
|
||||
sub ResetDB($) {
|
||||
$_[0]->disconnect() if defined $_[0];
|
||||
my $tempDBH = get_test_dbh();
|
||||
my $tempSP = new Supporters($tempDBH, "testcmd");
|
||||
return ($tempDBH, $tempSP);
|
||||
}
|
||||
|
||||
my($tempDBH, $tempSP) = ResetDB($dbh);
|
||||
$tempDBH->do("DROP TABLE email_address;");
|
||||
|
||||
dies_ok { $tempSP->addSupporter({ display_name => "Roger Sterling",
|
||||
public_ack => 0, ledger_entity_id => "Sterling-Roger",
|
||||
email_address => 'sterlingjr@example.com',
|
||||
email_address_type => 'home' }) }
|
||||
"addSupporter: dies when email_address table does not exist & email adress given";
|
||||
|
||||
$tempDBH = reopen_test_dbh();
|
||||
|
||||
$val = $tempDBH->selectall_hashref("SELECT id FROM supporter;", 'id');
|
||||
|
||||
ok( (defined $val and keys(%{$val}) == 0),
|
||||
"addSupporter: fails if email_address given but email cannot be inserted");
|
||||
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
$dbh->disconnect();
|
||||
$tempDBH->disconnect;
|
||||
|
||||
1;
|
||||
###############################################################################
|
||||
#
|
||||
# Local variables:
|
||||
|
|
Loading…
Reference in a new issue