/
CTWRM_Testing.pm
137 lines (111 loc) · 2.95 KB
/
CTWRM_Testing.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package CTWRM_Testing;
use strict;
use warnings;
use CPAN::Testers::WWW::Reports::Mailer;
use DBI;
#use DBD::SQLite;
use File::Spec;
use File::Path;
use File::Basename;
sub getObj {
my %opts = @_;
$opts{config} ||= \*DATA;
_cleanDir( 'logs' ) or return;
my $obj = CPAN::Testers::WWW::Reports::Mailer->new(%opts);
return $obj;
}
sub _cleanDir {
my $dir = shift;
if( -d $dir ){
rmtree($dir) or return;
}
mkpath($dir) or return;
return 1;
}
sub cleanDir {
my $obj = shift;
return _cleanDir( 'logs' );
}
sub whackDir {
my $obj = shift;
my $dir = 'logs';
if( -d $dir ){
rmtree($dir) or return;
}
return 1;
}
sub prefs_db_init {
my $data = shift;
my $f = File::Spec->catfile('t','_DBDIR','test2.db');
unlink $f if -f $f;
mkpath( dirname($f) );
my $dbh = DBI->connect("dbi:SQLite:dbname=$f", '', '', {AutoCommit=>1});
$dbh->do(q{
CREATE TABLE prefs_authors (
pauseid TEXT PRIMARY KEY,
active INTEGER,
lastlogin TEXT
)
});
$dbh->do(q{
CREATE TABLE prefs_distributions (
pauseid TEXT,
distribution TEXT,
ignored INTEGER,
report INTEGER,
grade TEXT,
tuple TEXT,
version TEXT,
patches INTEGER,
perl TEXT,
platform TEXT
)
});
while(<$data>){
chomp;
my ($type,@values) = split(/\|/,$_);
if($type eq 'auth') {
$dbh->do('INSERT INTO prefs_authors ( pauseid, active, lastlogin ) VALUES ( ?, ?, ? )', {}, @values );
} else {
$dbh->do('INSERT INTO prefs_distributions ( pauseid, distribution, ignored, report, grade, tuple, version, patches, perl, platform ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )', {}, @values );
}
}
my ($pa) = $dbh->selectrow_array('select count(*) from prefs_authors');
my ($pd) = $dbh->selectrow_array('select count(*) from prefs_distributions');
$dbh->disconnect;
return($pa,$pd);
}
sub mail_check {
my ($file1,$file2) = @_;
my $mail1 = readfile($file1);
my $mail2 = readfile($file2);
return $mail1 eq $mail2 ? 1 : 0;
}
sub readfile {
my $file = shift;
my $text;
my $fh = IO::File->new($file,'r') or die "Cannot open file [$file]: $!\n";
while(<$fh>) {
next if(/^Date:/);
$text .= $_
}
$fh->close;
return $text;
}
1;
__DATA__
[CPANSTATS]
driver=SQLite
database=t/_DBDIR/test.db
[CPANPREFS]
driver=SQLite
database=t/_DBDIR/test2.db
[ARTICLES]
driver=SQLite
database=t/_DBDIR/test3.db
[SETTINGS]
mailrc=t/data/01mailrc.txt
verbose=1
nomail=1
logfile=t/_TMPDIR/cpanreps.log
logclean=1