2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
4 use Test::More tests => 31;
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);
28 %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
34 my $sendmail_dir = $config{sendmail_dir};
35 my $spool_dir = $config{spool_dir};
36 my $config_dir = $config{config_dir};
40 diag("spool_dir: $spool_dir\n");
41 diag("config_dir: $config_dir\n");
42 diag("sendmail_dir: $sendmail_dir\n");
46 # We're going to use create mime message to create these messages, and
47 # then just send them to receive.
49 send_message(to=>'submit@bugs.something',
50 headers => [To => 'submit@bugs.something',
51 From => 'foo@bugs.something',
52 Subject => 'Submiting a bug',
54 body => <<EOF) or fail('Unable to send message');
61 # now we check to see that we have a bug, and nextnumber has been incremented
62 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
63 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
64 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
65 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
67 # next, we check to see that (at least) the proper messages have been
68 # sent out. 1) ack to submitter 2) mail to maintainer
70 # This keeps track of the previous size of the sendmail directory
72 my $SD_SIZE_NOW = dirsize($sendmail_dir);
73 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'submit messages appear to have been sent out properly');
74 $SD_SIZE_PREV=$SD_SIZE_NOW;
76 # now send a message to the bug
78 send_message(to => '1@bugs.something',
79 headers => [To => '1@bugs.something',
80 From => 'foo@bugs.something',
81 Subject => 'Sending a message to a bug',
83 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
90 $SD_SIZE_NOW = dirsize($sendmail_dir);
91 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'1@bugs.something messages appear to have been sent out properly');
92 $SD_SIZE_PREV=$SD_SIZE_NOW;
94 # just check to see that control doesn't explode
95 send_message(to => 'control@bugs.something',
96 headers => [To => 'control@bugs.something',
97 From => 'foo@bugs.something',
98 Subject => 'Munging a bug',
100 body => <<EOF) or fail 'message to control@bugs.something failed';
106 $SD_SIZE_NOW = dirsize($sendmail_dir);
107 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
108 $SD_SIZE_PREV=$SD_SIZE_NOW;
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);";
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 =
121 (severity_wishlist => {command => 'severity',
123 status_key => 'severity',
124 status_value => 'wishlist',
126 'found_1.0' => {command => 'found',
128 status_key => 'found_versions',
129 status_value => ['1.0'],
131 'notfound_1.0' => {command => 'notfound',
133 status_key => 'found_versions',
136 submitter_foo => {command => 'submitter',
137 value => 'foo@bar.com',
138 status_key => 'originator',
139 status_value => 'foo@bar.com',
142 forwarded_foo => {command => 'forwarded',
143 value => 'foo@bar.com',
144 status_key => 'forwarded',
145 status_value => 'foo@bar.com',
147 owner_foo => {command => 'owner',
148 value => 'foo@bar.com',
149 status_key => 'owner',
150 status_value => 'foo@bar.com',
152 noowner => {command => 'noowner',
154 status_key => 'owner',
160 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
161 # just check to see that control doesn't explode
162 $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
163 and $control_command->{value} !~ /^\s/;
164 send_message(to => 'control@bugs.something',
165 headers => [To => 'control@bugs.something',
166 From => 'foo@bugs.something',
167 Subject => "Munging a bug with $command",
169 body => <<EOF) or fail 'message to control@bugs.something failed';
170 $control_command->{command} 1$control_command->{value}
174 $SD_SIZE_NOW = dirsize($sendmail_dir);
175 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 1,'control@bugs.something messages appear to have been sent out properly');
176 $SD_SIZE_PREV=$SD_SIZE_NOW;
177 # now we need to check to make sure the control message was processed without errors
178 ok(system("sh -c 'find ".$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command"')) == 0,
179 'control@bugs.something'. "$command message was parsed without errors");
180 # now we need to check to make sure that the control message actually did anything
181 my $status = read_bug(bug=>1);
182 is_deeply($status->{$control_command->{status_key}},$control_command->{status_value},"bug 1 $command")
183 or fail(Dumper($status));