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