From 1e13c0c60c96dd1719e7c4c3931b4196c2b5bc61 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Fri, 30 Nov 2007 02:04:14 +0000 Subject: Initial work on supporting testing with MySQL. Add a drop() method to Wallet::Schema to destroy the wallet database. Add a test suite for it. Add a reinitialize() method to Wallet;:Server that drops the database before creating it. Modify the wallet object test cases to call reinitialize() to create the initial database and drop() to clean up the database after the test is complete. Fix a bug preventing Wallet::Schema from being initialized multiple times. We now stash the schema in a class static variable and reuse it for subsequent initializations, since re-reading DATA doesn't work. --- perl/t/schema.t | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'perl/t/schema.t') diff --git a/perl/t/schema.t b/perl/t/schema.t index 01b2b88..9e2d84f 100755 --- a/perl/t/schema.t +++ b/perl/t/schema.t @@ -8,7 +8,7 @@ # # See LICENSE for licensing terms. -use Test::More tests => 5; +use Test::More tests => 8; use DBI; use Wallet::Schema; @@ -31,5 +31,20 @@ $dbh->{PrintError} = 0; eval { $schema->create ($dbh) }; is ($@, '', "create() doesn't die"); +# Test dropping the database. +eval { $schema->drop ($dbh) }; +is ($@, '', "drop() doesn't die"); +my $sql = "select name from sqlite_master where type = 'table'"; +my $sth = $dbh->prepare ($sql); +$sth->execute; +my ($table, @tables); +while (defined ($table = $sth->fetchrow_array)) { + push (@tables, $table) unless $table =~ /^sqlite_/; +} +is ("@tables", '', ' and there are no tables in the database'); +eval { $schema->create ($dbh) }; +is ($@, '', ' and we can run create again'); + # Clean up. +eval { $schema->drop ($dbh) }; unlink 'wallet-db'; -- cgit v1.2.3