@EXPORT = ();
%EXPORT_TAGS = (configuration => [qw(dirsize create_debbugs_configuration send_message)],
mail => [qw(num_messages_sent)],
+ control => [qw(test_control_commands)],
);
@EXPORT_OK = ();
- Exporter::export_ok_tags(qw(configuration mail));
+ Exporter::export_ok_tags(qw(configuration mail control));
$EXPORT_TAGS{all} = [@EXPORT_OK];
}
sub create_debbugs_configuration {
my %param = validate_with(params => \@_,
spec => {debug => {type => BOOLEAN,
- default => 0,
+ default => exists $ENV{DEBUG}?
+ $ENV{DEBUG}:0,
},
cleanup => {type => BOOLEAN,
optional => 1,
$ENV{DEBBUGS_CONFIG_FILE} ="$config_dir/debbugs_config";
$ENV{PERL5LIB} = getcwd();
$ENV{SENDMAIL_TESTDIR} = $sendmail_dir;
+ eval {
my $sendmail_tester = getcwd().'/t/sendmail_tester';
unless (-x $sendmail_tester) {
die q(t/sendmail_tester doesn't exist or isn't executable. You may be in the wrong directory.);
\$gSpoolDir='$spool_dir';
\$gLibPath='@{[getcwd()]}/scripts';
\$gTemplateDir='@{[getcwd()]}/templates';
+\$gWebDir='@{[getcwd()]}/html';
\$gWebHost='localhost';
1;
END
foo main foo
END
"$config_dir/pseudo-packages.description" => '',
+ "$config_dir/pseudo-packages.maintainers" => '',
);
while (my ($file,$contents) = each %files_to_create) {
system('mkdir','-p',dirname($file));
"$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");
+ # generate the maintainers index files
+ system('scripts/maintainer-indices') == 0
+ or die "Unable to generate maintainer index files";
+ eval '
+END{
+ if ($ENV{DEBUG}) {
+ diag("spool_dir: $spool_dir\n");
+ diag("config_dir: $config_dir\n",);
+ diag("sendmail_dir: $sendmail_dir\n");
+ }
+}';
+ };
+ BAIL_OUT ($@) if ($@);
return (spool_dir => $spool_dir,
sendmail_dir => $sendmail_dir,
config_dir => $config_dir,
},
body => {type => SCALAR,
},
+ attachments => {type => ARRAYREF,
+ default => [],
+ },
run_processall =>{type => BOOLEAN,
default => 1,
},
$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) {
}
}
+=item test_control_commands
+
+ test_control_commands(\%config,
+ forcemerge => {command => 'forcemerge',
+ value => '1 2',
+ status_key => 'mergedwith',
+ status_value => '2',
+ expect_error => 0,
+ });
+
+Test a set of control commands to see if they will fail or not. Takes
+SCALAR/HASHREF pairs, where the scalar should be unique, and the HASHREF
+contains the following keys:
+
+=over
+
+=item command -- control command to issue
+
+=item value -- value to pass to control command
+
+=item status_key -- bug status key to check
+
+=item status_value -- value of status key
+
+=item expect_error -- whether to expect the control command to error or not
+
+=back
+
+=cut
+
+sub test_control_commands {
+ my ($config,@commands) = @_;
+
+ # now we need to check to make sure that the control message actually did anything
+ # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
+ eval "use Debbugs::Status qw(read_bug writebug);";
+ while (my ($command,$control_command) = splice(@commands,0,2)) {
+ # just check to see that control doesn't explode
+ $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
+ and $control_command->{value} !~ /^\s/;
+ send_message(to => 'control@bugs.something',
+ headers => [To => 'control@bugs.something',
+ From => 'foo@bugs.something',
+ Subject => "Munging a bug with $command",
+ ],
+ body => <<EOF) or fail 'message to control@bugs.something failed';
+debug 10
+$control_command->{command} $control_command->{value}
+thanks
+EOF
+ ;
+ # now we need to check to make sure the control message was processed without errors
+ if (not ($control_command->{expect_error} // 0)) {
+ ok(system('sh','-c','find '.$config->{sendmail_dir}.
+ q( -type f | xargs grep -q "Subject: Processed: Munging a bug with $command")
+ ) == 0,
+ 'control@bugs.something'. "$command message was parsed without errors");
+ }
+ # now we need to check to make sure that the control message actually did anything
+ my $status;
+ $status = read_bug(exists $control_command->{bug}?(bug => $control_command->{bug}):(bug=>1),
+ exists $control_command->{location}?(location => $control_command->{location}):(),
+ );
+ is_deeply($status->{$control_command->{status_key}},
+ $control_command->{status_value},
+ "bug " .
+ (exists $control_command->{bug}?$control_command->{bug}:1).
+ " $command"
+ )
+ or fail(Data::Dumper->Dump([$status],[qw(status)]));
+ }
+}
+
+
+$SIG{CHLD} = sub {};
+
{
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;