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();
35 my $sendmail_dir = $config{sendmail_dir};
36 my $spool_dir = $config{spool_dir};
37 my $config_dir = $config{config_dir};
41 # We're going to use create mime message to create these messages, and
42 # then just send them to receive.
44 send_message(to=>'submit@bugs.something',
45 headers => [To => 'submit@bugs.something',
46 From => 'foo@bugs.something',
47 Subject => 'Submiting a bug',
49 body => <<EOF) or fail('Unable to send message');
56 # now we check to see that we have a bug, and nextnumber has been incremented
57 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
58 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
59 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
60 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
62 # next, we check to see that (at least) the proper messages have been
63 # sent out. 1) ack to submitter 2) mail to maintainer
65 # This keeps track of the previous size of the sendmail directory
68 num_messages_sent($SD_SIZE,2,
70 'submit messages appear to have been sent out properly',
74 # now send a message to the bug
76 send_message(to => '1@bugs.something',
77 headers => [To => '1@bugs.something',
78 From => 'foo@bugs.something',
79 Subject => 'Sending a message to a bug',
81 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
89 num_messages_sent($SD_SIZE,2,
91 '1@bugs.something messages appear to have been sent out properly');
93 # just check to see that control doesn't explode
94 send_message(to => 'control@bugs.something',
95 headers => [To => 'control@bugs.something',
96 From => 'foo@bugs.something',
97 Subject => 'Munging a bug',
99 body => <<EOF) or fail 'message to control@bugs.something failed';
106 num_messages_sent($SD_SIZE,1,
108 'control@bugs.something messages appear to have been sent out properly');
109 # now we need to check to make sure the control message was processed without errors
110 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
111 'control@bugs.something message was parsed without errors');
112 # now we need to check to make sure that the control message actually did anything
113 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
114 eval "use Debbugs::Status qw(read_bug writebug);";
115 my $status = read_bug(bug=>1);
116 ok($status->{subject} eq 'new title','bug 1 retitled');
117 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');
119 # now we're going to go through and methododically test all of the control commands.
120 my @control_commands =
122 clone => {command => 'clone',
124 status_key => 'package',
125 status_value => 'foo',
128 merge => {command => 'merge',
130 status_key => 'mergedwith',
133 unmerge => {command => 'unmerge',
135 status_key => 'mergedwith',
140 test_control_commands(@control_commands);
142 send_message(to => 'control@bugs.something',
143 headers => [To => 'control@bugs.something',
144 From => 'foo@bugs.something',
145 Subject => "Munging a bug with lots of stuff",
147 body => <<'EOF') or fail 'message to control@bugs.something failed';
149 clone 2 -1 -2 -3 -4 -5 -6
152 submitter 2 fleb@bleh.com
153 tag 2 unreproducible moreinfo
159 forwarded 2 http://example.com/2
170 num_messages_sent($SD_SIZE,1,
172 'control@bugs.something messages appear to have been sent out properly');
175 test_control_commands(forcemerge => {command => 'forcemerge',
177 status_key => 'mergedwith',
180 unmerge => {command => 'unmerge',
182 status_key => 'mergedwith',
185 forcemerge => {command => 'forcemerge',
187 status_key => 'mergedwith',
188 status_value => '2 5',
190 forcemerge => {command => 'forcemerge',
192 status_key => 'mergedwith',
193 status_value => '2 5 6',
195 merge => {command => 'merge',
197 status_key => 'mergedwith',
204 sub test_control_commands{
207 while (my ($command,$control_command) = splice(@commands,0,2)) {
208 # just check to see that control doesn't explode
209 $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
210 and $control_command->{value} !~ /^\s/;
211 send_message(to => 'control@bugs.something',
212 headers => [To => 'control@bugs.something',
213 From => 'foo@bugs.something',
214 Subject => "Munging a bug with $command",
216 body => <<EOF) or fail 'message to control@bugs.something failed';
218 $control_command->{command} $control_command->{value}
223 num_messages_sent($SD_SIZE,1,
225 'control@bugs.something messages appear to have been sent out properly');
226 # now we need to check to make sure the control message was processed without errors
227 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
228 'control@bugs.something'. "$command message was parsed without errors");
229 # now we need to check to make sure that the control message actually did anything
231 $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
232 exists $control_command->{location}?(location => $control_command->{location}):(),
234 is_deeply($status->{$control_command->{status_key}},
235 $control_command->{status_value},
237 (exists $control_command->{bug}?$control_command->{bug}:1).
240 or fail(Dumper($status));