use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
use base qw(Exporter);
+use v5.10;
+
use IO::File;
use File::Temp qw(tempdir);
use Cwd qw(getcwd);
use IPC::Open3;
use IO::Handle;
use Test::More;
+use Test::PostgreSQL;
use Params::Validate qw(validate_with :types);
$DEBUG = 0 unless defined $DEBUG;
@EXPORT = ();
- %EXPORT_TAGS = (configuration => [qw(dirsize create_debbugs_configuration send_message)],
+ %EXPORT_TAGS = (configuration => [qw(dirsize create_debbugs_configuration send_message),
+ qw(submit_bug run_processall)],
mail => [qw(num_messages_sent)],
control => [qw(test_control_commands)],
+ database => [qw(create_postgresql_database update_postgresql_database)]
);
@EXPORT_OK = ();
- Exporter::export_ok_tags(qw(configuration mail control));
+ Exporter::export_ok_tags(keys %EXPORT_TAGS);
$EXPORT_TAGS{all} = [@EXPORT_OK];
}
$ENV{DEBBUGS_CONFIG_FILE} ="$config_dir/debbugs_config";
- $ENV{PERL5LIB} = getcwd();
+ $ENV{PERL5LIB} = getcwd().'/lib/';
$ENV{SENDMAIL_TESTDIR} = $sendmail_dir;
eval {
my $sendmail_tester = getcwd().'/t/sendmail_tester';
}
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}) {
}
# now we should run processall to see if the message gets processed
if ($param{run_processall}) {
- system('scripts/processall') == 0 or die "processall failed";
- }
+ run_processall();
+ }
+ return 1;
+}
+
+sub run_processall {
+ system('scripts/processall') == 0 or die "processall failed";
}
=item test_control_commands
(exists $control_command->{bug}?$control_command->{bug}:1).
" $command"
)
- or fail(Dumper($status));
+ or fail(Data::Dumper->Dump([$status],[qw(status)]));
}
}
+sub submit_bug {
+ state $spec =
+ {subject => {type => SCALAR,
+ default => 'Submitting a bug',
+ },
+ body => {type => SCALAR,
+ default => 'This is a silly bug',
+ },
+ submitter => {type => SCALAR,
+ default => 'foo@bugs.something',
+ },
+ pseudoheaders => {type => HASHREF,
+ default => sub {{}},
+ },
+ package => {type => SCALAR,
+ default => 'foo',
+ },
+ run_processall => {type => SCALAR,
+ default => 0,
+ },
+ };
+ my %param =
+ validate_with(params => \@_,
+ spec => $spec);
+ my $body = 'Package: '.$param{package}."\n";
+ foreach my $key (keys %{$param{pseudoheaders}}) {
+ for my $val (ref($param{pseudoheaders}{$key}) ?
+ @{$param{pseudoheaders}{$key}} :
+ $param{pseudoheaders}{$key}) {
+ $body .= $key. ': '.$val."\n";
+ }
+ }
+ $body .="\n".$param{body};
+ send_message(to => 'submit@bugs.something',
+ headers => [To => 'submit@bugs.something',
+ From => $param{submitter},
+ Subject => $param{subject},
+ ],
+ run_processall => $param{run_processall},
+ body => $body
+ );
+}
-$SIG{CHLD} = sub {};
{
package DebbugsTest::HTTPServer;
return $cur_size;
}
+=head2 create_postgresql_database
+
+C<my $pgsql = create_postgresql_database();>
+
+Create a postgresql database for testing; when the L<Test::PostgreSQL> object it
+returns is destroyed (or goes out of scope) the database will be removed.
+
+=cut
+
+sub create_postgresql_database {
+ my $pgsql = Test::PostgreSQL->new(use_socket => 1) or
+ return undef;
+ my $installsql =
+ File::Spec->rel2abs(dirname(__FILE__).'/../..').
+ '/bin/debbugs-installsql';
+ # create the debversion extension
+ my $dbh = DBI->connect($pgsql->dsn);
+ $dbh->do(<<END) or die "Unable to create extension";
+CREATE EXTENSION IF NOT EXISTS debversion;
+END
+ # create the schema for the bug tracking system
+ my $dep_dir = File::Temp::tempdir(CLEANUP=>1);
+ system($installsql,
+ '--dsn',$pgsql->dsn,
+ '--install',
+ '--deployment-dir',$dep_dir);
+
+ initialize_postgresql_database($pgsql,@_);
+ return $pgsql;
+}
+
+=item iniitalize_postgresql_database
+
+C<initialize_postgresql_database();>
+
+Initialize postgresql database by calling debbugs-loadsql appropriately.
+
+=cut
+
+sub initialize_postgresql_database {
+ my ($pgsql,@options) = @_;
+ my $loadsql =
+ File::Spec->rel2abs(dirname(__FILE__).'/../..').
+ '/bin/debbugs-loadsql';
+
+ my $ftpdists =
+ File::Spec->rel2abs(dirname(__FILE__).'/../debian/dist');
+ my $debinfo_dir =
+ File::Spec->rel2abs(dirname(__FILE__).'/../debian/debinfo');
+ my %loadsql_commands =
+ (configuration => [],
+ suites => ['--ftpdists',$ftpdists],
+ debinfo => ['--debinfo-dir',$debinfo_dir],
+ packages => ['--ftpdists',$ftpdists],
+ maintainers => [],
+ );
+ for my $command (keys %loadsql_commands) {
+ system($loadsql,$command,
+ '--dsn',$pgsql->dsn,
+ @options,
+ @{$loadsql_commands{$command}}) == 0 or
+ die "Unable to load $command";
+ }
+}
+
+
+=item update_postgresql_database
+
+C<update_postgresql_database();>
+
+Update the postgresql database by calling debbugs-loadsql appropriately.
+
+=cut
+sub update_postgresql_database {
+ my ($pgsql,@options) = @_;
+ my $loadsql =
+ File::Spec->rel2abs(dirname(__FILE__).'/../..').
+ '/bin/debbugs-loadsql';
+
+ my %loadsql_commands =
+ (bugs_and_logs => [],
+ );
+ for my $command (keys %loadsql_commands) {
+ system($loadsql,$command,
+ '--dsn',$pgsql->dsn,
+ @options,
+ @{$loadsql_commands{$command}}) == 0 or
+ die "Unable to load $command";
+ }
+}
+
+
1;