]> git.donarmstrong.com Git - debbugs.git/blob - t/06_mail_handling.t
much more work on the mail hadnling test script
[debbugs.git] / t / 06_mail_handling.t
1 # -*- mode: cperl;-*-
2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
3
4 use Test::More tests => 20;
5
6 use warnings;
7 use strict;
8
9 # Here, we're going to shoot messages through a set of things that can
10 # happen.
11
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.
15
16 use IO::File;
17 use File::Temp qw(tempdir);
18 use Cwd qw(getcwd);
19 use Debbugs::MIME qw(create_mime_message);
20
21
22 my $sendmail_dir = tempdir(CLEANUP => $ENV{DEBUG}?0:1);
23 my $spool_dir = tempdir(CLEANUP => $ENV{DEBUG}?0:1);
24 my $config_dir = tempdir(CLEANUP => $ENV{DEBUG}?0:1);
25
26 END{
27      if ($ENV{DEBUG}) {
28           print STDERR "\nspool_dir:   $spool_dir\n";
29           print STDERR "config_dir:   $config_dir\n";
30           print STDERR "sendmail_dir: $sendmail_dir\n";
31      }
32 }
33
34 $ENV{SENDMAIL_TESTDIR} = $sendmail_dir;
35 my $sendmail_tester = getcwd().'/t/sendmail_tester';
36
37 unless (-x $sendmail_tester) {
38      BAIL_OUT(q(t/sendmail_tester doesn't exist or isn't executable. You may be in the wrong directory.));
39 }
40
41 my %files_to_create = ("$config_dir/debbugs_config" => <<END,
42 \$gSendmail='$sendmail_tester';
43 \$gSpoolDir='$spool_dir';
44 END
45                        "$spool_dir/nextnumber" => qq(1\n),
46                        "$config_dir/Maintainers" => qq(foo Blah Bleargh <bar\@baz.com>),
47                        );
48 while (my ($file,$contents) = each %files_to_create) {
49      my $fh = new IO::File $file,'w' or
50           BAIL_OUT("Unable to create $file: $!");
51      print {$fh} $contents;
52      close $fh;
53 }
54
55 system('touch',"$spool_dir/index.db.realtime");
56 system('ln','-s','index.db.realtime',
57        "$spool_dir/index.db");
58 system('touch',"$spool_dir/index.archive.realtime");
59 system('ln','-s','index.archive.realtime',
60        "$spool_dir/index.archive");
61
62
63 $ENV{DEBBUGS_CONFIG_FILE}  ="$config_dir/debbugs_config";
64
65 # create the spool files and sub directories
66 map {system('mkdir','-p',"$spool_dir/$_"); }
67      map {('db-h/'.$_,'archive/'.$_)}
68      map { sprintf "%02d",$_ % 100} 0..99;
69 system('mkdir','-p',"$spool_dir/incoming");
70
71
72 # We're going to use create mime message to create these messages, and
73 # then just send them to receive.
74
75 # First, check that submit@ works
76
77 $ENV{LOCAL_PART} = 'submit@bugs.something';
78 my $receive = new IO::File ('|scripts/receive.in') or BAIL_OUT("Unable to start receive.in: $!");
79
80 print {$receive} create_mime_message([To   => 'submit@bugs.something',
81                                       From => 'foo@bugs.something',
82                                       Subject => 'Submiting a bug',
83                                      ],
84                                      <<EOF);
85 Package: foo
86 Severity: normal
87
88 This is a silly bug
89 EOF
90
91 close($receive);
92 ok($?==0,'receive took the mail');
93 # now we should run processall to see if the message gets processed
94 ok(system('scripts/processall.in') == 0,'processall ran');
95
96 # now we check to see that we have a bug, and nextnumber has been incremented
97 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
98 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
99 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
100 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
101
102 # next, we check to see that (at least) the proper messages have been
103 # sent out. 1) ack to submitter 2) mail to maintainer
104
105 sub dirsize{
106      my ($dir) = @_;
107      opendir(DIR,$dir);
108      my @content = grep {!/^\.\.?$/} readdir(DIR);
109      closedir(DIR);
110      return scalar @content;
111 }
112
113 # This keeps track of the previous size of the sendmail directory
114 my $SD_SIZE_PREV = 0;
115 my $SD_SIZE_NOW = dirsize($sendmail_dir);
116 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'submit messages appear to have been sent out properly');
117 $SD_SIZE_PREV=$SD_SIZE_NOW;
118
119 # now send a message to the bug
120
121 $ENV{LOCAL_PART} = '1@bugs.something';
122 $receive = new IO::File ('|scripts/receive.in') or
123      BAIL_OUT("Unable to start receive.in: $!");
124
125 print {$receive} create_mime_message([To   => '1@bugs.something',
126                                       From => 'foo@bugs.something',
127                                       Subject => 'Sending a message to a bug',
128                                      ],
129                                      <<EOF);
130 Package: foo
131 Severity: normal
132
133 This is a silly bug
134 EOF
135
136 close($receive);
137 ok($?==0,'receive took the mail');
138 # now we should run processall to see if the message gets processed
139 ok(system('scripts/processall.in') == 0,'processall ran');
140 $SD_SIZE_NOW = dirsize($sendmail_dir);
141 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'1@bugs.something messages appear to have been sent out properly');
142 $SD_SIZE_PREV=$SD_SIZE_NOW;
143
144 # just check to see that control doesn't explode
145 $ENV{LOCAL_PART} = 'control@bugs.something';
146 $receive = new IO::File ('|scripts/receive.in') or
147      BAIL_OUT("Unable to start receive.in: $!");
148
149 print {$receive} create_mime_message([To   => 'control@bugs.something',
150                                       From => 'foo@bugs.something',
151                                       Subject => 'Munging a bug',
152                                      ],
153                                      <<EOF);
154 severity 1 wishlist
155 thanks
156 EOF
157
158 close($receive);
159 ok($?==0,'receive took the mail');
160 # now we should run processall to see if the message gets processed
161 ok(system('scripts/processall.in') == 0,'processall ran');
162 $SD_SIZE_NOW = dirsize($sendmail_dir);
163 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'1@bugs.something messages appear to have been sent out properly');
164 $SD_SIZE_PREV=$SD_SIZE_NOW;
165
166
167