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