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