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