]> git.donarmstrong.com Git - debbugs.git/blob - t/12_merge.t
4857f143967327f4a8e537ac5faf6cb5e207b235
[debbugs.git] / t / 12_merge.t
1 # -*- mode: cperl;-*-
2
3 use Test::More tests => 35;
4
5 use warnings;
6 use strict;
7
8 # Here, we're going to shoot messages through a set of things that can
9 # happen.
10
11 # First, we're going to send mesages to receive.
12 # To do so, we'll first send a message to submit,
13 # then send messages to the newly created bugnumber.
14
15 use IO::File;
16 use File::Temp qw(tempdir);
17 use Cwd qw(getcwd);
18 use Debbugs::MIME qw(create_mime_message);
19 use File::Basename qw(dirname basename);
20 # The test functions are placed here to make things easier
21 use lib qw(t/lib);
22 use DebbugsTest qw(:all);
23 use Data::Dumper;
24
25 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
26 $SIG{CHLD} = sub {};
27 my %config;
28 eval {
29      %config = create_debbugs_configuration();
30 };
31 if ($@) {
32      BAIL_OUT($@);
33 }
34
35 my $sendmail_dir = $config{sendmail_dir};
36 my $spool_dir = $config{spool_dir};
37 my $config_dir = $config{config_dir};
38
39
40
41 # We're going to use create mime message to create these messages, and
42 # then just send them to receive.
43
44 send_message(to=>'submit@bugs.something',
45              headers => [To   => 'submit@bugs.something',
46                          From => 'foo@bugs.something',
47                          Subject => 'Submiting a bug',
48                         ],
49              body => <<EOF) or fail('Unable to send message');
50 Package: foo
51 Severity: normal
52
53 This is a silly bug
54 EOF
55
56 # now we check to see that we have a bug, and nextnumber has been incremented
57 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
58 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
59 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
60 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
61
62 # next, we check to see that (at least) the proper messages have been
63 # sent out. 1) ack to submitter 2) mail to maintainer
64
65 # This keeps track of the previous size of the sendmail directory
66 my $SD_SIZE = 0;
67 $SD_SIZE =
68     num_messages_sent($SD_SIZE,2,
69                       $sendmail_dir,
70                       'submit messages appear to have been sent out properly',
71                      );
72
73
74 # now send a message to the bug
75
76 send_message(to => '1@bugs.something',
77              headers => [To   => '1@bugs.something',
78                          From => 'foo@bugs.something',
79                          Subject => 'Sending a message to a bug',
80                         ],
81              body => <<EOF) or fail('sending message to 1@bugs.someting failed');
82 Package: foo
83 Severity: normal
84
85 This is a silly bug
86 EOF
87
88 $SD_SIZE =
89     num_messages_sent($SD_SIZE,2,
90                       $sendmail_dir,
91                       '1@bugs.something messages appear to have been sent out properly');
92
93 # just check to see that control doesn't explode
94 send_message(to => 'control@bugs.something',
95              headers => [To   => 'control@bugs.something',
96                          From => 'foo@bugs.something',
97                          Subject => 'Munging a bug',
98                         ],
99              body => <<EOF) or fail 'message to control@bugs.something failed';
100 severity 1 wishlist
101 retitle 1 new title
102 thanks
103 EOF
104
105 $SD_SIZE =
106    num_messages_sent($SD_SIZE,1,
107                      $sendmail_dir,
108                      'control@bugs.something messages appear to have been sent out properly');
109 # now we need to check to make sure the control message was processed without errors
110 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
111    'control@bugs.something message was parsed without errors');
112 # now we need to check to make sure that the control message actually did anything
113 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
114 eval "use Debbugs::Status qw(read_bug writebug);";
115 my $status = read_bug(bug=>1);
116 ok($status->{subject} eq 'new title','bug 1 retitled');
117 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');
118
119 # now we're going to go through and methododically test all of the control commands.
120 my @control_commands =
121      (
122       clone        => {command => 'clone',
123                        value   => '1 -1',
124                        status_key => 'package',
125                        status_value => 'foo',
126                        bug          => '2',
127                       },
128       merge        => {command => 'merge',
129                        value   => '1 2',
130                        status_key => 'mergedwith',
131                        status_value => '2',
132                       },
133       unmerge      => {command => 'unmerge',
134                        value   => '1',
135                        status_key => 'mergedwith',
136                        status_value => '',
137                       },
138      );
139
140 test_control_commands(@control_commands);
141
142 send_message(to => 'control@bugs.something',
143              headers => [To   => 'control@bugs.something',
144                          From => 'foo@bugs.something',
145                          Subject => "Munging a bug with lots of stuff",
146                         ],
147              body => <<'EOF') or fail 'message to control@bugs.something failed';
148 debug 10
149 clone 2 -1 -2 -3 -4 -5 -6
150 retitle 2 foo
151 owner 2 bar@baz.com
152 submitter 2 fleb@bleh.com
153 tag 2 unreproducible moreinfo
154 severity 2 grave
155 block -1 by 2
156 block 2 by -2
157 summary 2 4
158 affects 2 bleargh
159 forwarded 2 http://example.com/2
160 close 2
161 tag -3 wontfix
162 fixed -4 1.2-3
163 found -4 1.2-1
164 found -5 1.2-5
165 fixed -5 1.2-6
166 thanks
167 EOF
168         ;
169         $SD_SIZE =
170             num_messages_sent($SD_SIZE,1,
171                               $sendmail_dir,
172                               'control@bugs.something messages appear to have been sent out properly');
173
174
175 test_control_commands(forcemerge   => {command => 'forcemerge',
176                                        value   => '1 2',
177                                        status_key => 'mergedwith',
178                                        status_value => '2',
179                                       },
180                       unmerge      => {command => 'unmerge',
181                                        value   => '1',
182                                        status_key => 'mergedwith',
183                                        status_value => '',
184                                       },
185                       forcemerge   => {command => 'forcemerge',
186                                        value   => '1 2 5',
187                                        status_key => 'mergedwith',
188                                        status_value => '2 5',
189                                       },
190                       forcemerge   => {command => 'forcemerge',
191                                        value   => '1 2 6',
192                                        status_key => 'mergedwith',
193                                        status_value => '2 5 6',
194                                       },
195                       merge        => {command => 'merge',
196                                        value   => '7 8',
197                                        status_key => 'mergedwith',
198                                        status_value => '8',
199                                        bug => '7',
200                                       },
201                      );
202
203
204 sub test_control_commands{
205     my @commands = @_;
206
207     while (my ($command,$control_command) = splice(@commands,0,2)) {
208         # just check to see that control doesn't explode
209         $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
210             and $control_command->{value} !~ /^\s/;
211         send_message(to => 'control@bugs.something',
212                      headers => [To   => 'control@bugs.something',
213                                  From => 'foo@bugs.something',
214                                  Subject => "Munging a bug with $command",
215                                 ],
216                      body => <<EOF) or fail 'message to control@bugs.something failed';
217 debug 10
218 $control_command->{command} $control_command->{value}
219 thanks
220 EOF
221         ;
222         $SD_SIZE =
223             num_messages_sent($SD_SIZE,1,
224                               $sendmail_dir,
225                               'control@bugs.something messages appear to have been sent out properly');
226         # now we need to check to make sure the control message was processed without errors
227         ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
228            'control@bugs.something'. "$command message was parsed without errors");
229         # now we need to check to make sure that the control message actually did anything
230         my $status;
231         $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
232                            exists $control_command->{location}?(location => $control_command->{location}):(),
233                           );
234         is_deeply($status->{$control_command->{status_key}},
235                   $control_command->{status_value},
236                   "bug " .
237                   (exists $control_command->{bug}?$control_command->{bug}:1).
238                   " $command"
239                  )
240             or fail(Dumper($status));
241     }
242 }