X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=t%2Flib%2FDebbugsTest.pm;h=603b6ecd35a904f7af49424c831bf6fd09326b5a;hb=a89fb6f83e17fe0afe9436227c50a7a78be8321e;hp=39a791c79f923bd4c4c91bde438d11758621ca8c;hpb=1474e155834038b1afe42ec1a99f863d8f3647cd;p=debbugs.git diff --git a/t/lib/DebbugsTest.pm b/t/lib/DebbugsTest.pm index 39a791c..603b6ec 100644 --- a/t/lib/DebbugsTest.pm +++ b/t/lib/DebbugsTest.pm @@ -31,6 +31,7 @@ use Debbugs::MIME qw(create_mime_message); use File::Basename qw(dirname basename); use IPC::Open3; use IO::Handle; +use Test::More; use Params::Validate qw(validate_with :types); @@ -40,9 +41,10 @@ BEGIN{ @EXPORT = (); %EXPORT_TAGS = (configuration => [qw(dirsize create_debbugs_configuration send_message)], + mail => [qw(num_messages_sent)], ); @EXPORT_OK = (); - Exporter::export_ok_tags(qw(configuration)); + Exporter::export_ok_tags(qw(configuration mail)); $EXPORT_TAGS{all} = [@EXPORT_OK]; } @@ -80,16 +82,19 @@ sub create_debbugs_configuration { \$gSpoolDir='$spool_dir'; \$gLibPath='@{[getcwd()]}/scripts'; \$gTemplateDir='@{[getcwd()]}/templates'; +\$gWebDir='@{[getcwd()]}/html'; \$gWebHost='localhost'; 1; END "$spool_dir/nextnumber" => qq(1\n), "$config_dir/Maintainers" => qq(foo Blah Bleargh \nbar Bar Bleargh \n), "$config_dir/Maintainers.override" => qq(), + "$config_dir/Source_maintainers" => qq(foo Blah Bleargh \nbar Bar Bleargh \n), "$config_dir/indices/sources" => < '', + "$config_dir/pseudo-packages.maintainers" => '', ); while (my ($file,$contents) = each %files_to_create) { system('mkdir','-p',dirname($file)); @@ -107,9 +112,11 @@ END "$spool_dir/index.archive"); # create the spool files and sub directories - map {system('mkdir','-p',"$spool_dir/$_"); } - map {('db-h/'.$_,'archive/'.$_)} - map { sprintf "%02d",$_ % 100} 0..99; + for my $dir (0..99) { + for my $archive (qw(db-h archive)) { + system('mkdir','-p',"$spool_dir/$archive/".sprintf('%02d',$dir)); + } + } system('mkdir','-p',"$spool_dir/incoming"); system('mkdir','-p',"$spool_dir/lock"); @@ -141,6 +148,9 @@ sub send_message{ }, body => {type => SCALAR, }, + attachments => {type => ARRAYREF, + default => [], + }, run_processall =>{type => BOOLEAN, default => 1, }, @@ -149,13 +159,17 @@ sub send_message{ $ENV{LOCAL_PART} = $param{to}; my ($rfd,$wfd); my $output=''; - local $SIG{PIPE} = 'IGNORE'; - local $SIG{CHLD} = sub {}; + my $pipe_handler = $SIG{PIPE}; + $SIG{PIPE} = 'IGNORE'; + $SIG{CHLD} = 'DEFAULT'; my $pid = open3($wfd,$rfd,$rfd,'scripts/receive') or die "Unable to start receive: $!"; print {$wfd} create_mime_message($param{headers}, - $param{body}) or die "Unable to to print to receive"; + $param{body}, + $param{attachments}) or + die "Unable to to print to receive"; close($wfd) or die "Unable to close receive"; + $SIG{PIPE} = $pipe_handler; my $err = $? >> 8; my $childpid = waitpid($pid,0); if ($childpid != -1) { @@ -181,7 +195,7 @@ sub send_message{ { package DebbugsTest::HTTPServer; - use base qw(HTTP::Server::Simple::CGI); + use base qw(HTTP::Server::Simple::CGI HTTP::Server::Simple::CGI::Environment); our $child_pid = undef; our $webserver = undef; @@ -230,6 +244,25 @@ sub send_message{ } } +=head2 num_messages_sent + + $SD_SIZE = num_messages_sent($SD_SIZE,2,$sendmail_dir,'2 messages have been sent properly'); + +Tests to make sure that at least a certain number of messages have +been sent since the last time this command was run. Usefull to test to +make sure that mail has been sent. + +=cut + +sub num_messages_sent { + my ($prev_size,$num_messages,$sendmail_dir,$test_name) = @_; + my $cur_size = dirsize($sendmail_dir); + ## print STDERR "sendmail: $sendmail_dir, want: $num_messages, + ## size: $cur_size, prev_size: $prev_size\n"; + ok($cur_size-$prev_size >= $num_messages, $test_name); + return $cur_size; +} + 1;