]> git.donarmstrong.com Git - debbugs.git/blob - t/12_merge.t
change convert_to_utf8 to attempt to fix doubly encoded things
[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(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 -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   => '1',
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 -5 -6
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 found -5 1.2-5
171 fixed -5 1.2-6
172 thanks
173 EOF
174         ;
175         $SD_SIZE =
176             num_messages_sent($SD_SIZE,1,
177                               $sendmail_dir,
178                               'control@bugs.something messages appear to have been sent out properly');
179
180
181 test_control_commands(forcemerge   => {command => 'forcemerge',
182                                        value   => '1 2',
183                                        status_key => 'mergedwith',
184                                        status_value => '2',
185                                       },
186                       unmerge      => {command => 'unmerge',
187                                        value   => '1',
188                                        status_key => 'mergedwith',
189                                        status_value => '',
190                                       },
191                       forcemerge   => {command => 'forcemerge',
192                                        value   => '1 2 5',
193                                        status_key => 'mergedwith',
194                                        status_value => '2 5',
195                                       },
196                       forcemerge   => {command => 'forcemerge',
197                                        value   => '1 2 6',
198                                        status_key => 'mergedwith',
199                                        status_value => '2 5 6',
200                                       },
201                       merge        => {command => 'merge',
202                                        value   => '7 8',
203                                        status_key => 'mergedwith',
204                                        status_value => '8',
205                                        bug => '7',
206                                       },
207                      );
208
209
210 sub test_control_commands{
211     my @commands = @_;
212
213     while (my ($command,$control_command) = splice(@commands,0,2)) {
214         # just check to see that control doesn't explode
215         $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
216             and $control_command->{value} !~ /^\s/;
217         send_message(to => 'control@bugs.something',
218                      headers => [To   => 'control@bugs.something',
219                                  From => 'foo@bugs.something',
220                                  Subject => "Munging a bug with $command",
221                                 ],
222                      body => <<EOF) or fail 'message to control@bugs.something failed';
223 debug 10
224 $control_command->{command} $control_command->{value}
225 thanks
226 EOF
227         ;
228         $SD_SIZE =
229             num_messages_sent($SD_SIZE,1,
230                               $sendmail_dir,
231                               'control@bugs.something messages appear to have been sent out properly');
232         # now we need to check to make sure the control message was processed without errors
233         ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
234            'control@bugs.something'. "$command message was parsed without errors");
235         # now we need to check to make sure that the control message actually did anything
236         my $status;
237         $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
238                            exists $control_command->{location}?(location => $control_command->{location}):(),
239                           );
240         is_deeply($status->{$control_command->{status_key}},
241                   $control_command->{status_value},
242                   "bug " .
243                   (exists $control_command->{bug}?$control_command->{bug}:1).
244                   " $command"
245                  )
246             or fail(Dumper($status));
247     }
248 }