From 3f7203cabc12284f6199ec6d66d00de4c0a076c9 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Tue, 27 Feb 2018 14:53:20 -0800 Subject: [PATCH] use Test::PostgreSQL to test whether the postgresql database works at all --- debian/control | 3 +- t/lib/DebbugsTest.pm | 98 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/debian/control b/debian/control index 097852d..7729153 100644 --- a/debian/control +++ b/debian/control @@ -16,7 +16,8 @@ Build-Depends-Indep: libparams-validate-perl, libfile-libmagic-perl, libgravatar-url-perl, libwww-perl, imagemagick, libdbix-class-perl, libdatetime-format-pg-perl, libdatetime-format-mail-perl, - libtext-template-perl, graphviz, libtext-iconv-perl, libnet-server-perl + libtext-template-perl, graphviz, libtext-iconv-perl, libnet-server-perl, + libtest-postgresql-perl Homepage: http://wiki.debian.org/Teams/Debbugs Package: debbugs diff --git a/t/lib/DebbugsTest.pm b/t/lib/DebbugsTest.pm index 6e33399..fcd5ebb 100644 --- a/t/lib/DebbugsTest.pm +++ b/t/lib/DebbugsTest.pm @@ -32,6 +32,7 @@ use File::Basename qw(dirname basename); use IPC::Open3; use IO::Handle; use Test::More; +use Test::PostgreSQL; use Params::Validate qw(validate_with :types); @@ -42,9 +43,10 @@ BEGIN{ @EXPORT = (); %EXPORT_TAGS = (configuration => [qw(dirsize create_debbugs_configuration send_message)], mail => [qw(num_messages_sent)], + database => [qw(create_postgresql_database update_postgresql_database)] ); @EXPORT_OK = (); - Exporter::export_ok_tags(qw(configuration mail)); + Exporter::export_ok_tags(keys %EXPORT_TAGS); $EXPORT_TAGS{all} = [@EXPORT_OK]; } @@ -277,6 +279,100 @@ sub num_messages_sent { return $cur_size; } +=head2 create_postgresql_database + +C + +Create a postgresql database for testing; when the L 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 + print STDERR $pgsql->dsn; + print STDERR "\n"; + my $dbh = DBI->connect($pgsql->dsn); + $dbh->do(<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 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 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; -- 2.39.2