2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
4 use Test::More tests => 20;
9 # Here, we're going to shoot messages through a set of things that can
12 # First, we're going to send mesages to receive.
13 # To do so, we'll first send a message to submit,
14 # then send messages to the newly created bugnumber.
17 use File::Temp qw(tempdir);
19 use Debbugs::MIME qw(create_mime_message);
20 use File::Basename qw(dirname basename);
23 my $sendmail_dir = tempdir(CLEANUP => $ENV{DEBUG}?0:1);
24 my $spool_dir = tempdir(CLEANUP => $ENV{DEBUG}?0:1);
25 my $config_dir = tempdir(CLEANUP => $ENV{DEBUG}?0:1);
29 print STDERR "\nspool_dir: $spool_dir\n";
30 print STDERR "config_dir: $config_dir\n";
31 print STDERR "sendmail_dir: $sendmail_dir\n";
35 $ENV{DEBBUGS_CONFIG_FILE} ="$config_dir/debbugs_config";
36 $ENV{PERL5LIB} = getcwd();
37 $ENV{SENDMAIL_TESTDIR} = $sendmail_dir;
38 my $sendmail_tester = getcwd().'/t/sendmail_tester';
41 unless (-x $sendmail_tester) {
42 BAIL_OUT(q(t/sendmail_tester doesn't exist or isn't executable. You may be in the wrong directory.));
45 my %files_to_create = ("$config_dir/debbugs_config" => <<END,
46 \$gSendmail='$sendmail_tester';
47 \$gSpoolDir='$spool_dir';
48 \$gLibPath='@{[getcwd()]}/scripts';
51 "$spool_dir/nextnumber" => qq(1\n),
52 "$config_dir/Maintainers" => qq(foo Blah Bleargh <bar\@baz.com>\n),
53 "$config_dir/Maintainers.override" => qq(),
54 "$config_dir/indices/sources" => <<END,
58 while (my ($file,$contents) = each %files_to_create) {
59 system('mkdir','-p',dirname($file));
60 my $fh = IO::File->new($file,'w') or
61 BAIL_OUT("Unable to create $file: $!");
62 print {$fh} $contents;
66 system('touch',"$spool_dir/index.db.realtime");
67 system('ln','-s','index.db.realtime',
68 "$spool_dir/index.db");
69 system('touch',"$spool_dir/index.archive.realtime");
70 system('ln','-s','index.archive.realtime',
71 "$spool_dir/index.archive");
75 # create the spool files and sub directories
76 map {system('mkdir','-p',"$spool_dir/$_"); }
77 map {('db-h/'.$_,'archive/'.$_)}
78 map { sprintf "%02d",$_ % 100} 0..99;
79 system('mkdir','-p',"$spool_dir/incoming");
80 system('mkdir','-p',"$spool_dir/lock");
83 # We're going to use create mime message to create these messages, and
84 # then just send them to receive.
86 # First, check that submit@ works
88 $ENV{LOCAL_PART} = 'submit@bugs.something';
89 my $receive = new IO::File ('|scripts/receive.in') or BAIL_OUT("Unable to start receive.in: $!");
91 print {$receive} create_mime_message([To => 'submit@bugs.something',
92 From => 'foo@bugs.something',
93 Subject => 'Submiting a bug',
103 ok($?==0,'receive took the mail');
104 # now we should run processall to see if the message gets processed
105 ok(system('scripts/processall.in') == 0,'processall ran');
107 # now we check to see that we have a bug, and nextnumber has been incremented
108 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
109 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
110 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
111 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
113 # next, we check to see that (at least) the proper messages have been
114 # sent out. 1) ack to submitter 2) mail to maintainer
119 my @content = grep {!/^\.\.?$/} readdir(DIR);
121 return scalar @content;
124 # This keeps track of the previous size of the sendmail directory
125 my $SD_SIZE_PREV = 0;
126 my $SD_SIZE_NOW = dirsize($sendmail_dir);
127 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'submit messages appear to have been sent out properly');
128 $SD_SIZE_PREV=$SD_SIZE_NOW;
130 # now send a message to the bug
132 $ENV{LOCAL_PART} = '1@bugs.something';
133 $receive = new IO::File ('|scripts/receive.in') or
134 BAIL_OUT("Unable to start receive.in: $!");
136 print {$receive} create_mime_message([To => '1@bugs.something',
137 From => 'foo@bugs.something',
138 Subject => 'Sending a message to a bug',
148 ok($?==0,'receive took the mail');
149 # now we should run processall to see if the message gets processed
150 ok(system('scripts/processall.in') == 0,'processall ran');
151 $SD_SIZE_NOW = dirsize($sendmail_dir);
152 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'1@bugs.something messages appear to have been sent out properly');
153 $SD_SIZE_PREV=$SD_SIZE_NOW;
155 # just check to see that control doesn't explode
156 $ENV{LOCAL_PART} = 'control@bugs.something';
157 $receive = new IO::File ('|scripts/receive.in') or
158 BAIL_OUT("Unable to start receive.in: $!");
160 print {$receive} create_mime_message([To => 'control@bugs.something',
161 From => 'foo@bugs.something',
162 Subject => 'Munging a bug',
171 ok($?==0,'receive took the mail');
172 # now we should run processall to see if the message gets processed
173 ok(system('scripts/processall.in') == 0,'processall ran');
174 $SD_SIZE_NOW = dirsize($sendmail_dir);
175 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
176 $SD_SIZE_PREV=$SD_SIZE_NOW;
177 # now we need to check to make sure the control message was processed without errors
178 ok(system("sh -c 'find ".$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug"')) == 0,
179 'control@bugs.something message was parsed without errors');
180 # now we need to check to make sure that the control message actually did anything
181 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
182 eval "use Debbugs::Status qw(read_bug);";
183 my $status = read_bug(bug=>1);
184 ok($status->{subject} eq 'new title','bug 1 retitled');
185 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');