Permalink
Browse files

fixed test suite when Test::Database not installed

  • Loading branch information...
barbie committed Nov 28, 2012
1 parent 6685861 commit 1de848ec3f3f363172847b75b89d4303d99e68fa
Showing with 108 additions and 92 deletions.
  1. +2 −2 t/05setup_db-uploads.t
  2. +29 −25 t/30reindex.t
  3. +25 −21 t/31generate.t
  4. +36 −32 t/32update.t
  5. +16 −12 t/33backup.t
View
@@ -6,12 +6,13 @@ use strict;
use CPAN::Testers::Common::DBUtils;
use File::Path;
-use File::Basename;
use Test::More;
#----------------------------------------------------------------------------
# Tests
+mkpath( 't/_DBDIR' );
+
eval "use Test::Database";
if($@) { plan skip_all => "Test::Database required for DB testing"; }
else { plan tests => 2 }
@@ -59,7 +60,6 @@ sub create_config {
# main config
my $f = 't/_DBDIR/test-config.ini';
unlink $f if -f $f;
- mkpath( dirname($f) );
my $dbcfg = join("\n", map { "$_=$options->{$_}" } grep { $options->{$_}} qw(driver database dbfile dbhost dbport dbuser dbpass) );
View
@@ -13,38 +13,42 @@ my @ROWS = (
my $config = 't/_DBDIR/test-config.ini';
my $idfile = 't/_DBDIR/lastid.txt';
-my $obj;
-eval { $obj = CPAN::Testers::Data::Uploads->new( config => $config, reindex => 1 ) };
-isa_ok($obj,'CPAN::Testers::Data::Uploads');
-
SKIP: {
- skip "Problem creating object", 8 unless($obj);
+ skip "Test::Database required for DB testing", 9 unless(-f $config);
+
+ my $obj;
+ eval { $obj = CPAN::Testers::Data::Uploads->new( config => $config, reindex => 1 ) };
+ isa_ok($obj,'CPAN::Testers::Data::Uploads');
- my $dbh = $obj->uploads;
- ok($dbh);
+ SKIP: {
+ skip "Problem creating object", 8 unless($obj);
- my @rows = $dbh->get_query('hash','select count(*) as count from uploads');
- is($rows[0]->{count}, 63, "row count for uploads");
- @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
- is($rows[0]->{count}, 0, "row count for ixlatest");
+ my $dbh = $obj->uploads;
+ ok($dbh);
- $obj->process;
+ my @rows = $dbh->get_query('hash','select count(*) as count from uploads');
+ is($rows[0]->{count}, 63, "row count for uploads");
+ @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
+ is($rows[0]->{count}, 0, "row count for ixlatest");
- @rows = $dbh->get_query('hash','select count(*) as count from uploads');
- is($rows[0]->{count}, 63, "row count for uploads");
- @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
- is($rows[0]->{count}, 17, "row count for ixlatest");
- @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','Acme-CPANAuthors-Japanese');
- is($rows[0]->{version}, '0.090101', "old index version");
+ $obj->process;
- # a few extras
- insert_records($dbh,\@ROWS);
- $obj->process;
+ @rows = $dbh->get_query('hash','select count(*) as count from uploads');
+ is($rows[0]->{count}, 63, "row count for uploads");
+ @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
+ is($rows[0]->{count}, 17, "row count for ixlatest");
+ @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','Acme-CPANAuthors-Japanese');
+ is($rows[0]->{version}, '0.090101', "old index version");
- @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
- is($rows[0]->{count}, 17, "row count for ixlatest");
- @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','Acme-CPANAuthors-Japanese');
- is($rows[0]->{version}, '0.090202', "new index version");
+ # a few extras
+ insert_records($dbh,\@ROWS);
+ $obj->process;
+
+ @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
+ is($rows[0]->{count}, 17, "row count for ixlatest");
+ @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','Acme-CPANAuthors-Japanese');
+ is($rows[0]->{version}, '0.090202', "new index version");
+ }
}
sub insert_records {
View
@@ -9,31 +9,35 @@ use Test::More tests => 7;
my $config = 't/_DBDIR/test-config.ini';
my $idfile = 't/_DBDIR/lastid.txt';
-my $obj;
-eval { $obj = CPAN::Testers::Data::Uploads->new( config => $config, generate => 1 ) };
-isa_ok($obj,'CPAN::Testers::Data::Uploads');
-
SKIP: {
- skip "Problem creating object", 6 unless($obj);
+ skip "Test::Database required for DB testing", 7 unless(-f $config);
+
+ my $obj;
+ eval { $obj = CPAN::Testers::Data::Uploads->new( config => $config, generate => 1 ) };
+ isa_ok($obj,'CPAN::Testers::Data::Uploads');
+
+ SKIP: {
+ skip "Problem creating object", 6 unless($obj);
- my $dbh = $obj->uploads;
- ok($dbh);
+ my $dbh = $obj->uploads;
+ ok($dbh);
- # clean DB
- $dbh->do_query('DELETE FROM uploads');
- $dbh->do_query('DELETE FROM ixlatest');
+ # clean DB
+ $dbh->do_query('DELETE FROM uploads');
+ $dbh->do_query('DELETE FROM ixlatest');
- my @rows = $dbh->get_query('hash','select count(*) as count from uploads');
- is($rows[0]->{count}, 0, "row count for uploads");
- @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
- is($rows[0]->{count}, 0, "row count for ixlatest");
+ my @rows = $dbh->get_query('hash','select count(*) as count from uploads');
+ is($rows[0]->{count}, 0, "row count for uploads");
+ @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
+ is($rows[0]->{count}, 0, "row count for ixlatest");
- $obj->process;
+ $obj->process;
- @rows = $dbh->get_query('hash','select count(*) as count from uploads');
- is($rows[0]->{count}, 63, "row count for uploads");
- @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
- is($rows[0]->{count}, 17, "row count for ixlatest");
- @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','Acme-CPANAuthors-Japanese');
- is($rows[0]->{version}, '0.090101', "old index version");
+ @rows = $dbh->get_query('hash','select count(*) as count from uploads');
+ is($rows[0]->{count}, 63, "row count for uploads");
+ @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
+ is($rows[0]->{count}, 17, "row count for ixlatest");
+ @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','Acme-CPANAuthors-Japanese');
+ is($rows[0]->{version}, '0.090101', "old index version");
+ }
}
View
@@ -44,39 +44,43 @@ my %articles = (
4 => 't/nntp/34358.txt',
);
-my $obj;
-eval { $obj = CPAN::Testers::Data::Uploads->new( config => $config, update => 1 ) };
-isa_ok($obj,'CPAN::Testers::Data::Uploads');
-
SKIP: {
- skip "Problem creating object", 11 unless($obj);
-
- my $dbh = $obj->uploads;
- ok($dbh);
-
- is(lastid(),0,'.. lastid is 0 from start');
-
- my @rows = $dbh->get_query('hash','select count(*) as count from uploads');
- is($rows[0]->{count}, 63, "row count for uploads");
- @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
- is($rows[0]->{count}, 17, "row count for ixlatest");
-
- $obj->process;
-
- is(lastid(),72870,'.. lastid is updated after process');
-
- @rows = $dbh->get_query('hash','select count(*) as count from uploads');
- is($rows[0]->{count}, 66, "row count for uploads");
- @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
- is($rows[0]->{count}, 18, "row count for ixlatest");
- @rows = $dbh->get_query('hash','select count(*) as count from page_requests');
- is($rows[0]->{count}, 16, "row count for page_requests");
- @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','Acme-CPANAuthors-French');
- is($rows[0]->{version}, '0.07', "old index version not overwritten");
- @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','Acme-CPANAuthors-Japanese');
- is($rows[0]->{version}, '0.090911', "old index version");
- @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','CPAN-Testers-Data-Uploads');
- is($rows[0]->{version}, '0.12', "new index version");
+ skip "Test::Database required for DB testing", 12 unless(-f $config);
+
+ my $obj;
+ eval { $obj = CPAN::Testers::Data::Uploads->new( config => $config, update => 1 ) };
+ isa_ok($obj,'CPAN::Testers::Data::Uploads');
+
+ SKIP: {
+ skip "Problem creating object", 11 unless($obj);
+
+ my $dbh = $obj->uploads;
+ ok($dbh);
+
+ is(lastid(),0,'.. lastid is 0 from start');
+
+ my @rows = $dbh->get_query('hash','select count(*) as count from uploads');
+ is($rows[0]->{count}, 63, "row count for uploads");
+ @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
+ is($rows[0]->{count}, 17, "row count for ixlatest");
+
+ $obj->process;
+
+ is(lastid(),72870,'.. lastid is updated after process');
+
+ @rows = $dbh->get_query('hash','select count(*) as count from uploads');
+ is($rows[0]->{count}, 66, "row count for uploads");
+ @rows = $dbh->get_query('hash','select count(*) as count from ixlatest');
+ is($rows[0]->{count}, 18, "row count for ixlatest");
+ @rows = $dbh->get_query('hash','select count(*) as count from page_requests');
+ is($rows[0]->{count}, 16, "row count for page_requests");
+ @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','Acme-CPANAuthors-French');
+ is($rows[0]->{version}, '0.07', "old index version not overwritten");
+ @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','Acme-CPANAuthors-Japanese');
+ is($rows[0]->{version}, '0.090911', "old index version");
+ @rows = $dbh->get_query('hash','select * from ixlatest where dist=?','CPAN-Testers-Data-Uploads');
+ is($rows[0]->{version}, '0.12', "new index version");
+ }
}
sub lastid {
View
@@ -13,22 +13,26 @@ my $config = 't/_DBDIR/test-config.ini';
my $sqlite = 't/_DBDIR/uploads.db';
my $csvfile = 't/_DBDIR/uploads.csv';
-my $obj;
-eval { $obj = CPAN::Testers::Data::Uploads->new( config => $config, backup => 1 ) };
-isa_ok($obj,'CPAN::Testers::Data::Uploads');
-
SKIP: {
- skip "Problem creating object", 4 unless($obj);
+ skip "Test::Database required for DB testing", 5 unless(-f $config);
- ok( ! -f $sqlite, '.. no SQLite backup' );
- ok( ! -f $csvfile, '.. no CSV backup' );
+ my $obj;
+ eval { $obj = CPAN::Testers::Data::Uploads->new( config => $config, backup => 1 ) };
+ isa_ok($obj,'CPAN::Testers::Data::Uploads');
- $obj->process;
+ SKIP: {
+ skip "Problem creating object", 4 unless($obj);
- ok( -f $sqlite, '.. got SQLite backup' );
+ ok( ! -f $sqlite, '.. no SQLite backup' );
+ ok( ! -f $csvfile, '.. no CSV backup' );
- SKIP: {
- skip "DBD::CSV not installed", 1 unless($available_drivers{'CSV'});
- ok( -f $csvfile, '.. got CSV backup' );
+ $obj->process;
+
+ ok( -f $sqlite, '.. got SQLite backup' );
+
+ SKIP: {
+ skip "DBD::CSV not installed", 1 unless($available_drivers{'CSV'});
+ ok( -f $csvfile, '.. got CSV backup' );
+ }
}
}

0 comments on commit 1de848e

Please sign in to comment.