4 use Test::More tests => 21;
9 # Here, we're going to shoot messages through a set of things that can
12 # First, we're going to send mesages to receive.
13 # To do so, we'll first send a message to submit,
14 # then send messages to the newly created bugnumber.
17 use File::Temp qw(tempdir);
19 use Debbugs::MIME qw(create_mime_message);
20 use File::Basename qw(dirname basename);
21 # The test functions are placed here to make things easier
23 use DebbugsTest qw(:all);
26 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
28 my %config = create_debbugs_configuration();
31 my $sendmail_dir = $config{sendmail_dir};
32 my $spool_dir = $config{spool_dir};
33 my $config_dir = $config{config_dir};
37 # We're going to use create mime message to create these messages, and
38 # then just send them to receive.
40 send_message(to=>'submit@bugs.something',
41 headers => [To => 'submit@bugs.something',
42 From => 'foo@bugs.something',
43 Subject => 'Submiting a bug',
45 body => <<EOF) or fail('Unable to send message');
52 # now we check to see that we have a bug, and nextnumber has been incremented
53 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
54 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
55 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
56 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
58 # next, we check to see that (at least) the proper messages have been
59 # sent out. 1) ack to submitter 2) mail to maintainer
61 # This keeps track of the previous size of the sendmail directory
63 my $SD_SIZE_NOW = dirsize($sendmail_dir);
64 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'submit messages appear to have been sent out properly');
65 $SD_SIZE_PREV=$SD_SIZE_NOW;
67 # now send a message to the bug
69 send_message(to => '1@bugs.something',
70 headers => [To => '1@bugs.something',
71 From => 'foo@bugs.something',
72 Subject => 'Sending a message to a bug',
74 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
81 $SD_SIZE_NOW = dirsize($sendmail_dir);
82 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'1@bugs.something messages appear to have been sent out properly');
83 $SD_SIZE_PREV=$SD_SIZE_NOW;
85 # just check to see that control doesn't explode
86 send_message(to => 'control@bugs.something',
87 headers => [To => 'control@bugs.something',
88 From => 'foo@bugs.something',
89 Subject => 'Munging a bug',
91 body => <<EOF) or fail 'message to control@bugs.something failed';
97 $SD_SIZE_NOW = dirsize($sendmail_dir);
98 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
99 $SD_SIZE_PREV=$SD_SIZE_NOW;
100 # now we need to check to make sure the control message was processed without errors
101 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
102 'control@bugs.something message was parsed without errors');
103 # now we need to check to make sure that the control message actually did anything
104 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
105 eval "use Debbugs::Status qw(read_bug writebug);";
106 my $status = read_bug(bug=>1);
107 ok($status->{subject} eq 'new title','bug 1 retitled');
108 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');
110 # now we're going to go through and methododically test all of the control commands.
111 my @control_commands =
112 (close => {command => 'close',
114 status_key => 'done',
115 status_value => 'foo@bugs.something',
117 archive => {command => 'archive',
119 status_key => 'owner',
121 location => 'archive',
123 unarchive => {command => 'unarchive',
125 status_key => 'owner',
130 # In order for the archive/unarchive to work, we have to munge the summary file slightly
131 $status = read_bug(bug => 1);
132 $status->{unarchived} = time;
134 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
135 # just check to see that control doesn't explode
136 $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
137 and $control_command->{value} !~ /^\s/;
138 send_message(to => 'control@bugs.something',
139 headers => [To => 'control@bugs.something',
140 From => 'foo@bugs.something',
141 Subject => "Munging a bug with $command",
143 body => <<EOF) or fail 'message to control@bugs.something failed';
145 $control_command->{command} 1$control_command->{value}
149 $SD_SIZE_NOW = dirsize($sendmail_dir);
150 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
151 $SD_SIZE_PREV=$SD_SIZE_NOW;
152 # now we need to check to make sure the control message was processed without errors
153 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")) == 0,
154 'control@bugs.something'. "$command message was parsed without errors");
155 # now we need to check to make sure that the control message actually did anything
157 $status = read_bug(bug=>1,
158 exists $control_command->{location}?(location => $control_command->{location}):(),
160 is_deeply($status->{$control_command->{status_key}},$control_command->{status_value},"bug 1 $command")
161 or fail(Dumper($status));
164 # now we need to run expire, and make sure that bug is expired
166 # we punt and touch to set it to something that is archiveable
168 # set the access time to twice the remove age
169 my $old_time = time - 28*2*24*60*60;
171 system('touch','-d','@'.$old_time,"$spool_dir/db-h/01/1.log", );
172 system('touch','-d','@'.$old_time,"$spool_dir/db-h/01/1.summary",);
173 system('touch','-d','@'.$old_time,"$spool_dir/db-h/01/1.status", );
174 system('touch','-d','@'.$old_time,"$spool_dir/db-h/01/1.report", );
175 ok(system('scripts/expire') == 0,'expire completed successfully');
177 ok($status = read_bug(bug => 1,location => 'archive'),'read bug from archive correctly');