3 use Test::More tests => 35;
8 # Here, we're going to shoot messages through a set of things that can
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.
16 use File::Temp qw(tempdir);
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
22 use DebbugsTest qw(:all);
25 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
29 %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
35 my $sendmail_dir = $config{sendmail_dir};
36 my $spool_dir = $config{spool_dir};
37 my $config_dir = $config{config_dir};
41 diag("spool_dir: $spool_dir\n");
42 diag("config_dir: $config_dir\n");
43 diag("sendmail_dir: $sendmail_dir\n");
47 # We're going to use create mime message to create these messages, and
48 # then just send them to receive.
50 send_message(to=>'submit@bugs.something',
51 headers => [To => 'submit@bugs.something',
52 From => 'foo@bugs.something',
53 Subject => 'Submiting a bug',
55 body => <<EOF) or fail('Unable to send message');
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');
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
71 # This keeps track of the previous size of the sendmail directory
74 num_messages_sent($SD_SIZE,2,
76 'submit messages appear to have been sent out properly',
80 # now send a message to the bug
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',
87 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
95 num_messages_sent($SD_SIZE,2,
97 '1@bugs.something messages appear to have been sent out properly');
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',
105 body => <<EOF) or fail 'message to control@bugs.something failed';
112 num_messages_sent($SD_SIZE,1,
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');
125 # now we're going to go through and methododically test all of the control commands.
126 my @control_commands =
128 clone => {command => 'clone',
130 status_key => 'package',
131 status_value => 'foo',
134 merge => {command => 'merge',
136 status_key => 'mergedwith',
139 unmerge => {command => 'unmerge',
141 status_key => 'mergedwith',
146 test_control_commands(@control_commands);
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",
153 body => <<'EOF') or fail 'message to control@bugs.something failed';
155 clone 2 -1 -2 -3 -4 -5 -6
158 submitter 2 fleb@bleh.com
159 tag 2 unreproducible moreinfo
165 forwarded 2 http://example.com/2
176 num_messages_sent($SD_SIZE,1,
178 'control@bugs.something messages appear to have been sent out properly');
181 test_control_commands(forcemerge => {command => 'forcemerge',
183 status_key => 'mergedwith',
186 unmerge => {command => 'unmerge',
188 status_key => 'mergedwith',
191 forcemerge => {command => 'forcemerge',
193 status_key => 'mergedwith',
194 status_value => '2 5',
196 forcemerge => {command => 'forcemerge',
198 status_key => 'mergedwith',
199 status_value => '2 5 6',
201 merge => {command => 'merge',
203 status_key => 'mergedwith',
210 sub test_control_commands{
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",
222 body => <<EOF) or fail 'message to control@bugs.something failed';
224 $control_command->{command} $control_command->{value}
229 num_messages_sent($SD_SIZE,1,
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
237 $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
238 exists $control_command->{location}?(location => $control_command->{location}):(),
240 is_deeply($status->{$control_command->{status_key}},
241 $control_command->{status_value},
243 (exists $control_command->{bug}?$control_command->{bug}:1).
246 or fail(Dumper($status));