Permalink
Browse files

redesigned test data and loader

  • Loading branch information...
1 parent 2bae0e4 commit f024b023100113089ac9710e7d3d2def944d6592 @barbie committed Sep 8, 2013
View
@@ -24,12 +24,16 @@ t/91podcover.t
t/94metatest.t
t/95changedate.t
t/96metatest.t
-t/data/a58945f6-3510-11df-89c9-1bb9c3681c0d.json
t/data/ad3189d0-3510-11df-89c9-1bb9c3681c0d.json
-t/data/af820e12-3510-11df-89c9-1bb9c3681c0d.json
-t/data/b248f71e-3510-11df-89c9-1bb9c3681c0d.json
-t/data/b77e7132-3510-11df-89c9-1bb9c3681c0d.json
-t/data/testers.csv
+t/data/4f976d00-08d2-11e3-bc0a-b75d6d822b3f.dat
+t/data/7af15cf4-0a80-11e3-ab4d-dce3f09adca3.dat
+t/data/8fd1b4e0-0e48-11e3-8d27-d505f19adca3.dat
+t/data/c9bb8cac-109c-11e3-9d5d-466d772db441.dat
+t/data/fbc49036-08ea-11e3-b8b2-96b61dda783b.dat
+t/data/cpanstats.sql
+t/data/metabase.sql
+t/data/testers_email.sql
+t/lib/Fake/Loader.pm
t/test-config.ini
templates/mail-bad-reports.eml
templates/mail-bad-uploads.eml
View
@@ -18,51 +18,33 @@ use CPAN::Testers::Metabase::AWS;
use File::Path;
use IO::File;
use JSON;
-use Test::More tests => 23;
+use Test::More tests => 22;
+
+use lib qw(t/lib);
+use Fake::Loader;
#----------------------------------------------------------------------------
# Test Variables
-my (%options,$meta);
my $config = 't/_DBDIR/test-config.ini';
-#----------------------------------------------------------------------------
-# Test Data
-
-my @test_stat_rows = (
-[ '1', '2', 'a58945f6-3510-11df-89c9-1bb9c3681c0d', 'pass', '201003', 'chris@bingosnet.co.uk', 'Sub-Exporter-ForMethods', '0.100050', 'i686-linux-thread-multi-64int', '5.8.8', 'Linux', '2.6.28-11-generic', '201003211739' ],
-[ '2', '2', 'ad3189d0-3510-11df-89c9-1bb9c3681c0d', 'pass', '201003', 'chris@bingosnet.co.uk', 'Algorithm-Diff', '1.1902', 'i686-linux-thread-multi-64int', '5.8.8', 'Linux', '2.6.28-11-generic', '201003211739' ],
-[ '3', '2', 'af820e12-3510-11df-89c9-1bb9c3681c0d', 'pass', '201003', 'chris@bingosnet.co.uk', 'Text-Diff', '1.37', 'i686-linux-thread-multi-64int', '5.8.8', 'Linux', '2.6.28-11-generic', '201003211739' ],
-[ '4', '2', 'b248f71e-3510-11df-89c9-1bb9c3681c0d', 'pass', '201003', 'chris@bingosnet.co.uk', 'Test-Differences', '0.500', 'i686-linux-thread-multi-64int', '5.8.8', 'Linux', '2.6.28-11-generic', '201003211739' ],
-[ '5', '2', 'b77e7132-3510-11df-89c9-1bb9c3681c0d', 'pass', '201003', 'chris@bingosnet.co.uk', 'namespace-autoclean', '0.09', 'i686-linux-thread-multi-64int', '5.8.8', 'Linux', '2.6.28-11-generic', '201003211739' ]
-);
-
-my @test_meta_rows = (
-[ 1, 'a58945f6-3510-11df-89c9-1bb9c3681c0d', '2010-03-21T17:39:05Z' ],
-[ 2, 'ad3189d0-3510-11df-89c9-1bb9c3681c0d', '2010-03-21T17:39:18Z' ],
-[ 3, 'af820e12-3510-11df-89c9-1bb9c3681c0d', '2010-03-21T17:39:22Z' ],
-[ 4, 'b248f71e-3510-11df-89c9-1bb9c3681c0d', '2010-03-21T17:39:27Z' ],
-[ 5, 'b77e7132-3510-11df-89c9-1bb9c3681c0d', '2010-03-21T17:39:35Z' ]
-);
+my $loader = Fake::Loader->new();
#----------------------------------------------------------------------------
# Test Main
# TEST INTERNALS
SKIP: {
- skip "Test::Database required for DB testing", 23 unless(-f $config);
+ skip "Test::Database required for DB testing", 22 unless($loader);
# prep test directory
my $directory = './test';
rmtree($directory);
mkpath($directory) or die "cannot create directory";
- testCpanstatsRecords();
- testMetabaseRecords();
-
- my $c1 = getMetabaseCount();
- is($c1,5,'Internal Tests, metabase contains 5 reports');
+ is($loader->count_cpanstats(),5,'Internal Tests, metabase contains 5 reports');
+ is($loader->count_metabase(),5,'Internal Tests, metabase contains 5 reports');
my $t;
eval {
@@ -83,22 +65,21 @@ SKIP: {
[ undef, '', 'xxx' ],
[ '2000-01-01T00:00:00Z', '', '2000-01-01T00:00:00Z' ],
[ '2010-09-13T03:20:00Z', undef, '2010-09-13T03:20:00Z' ],
- [ '2010-03-21T17:39:05Z', 'a58945f6-3510-11df-89c9-1bb9c3681c0d', '' ],
+ [ '2013-08-18T10:22:13Z', '0cbce1be-07f0-11e3-9db1-878205732d18', '' ],
);
for my $test (@test_dates) {
is($t->_get_createdate($test->[1],$test->[2]),$test->[0], ".. test date [".($test->[0]||'undef')."]");
}
- is($t->already_saved('a58945f7-3510-11df-89c9-1bb9c3681c0d'),0,'.. missing metabase guid');
- is($t->already_saved('a58945f6-3510-11df-89c9-1bb9c3681c0d'),'2010-03-21T17:39:05Z','.. found metabase guid');
+ is($t->already_saved('5ad79194-6cdc-1014-b4e3-38f2223f278c'),0,'.. missing metabase guid');
+ is($t->already_saved('5ad79194-6cdc-1014-b4e3-38f2223f278b'),'2013-08-18T10:34:33Z','.. found metabase guid');
is($t->retrieve_report('a58945f7-3510-11df-89c9-1bb9c3681c0d'),undef,'.. missing cpanstats guid');
- my $r = $t->retrieve_report('a58945f6-3510-11df-89c9-1bb9c3681c0d');
- is($r->{guid},'a58945f6-3510-11df-89c9-1bb9c3681c0d','.. found cpanstats guid');
+ my $r = $t->retrieve_report('5ad79194-6cdc-1014-b4e3-38f2223f278b');
+ is($r->{guid},'5ad79194-6cdc-1014-b4e3-38f2223f278b','.. found cpanstats guid');
- $options{CPANSTATS} ||= config_db('CPANSTATS');
- my @rows = $options{CPANSTATS}->{dbh}->get_query('array','SELECT count(id) FROM osname');
+ my @rows = $loader->{CPANSTATS}{dbh}->get_query('array','SELECT count(id) FROM osname');
is($rows[0]->[0],25,'.. all OS names');
is($t->_platform_to_osname('linux'),'linux', '.. known OS');
@@ -120,75 +101,3 @@ SKIP: {
is($t->{report}{osname},'linux','.. set OS');
is($t->{report}{platform},'i686-linux-thread-multi-64int','.. set platform');
}
-
-#----------------------------------------------------------------------------
-# Test Functions
-
-sub config_db {
- # Loads Test::Database instances
-
- my $db = shift;
-
- # load config file
- my $cfg = Config::IniFiles->new( -file => $config );
-
- # configure databases
- die "No configuration for $db database\n" unless($cfg->SectionExists($db));
- my %opts = map {$_ => ($cfg->val($db,$_)||undef);} qw(driver database dbfile dbhost dbport dbuser dbpass);
- unlink $opts{database} if($opts{driver} eq 'SQLite' && -f $opts{database});
-
- # need to store new configuration details here
-
- my $dbh = CPAN::Testers::Common::DBUtils->new(%opts);
- die "Cannot configure $db database\n" unless($dbh);
-
- my %hash = ( opts => \%opts, dbh => $dbh );
- return \%hash;
-}
-
-sub testCpanstatsRecords {
- $options{CPANSTATS} ||= config_db('CPANSTATS');
- my @rows = $options{CPANSTATS}->{dbh}->get_query('array','SELECT * FROM cpanstats');
- is_deeply(\@rows,\@test_stat_rows,'.. test cpanstats rows');
-}
-
-sub testMetabaseRecords {
- $options{METABASE} ||= config_db('METABASE');
- my @rows = $options{METABASE}->{dbh}->get_query('array','SELECT id,guid,updated FROM metabase');
- is_deeply(\@rows,\@test_meta_rows,'.. test metabase rows');
-}
-
-sub getMetabaseCount {
- $options{METABASE} ||= config_db('METABASE');
- my @rows = $options{METABASE}->{dbh}->get_query('array','SELECT count(id) FROM metabase');
- return 0 unless(@rows);
- return $rows[0]->[0] || 0;
-}
-
-sub deleteMetabase {
- my $id = shift;
- $options{METABASE} ||= config_db('METABASE');
- my @rows = $options{METABASE}->{dbh}->get_query('array','SELECT * FROM metabase WHERE id = ?',$id);
- $options{METABASE}->{dbh}->do_query('DELETE FROM metabase WHERE id = ?',$id) if(@rows);
-}
-
-sub countRequests {
- $options{CPANSTATS} ||= config_db('CPANSTATS');
- my @rows = $options{CPANSTATS}->{dbh}->get_query('array','SELECT * FROM page_requests');
-# diag(Dumper($_)) for(@rows);
- return scalar(@rows);
-}
-
-sub countSummaries {
- $options{CPANSTATS} ||= config_db('CPANSTATS');
- my @rows = $options{CPANSTATS}->{dbh}->get_query('array','SELECT * FROM release_summary');
-# diag(Dumper($_)) for(@rows);
- return scalar(@rows);
-}
-
-sub countReleases {
- $options{CPANSTATS} ||= config_db('CPANSTATS');
- my @rows = $options{CPANSTATS}->{dbh}->get_query('array','SELECT * FROM release_data');
-# diag(Dumper($_)) for(@rows);
- return scalar(@rows);
-}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
+INSERT INTO `cpanstats` (id,guid,state,postdate,tester,dist,version,platform,perl,osname,osvers,fulldate,type) VALUES (33578672,'0cbce1be-07f0-11e3-9db1-878205732d18','pass','201308','srezic@iconmobile.net (Slaven Rezic)','CPAN-Testers-WWW-Statistics','1.06','i386-freebsd','5.8.9','freebsd','8.0-release','201308181022',2);
+INSERT INTO `cpanstats` (id,guid,state,postdate,tester,dist,version,platform,perl,osname,osvers,fulldate,type) VALUES (33578876,'5ad79194-6cdc-1014-b4e3-38f2223f278b','na','201308','mithaldu@yahoo.de (\"Christian Walde\")','CPAN-Testers-WWW-Statistics','1.06','MSWin32-x86-multi-thread','5.16.0','MSWin32','5.2','201308181034',2);
+INSERT INTO `cpanstats` (id,guid,state,postdate,tester,dist,version,platform,perl,osname,osvers,fulldate,type) VALUES (33579060,'66261f56-07f3-11e3-ac5a-df7f19362e69','pass','201308','srezic@iconmobile.net (Slaven Rezic)','CPAN-Testers-WWW-Statistics','1.06','i386-freebsd','5.12.3','freebsd','8.0-release','201308181046',2);
+INSERT INTO `cpanstats` (id,guid,state,postdate,tester,dist,version,platform,perl,osname,osvers,fulldate,type) VALUES (33578988,'b35d7c0c-07f2-11e3-afab-ccf1a108922b','pass','201308','srezic@iconmobile.net (Slaven Rezic)','CPAN-Testers-WWW-Statistics','1.06','i386-freebsd','5.14.0','freebsd','8.0-release','201308181041',2);
+INSERT INTO `cpanstats` (id,guid,state,postdate,tester,dist,version,platform,perl,osname,osvers,fulldate,type) VALUES (33578912,'ffdb8ffc-07f1-11e3-a0a5-bfc8c70fa3a9','pass','201308','srezic@iconmobile.net (Slaven Rezic)','CPAN-Testers-WWW-Statistics','1.06','i386-freebsd','5.16.0 RC0','freebsd','8.0-release-p4','201308181036',2);
Binary file not shown.
Oops, something went wrong.

0 comments on commit f024b02

Please sign in to comment.