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.
27 my %config = create_debbugs_configuration();
30 my $sendmail_dir = $config{sendmail_dir};
31 my $spool_dir = $config{spool_dir};
32 my $config_dir = $config{config_dir};
36 # We're going to use create mime message to create these messages, and
37 # then just send them to receive.
39 send_message(to=>'submit@bugs.something',
40 headers => [To => 'submit@bugs.something',
41 From => 'foo@bugs.something',
42 Subject => 'Submiting a bug',
44 body => <<EOF) or fail('Unable to send message');
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');
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
60 # This keeps track of the previous size of the sendmail directory
63 num_messages_sent($SD_SIZE,2,
65 'submit messages appear to have been sent out properly',
69 # now send a message to the bug
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',
76 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
84 num_messages_sent($SD_SIZE,2,
86 '1@bugs.something messages appear to have been sent out properly');
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',
94 body => <<EOF) or fail 'message to control@bugs.something failed';
101 num_messages_sent($SD_SIZE,1,
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');
114 # now we're going to go through and methododically test all of the control commands.
115 my @control_commands =
117 clone => {command => 'clone',
119 status_key => 'package',
120 status_value => 'foo',
123 merge => {command => 'merge',
125 status_key => 'mergedwith',
128 unmerge => {command => 'unmerge',
130 status_key => 'mergedwith',
135 test_control_commands(@control_commands);
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",
142 body => <<'EOF') or fail 'message to control@bugs.something failed';
144 clone 2 -1 -2 -3 -4 -5 -6
147 submitter 2 fleb@bleh.com
148 tag 2 unreproducible moreinfo
154 forwarded 2 http://example.com/2
165 num_messages_sent($SD_SIZE,1,
167 'control@bugs.something messages appear to have been sent out properly');
170 test_control_commands(forcemerge => {command => 'forcemerge',
172 status_key => 'mergedwith',
175 unmerge => {command => 'unmerge',
177 status_key => 'mergedwith',
180 forcemerge => {command => 'forcemerge',
182 status_key => 'mergedwith',
183 status_value => '2 5',
185 forcemerge => {command => 'forcemerge',
187 status_key => 'mergedwith',
188 status_value => '2 5 6',
190 merge => {command => 'merge',
192 status_key => 'mergedwith',
199 sub test_control_commands{
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",
211 body => <<EOF) or fail 'message to control@bugs.something failed';
213 $control_command->{command} $control_command->{value}
218 num_messages_sent($SD_SIZE,1,
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
226 $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
227 exists $control_command->{location}?(location => $control_command->{location}):(),
229 is_deeply($status->{$control_command->{status_key}},
230 $control_command->{status_value},
232 (exists $control_command->{bug}?$control_command->{bug}:1).
235 or fail(Dumper($status));