2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
4 use Test::More tests => 102;
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);
21 # The test functions are placed here to make things easier
23 use DebbugsTest qw(:all);
26 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
30 %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
36 my $sendmail_dir = $config{sendmail_dir};
37 my $spool_dir = $config{spool_dir};
38 my $config_dir = $config{config_dir};
42 diag("spool_dir: $spool_dir\n");
43 diag("config_dir: $config_dir\n");
44 diag("sendmail_dir: $sendmail_dir\n");
48 # We're going to use create mime message to create these messages, and
49 # then just send them to receive.
51 send_message(to=>'submit@bugs.something',
52 headers => [To => 'submit@bugs.something',
53 From => 'foo@bugs.something',
54 Subject => 'Submiting a bug',
56 body => <<EOF) or fail('Unable to send message');
63 # now we check to see that we have a bug, and nextnumber has been incremented
64 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
65 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
66 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
67 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
69 # next, we check to see that (at least) the proper messages have been
70 # sent out. 1) ack to submitter 2) mail to maintainer
72 # This keeps track of the previous size of the sendmail directory
74 my $SD_SIZE_NOW = dirsize($sendmail_dir);
75 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'submit messages appear to have been sent out properly');
76 $SD_SIZE_PREV=$SD_SIZE_NOW;
78 # now send a message to the bug
80 send_message(to => '1@bugs.something',
81 headers => [To => '1@bugs.something',
82 From => 'foo@bugs.something',
83 Subject => 'Sending a message to a bug',
85 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
92 $SD_SIZE_NOW = dirsize($sendmail_dir);
93 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'1@bugs.something messages appear to have been sent out properly');
94 $SD_SIZE_PREV=$SD_SIZE_NOW;
96 # just check to see that control doesn't explode
97 send_message(to => 'control@bugs.something',
98 headers => [To => 'control@bugs.something',
99 From => 'foo@bugs.something',
100 Subject => 'Munging a bug',
102 body => <<EOF) or fail 'message to control@bugs.something failed';
108 $SD_SIZE_NOW = dirsize($sendmail_dir);
109 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
110 $SD_SIZE_PREV=$SD_SIZE_NOW;
111 # now we need to check to make sure the control message was processed without errors
112 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
113 'control@bugs.something message was parsed without errors');
114 # now we need to check to make sure that the control message actually did anything
115 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
116 eval "use Debbugs::Status qw(read_bug writebug);";
117 my $status = read_bug(bug=>1);
118 ok($status->{subject} eq 'new title','bug 1 retitled');
119 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');
121 # now we're going to go through and methododically test all of the control commands.
122 my @control_commands =
124 severity_wishlist => {command => 'severity',
126 status_key => 'severity',
127 status_value => 'wishlist',
129 reassign_bar_baz => {command => 'reassign',
131 status_key => 'package',
132 status_value => 'bar,baz',
134 reassign_foo => {command => 'reassign',
136 status_key => 'package',
137 status_value => 'foo',
139 'found_1.0' => {command => 'found',
141 status_key => 'found_versions',
142 status_value => ['1.0'],
144 'notfound_1.0' => {command => 'notfound',
146 status_key => 'found_versions',
149 'found_1.0~5+1b2' => {command => 'found',
150 value => '1.0~5+1b2',
151 status_key => 'found_versions',
152 status_value => ['1.0~5+1b2'],
154 'notfound_1.0~5+1b2' => {command => 'notfound',
155 value => '1.0~5+1b2',
156 status_key => 'found_versions',
159 'fixed_1.1' => {command => 'fixed',
161 status_key => 'fixed_versions',
162 status_value => ['1.1'],
164 'notfixed_1.1' => {command => 'notfixed',
166 status_key => 'fixed_versions',
169 'found_1.0~5+1b2' => {command => 'found',
170 value => '1.0~5+1b2',
171 status_key => 'found_versions',
172 status_value => ['1.0~5+1b2'],
174 'fixed_1.2' => {command => 'fixed',
176 status_key => 'fixed_versions',
177 status_value => ['1.2'],
179 close => {command => 'close',
181 status_key => 'done',
182 status_value => 'foo@bugs.something',
184 'found_1.3' => {command => 'found',
186 status_key => 'done',
189 submitter_foo => {command => 'submitter',
190 value => 'foo@bar.com',
191 status_key => 'originator',
192 status_value => 'foo@bar.com',
195 forwarded_foo => {command => 'forwarded',
196 value => 'foo@bar.com',
197 status_key => 'forwarded',
198 status_value => 'foo@bar.com',
200 owner_foo => {command => 'owner',
201 value => 'foo@bar.com',
202 status_key => 'owner',
203 status_value => 'foo@bar.com',
205 noowner => {command => 'noowner',
207 status_key => 'owner',
210 clone => {command => 'clone',
212 status_key => 'package',
213 status_value => 'foo',
216 merge => {command => 'merge',
218 status_key => 'mergedwith',
221 unmerge => {command => 'unmerge',
223 status_key => 'mergedwith',
226 forcemerge => {command => 'forcemerge',
228 status_key => 'mergedwith',
231 unmerge => {command => 'unmerge',
233 status_key => 'mergedwith',
236 block => {command => 'block',
238 status_key => 'blockedby',
241 summary => {command => 'summary',
243 status_key => 'summary',
244 status_value => 'This is a silly bug',
246 nosummary => {command => 'summary',
248 status_key => 'summary',
251 affects => {command => 'affects',
253 status_key => 'affects',
254 status_value => 'foo',
256 noaffects => {command => 'affects',
258 status_key => 'affects',
261 close => {command => 'close',
263 status_key => 'done',
264 status_value => 'foo@bugs.something',
266 archive => {command => 'archive',
268 status_key => 'owner',
270 location => 'archive',
272 unarchive => {command => 'unarchive',
274 status_key => 'owner',
279 # In order for the archive/unarchive to work, we have to munge the summary file slightly
280 $status = read_bug(bug => 1);
281 $status->{unarchived} = time;
283 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
284 # just check to see that control doesn't explode
285 $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
286 and $control_command->{value} !~ /^\s/;
287 send_message(to => 'control@bugs.something',
288 headers => [To => 'control@bugs.something',
289 From => 'foo@bugs.something',
290 Subject => "Munging a bug with $command",
292 body => <<EOF) or fail 'message to control@bugs.something failed';
294 $control_command->{command} 1$control_command->{value}
298 $SD_SIZE_NOW = dirsize($sendmail_dir);
299 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
300 $SD_SIZE_PREV=$SD_SIZE_NOW;
301 # now we need to check to make sure the control message was processed without errors
302 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
303 'control@bugs.something'. "$command message was parsed without errors");
304 # now we need to check to make sure that the control message actually did anything
306 $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
307 exists $control_command->{location}?(location => $control_command->{location}):(),
309 is_deeply($status->{$control_command->{status_key}},
310 $control_command->{status_value},
312 (exists $control_command->{bug}?$control_command->{bug}:1).
315 or fail(Dumper($status));
318 # verify that archive/unarchive can then be modified afterwards
320 send_message(to => 'control@bugs.something',
321 headers => [To => 'control@bugs.something',
322 From => 'foo@bugs.something',
323 Subject => "Munging a bug with unarchivearchive",
325 body => <<'EOF') or fail 'message to control@bugs.something failed';
329 submitter 1 bar@baz.com
333 $SD_SIZE_NOW = dirsize($sendmail_dir);
334 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
335 $SD_SIZE_PREV=$SD_SIZE_NOW;
336 # now we need to check to make sure the control message was processed without errors
337 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with unarchivearchive")) == 0,
338 'control@bugs.something'. "unarchive/archive message was parsed without errors");