]> git.donarmstrong.com Git - debbugs.git/blob - t/14_control_at_submit.t
41c6a03758cd8f7751509e1c30a008e29061f60e
[debbugs.git] / t / 14_control_at_submit.t
1 # -*- mode: cperl;-*-
2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
3
4 use Test::More tests => 122;
5
6 use warnings;
7 use strict;
8
9 # Here, we're going to shoot messages through a set of things that can
10 # happen.
11
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.
15
16 use IO::File;
17 use File::Temp qw(tempdir);
18 use Cwd qw(getcwd);
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
22 use lib qw(t/lib);
23 use DebbugsTest qw(:all);
24 use Data::Dumper;
25 use Encode qw(decode encode);
26
27 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
28 $SIG{CHLD} = sub {};
29 my %config;
30 eval {
31      %config = create_debbugs_configuration();
32 };
33 if ($@) {
34      BAIL_OUT($@);
35 }
36
37 my $sendmail_dir = $config{sendmail_dir};
38 my $spool_dir = $config{spool_dir};
39 my $config_dir = $config{config_dir};
40
41
42
43 # We're going to use create mime message to create these messages, and
44 # then just send them to receive.
45
46 send_message(to=>'submit@bugs.something',
47              headers => [To   => 'submit@bugs.something',
48                          From => 'foo@bugs.something',
49                          Subject => 'Submiting a bug',
50                         ],
51              body => <<EOF) or fail('Unable to send message');
52 Package: foo
53 Severity: normal
54
55 This is a silly bug
56 EOF
57
58 # now we check to see that we have a bug, and nextnumber has been incremented
59 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
60 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
61 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
62 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
63
64 # next, we check to see that (at least) the proper messages have been
65 # sent out. 1) ack to submitter 2) mail to maintainer
66
67 # This keeps track of the previous size of the sendmail directory
68 my $SD_SIZE = 0;
69 $SD_SIZE =
70     num_messages_sent($SD_SIZE,2,
71                       $sendmail_dir,
72                       'submit messages appear to have been sent out properly',
73                      );
74
75
76 # now send a message to the bug
77
78 send_message(to => '1@bugs.something',
79              headers => [To   => '1@bugs.something',
80                          From => 'foo@bugs.something',
81                          Subject => 'Sending a message to a bug',
82                         ],
83              body => <<EOF) or fail('sending message to 1@bugs.someting failed');
84 Package: foo
85 Severity: normal
86
87 This is a silly bug
88 EOF
89
90 $SD_SIZE =
91     num_messages_sent($SD_SIZE,2,
92                       $sendmail_dir,
93                       '1@bugs.something messages appear to have been sent out properly');
94
95 # just check to see that control doesn't explode
96 send_message(to => 'control@bugs.something',
97              headers => [To   => 'control@bugs.something',
98                          From => 'foo@bugs.something',
99                          Subject => 'Munging a bug',
100                         ],
101              body => <<EOF) or fail 'message to control@bugs.something failed';
102 severity 1 wishlist
103 retitle 1 new title
104 thanks
105 EOF
106
107 $SD_SIZE =
108    num_messages_sent($SD_SIZE,1,
109                      $sendmail_dir,
110                      'control@bugs.something messages appear to have been sent out properly');
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');
120
121 send_message(to => 'submit@bugs.something',
122              headers => [To   => 'submit@bugs.something',
123                          From => 'foo@bugs.something',
124                          Subject => 'Testing submit at control',
125                         ],
126              body => <<EOF) or fail 'message to submit@bugs.something failed';
127 Package: foo
128 Control: retitle -1 this is a new title
129 EOF
130
131 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Testing submit at control")) == 0,
132    'submit@bugs.something message was parsed without errors');
133
134 $status = read_bug(bug=>2);
135 ok($status->{subject} eq 'this is a new title','bug 2 retitled at submit@ time');
136
137 send_message(to => '1@bugs.something',
138              headers => [To   => '1@bugs.something',
139                          From => 'foo@bugs.something',
140                          Subject => 'Testing control at 1@bugs.something',
141                         ],
142              body => <<EOF) or fail 'message to 1@bugs.something failed';
143 Control: retitle -1 this is now the title of bug 1
144 EOF
145
146 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Testing control at 1@bugs.something")) == 0,
147    '1@bugs.something message was parsed without errors');
148
149 $status = read_bug(bug=>1);
150 ok($status->{subject} eq 'this is now the title of bug 1','bug 1 retitled at 1@ time');
151
152
153
154 # now we're going to go through and methododically test all of the control commands.
155 my @control_commands =
156      (
157        clone        => {command => 'clone',
158                        value   => '-2',
159                        status_key => 'package',
160                        status_value => 'foo',
161                        bug          => '4',
162                       },
163        severity_wishlist => {command => 'severity',
164                             value   => 'wishlist',
165                             status_key => 'severity',
166                             status_value => 'wishlist',
167                            },
168        reassign_bar_baz => {command => 'reassign',
169                            value   => 'bar,baz',
170                            status_key => 'package',
171                            status_value => 'bar,baz',
172                           },
173        reassign_foo => {command => 'reassign',
174                        value   => 'foo',
175                        status_key => 'package',
176                        status_value => 'foo',
177                       },
178        'found_1.0'        => {command => 'found',
179                              value   => '1.0',
180                              status_key => 'found_versions',
181                              status_value => ['1.0'],
182                             },
183        'notfound_1.0'     => {command => 'notfound',
184                              value   => '1.0',
185                              status_key => 'found_versions',
186                              status_value => [],
187                             },
188        'found_1.0~5+1b2'  => {command => 'found',
189                              value   => '1.0~5+1b2',
190                              status_key => 'found_versions',
191                              status_value => ['1.0~5+1b2'],
192                             },
193        'notfound_1.0~5+1b2' => {command => 'notfound',
194                                value   => '1.0~5+1b2',
195                                status_key => 'found_versions',
196                                status_value => [],
197                               },
198        'fixed_1.1'        => {command => 'fixed',
199                              value   => '1.1',
200                              status_key => 'fixed_versions',
201                              status_value => ['1.1'],
202                             },
203        'notfixed_1.1'     => {command => 'notfixed',
204                              value   => '1.1',
205                              status_key => 'fixed_versions',
206                              status_value => [],
207                             },
208        'found_1.0~5+1b2'  => {command => 'found',
209                              value   => '1.0~5+1b2',
210                              status_key => 'found_versions',
211                              status_value => ['1.0~5+1b2'],
212                             },
213        'fixed_1.2'        => {command => 'fixed',
214                              value   => '1.2',
215                              status_key => 'fixed_versions',
216                              status_value => ['1.2'],
217                             },
218        close              => {command => 'close',
219                              value   => '',
220                              status_key => 'done',
221                              status_value => 'foo@bugs.something',
222                             },
223        'found_1.3'        => {command => 'found',
224                              value   => '1.3',
225                              status_key => 'done',
226                              status_value => '',
227                             },
228        submitter_foo      => {command => 'submitter',
229                              value   => 'foo@bar.com',
230                              status_key => 'originator',
231                              status_value => 'foo@bar.com',
232                             },
233  
234        forwarded_foo      => {command => 'forwarded',
235                              value   => 'foo@bar.com',
236                              status_key => 'forwarded',
237                              status_value => 'foo@bar.com',
238                             },
239        notforwarded       => {command => 'notforwarded',
240                              value   => '',
241                              status_key => 'forwarded',
242                              status_value => '',
243                             },
244        owner_foo          => {command => 'owner',
245                              value   => 'foo@bar.com',
246                              status_key => 'owner',
247                              status_value => 'foo@bar.com',
248                             },
249        noowner      => {command => 'noowner',
250                        value   => '',
251                        status_key => 'owner',
252                        status_value => '',
253                       },
254        merge        => {command => 'merge',
255                        value   => '1 4',
256                        status_key => 'mergedwith',
257                        status_value => '4',
258                       },
259        unmerge      => {command => 'unmerge',
260                        value   => '',
261                        status_key => 'mergedwith',
262                        status_value => '',
263                       },
264        forcemerge   => {command => 'forcemerge',
265                        value   => '4',
266                        status_key => 'mergedwith',
267                        status_value => '4',
268                       },
269        unmerge      => {command => 'unmerge',
270                        value   => '',
271                        status_key => 'mergedwith',
272                        status_value => '',
273                       },
274        block        => {command => 'block',
275                        value   => ' with 2',
276                        status_key => 'blockedby',
277                        status_value => '2',
278                       },
279        unblock      => {command => 'unblock',
280                        value   => ' with 2',
281                        status_key => 'blockedby',
282                        status_value => '',
283                       },
284        summary      => {command => 'summary',
285                        value   => '5',
286                        status_key => 'summary',
287                        status_value => 'This is a silly bug',
288                       },
289        nosummary    => {command => 'summary',
290                        value   => '',
291                        status_key => 'summary',
292                        status_value => '',
293                       },
294        affects      => {command => 'affects',
295                        value   => 'foo',
296                        status_key => 'affects',
297                        status_value => 'foo',
298                       },
299        noaffects    => {command => 'affects',
300                        value   => '',
301                        status_key => 'affects',
302                        status_value => '',
303                       },
304        close        => {command => 'close',
305                        value   => '',
306                        status_key => 'done',
307                        status_value => 'foo@bugs.something',
308                       },
309        archive      => {command => 'archive',
310                        value   => '',
311                        status_key => 'owner',
312                        status_value => '',
313                        location => 'archive',
314                       },
315        unarchive    => {command => 'unarchive',
316                        value   => '',
317                        status_key => 'owner',
318                        status_value => '',
319                       },
320        tag          => {command => 'tag',
321                        value   => ' = patch',
322                        status_key => 'keywords',
323                        status_value => 'patch',
324                       },
325        untag        => {command => 'tag',
326                        value   => ' - patch',
327                        status_key => 'keywords',
328                        status_value => '',
329                       },
330        plustag      => {command => 'tag',
331                        value   => ' + patch',
332                        status_key => 'keywords',
333                        status_value => 'patch',
334                       },
335        utf8_retitle => {command => 'retitle',
336                        value   => 'Thïs is a ütff8 title [♥♡☙☎]',
337                        status_key => 'subject',
338                        status_value => decode("utf8",'Thïs is a ütff8 title [♥♡☙☎]'),
339                       },
340      );
341
342 # In order for the archive/unarchive to work, we have to munge the summary file slightly
343 $status = read_bug(bug => 1);
344 $status->{unarchived} = time;
345 writebug(1,$status);
346 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
347      # just check to see that control doesn't explode
348      $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
349           and $control_command->{value} !~ /^\s/;
350      send_message(to => 'submit@bugs.something',
351                   headers => [To   => 'submit@bugs.something',
352                               From => 'foo@bugs.something',
353                               Subject => "Munging a bug with $command",
354                              ],
355                   body => <<EOF) or fail 'message to control@bugs.something failed';
356 Package: foo
357 Control: $control_command->{command} 1$control_command->{value}
358 EOF
359                                   ;
360      $SD_SIZE =
361          num_messages_sent($SD_SIZE,1,
362                            $sendmail_dir,
363                            'control@bugs.something messages appear to have been sent out properly');
364      # now we need to check to make sure the control message was processed without errors
365      ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
366         'control@bugs.something'. "$command message was parsed without errors");
367      # now we need to check to make sure that the control message actually did anything
368      my $status;
369      $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
370                         exists $control_command->{location}?(location => $control_command->{location}):(),
371                        );
372      is_deeply($status->{$control_command->{status_key}},
373                $control_command->{status_value},
374                "bug " .
375                (exists $control_command->{bug}?$control_command->{bug}:1).
376                " $command"
377               )
378           or fail(Dumper($status));
379 }
380