Commit e94393a8 authored by Martin Pitt's avatar Martin Pitt

rewrote tests using higher level functions of TestLib

parent 1d6a2e39
......@@ -10,19 +10,10 @@ use Test::More tests => 4;
use lib 't';
use TestLib;
open (OUT, '-|', 'psql', '--version') or die "call psql: $!";
$_ = <OUT>;
my @F = split;
like ($F[-1], qr/$LATEST_MAJOR\.\d/, 'pg_wrapper selects highest available version number');
close OUT;
is ($?, 0, 'psql --version exits successfully'); # check exit code
like_program_out 0, 'psql --version', 0, qr/^psql \(PostgreSQL\) $LATEST_MAJOR\.\d\b/,
'pg_wrapper selects highest available version number';
close STDERR;
open (OUT, '-|', 'psql', '-h', '127.0.0.1', '-l') or die "call psql: $!";
<OUT>;
@F = split;
like ($F[-1], qr/$LATEST_MAJOR\.\d/, 'pg_wrapper selects highest available version number');
close OUT;
is ($? >> 8, 2, 'connecting to localhost fails with no clusters'); # check failure exit code
like_program_out 0, 'psql -h 127.0.0.1 -l', 2, qr/could not connect/,
'connecting to localhost fails with no clusters';
# vim: filetype=perl
......@@ -10,7 +10,7 @@ use TestLib;
use lib '/usr/share/postgresql-common';
use PgCommon;
use Test::More tests => 29 * ($#MAJORS+1);
use Test::More tests => 30 * ($#MAJORS+1);
sub check_major {
my $v = $_[0];
......@@ -29,12 +29,8 @@ sub check_major {
}
# verify that the correct client version is selected
open (OUT, '-|', 'psql', '--version') or die "call psql: $!";
$_ = <OUT>;
close OUT;
die 'psql --version failed' if $?;
my @F = split;
like ($F[-1], qr/$v\.\d/, 'pg_wrapper selects version number of cluster');
like_program_out 'postgres', 'psql --version', 0, qr/^psql \(PostgreSQL\) $v\.\d/,
'pg_wrapper selects version number of cluster';
# verify that the cluster is displayed
my $ls = `pg_lsclusters -h`;
......@@ -71,26 +67,24 @@ template1|postgres|UNICODE
is ((exec_as 'nobody', 'psql nobodydb -c "insert into phone values (\'Bob\', 3)"'), 1, 'primary key violation');
# Check table contents
is ((exec_as 'nobody', 'psql -tAc "select * from phone order by name" nobodydb', $outref), 0, 'SQL command: select');
is ($$outref, 'Alice|2
is_program_out 'nobody', 'psql -tAc "select * from phone order by name" nobodydb', 0,
'Alice|2
Bob|1
', 'SQL command output: select');
', 'SQL command output: select';
# Check pg_maintenance
is ((exec_as 0, 'pg_maintenance', $outref), 0, 'pg_maintenance succeeds');
if ($pg_autovacuum || $v ge '8.1') {
like $$outref, qr/^Skipping/, 'pg_maintenance skips autovacuumed cluster';
like_program_out 0, 'pg_maintenance', 0, qr/^Skipping/, 'pg_maintenance skips autovacuumed cluster';
} else {
like $$outref, qr/^Doing/, 'pg_maintenance handles non-autovacuumed cluster';
like_program_out 0, 'pg_maintenance', 0, qr/^Doing/, 'pg_maintenance handles non-autovacuumed cluster';
}
is ((exec_as 0, 'pg_maintenance --force', $outref), 0,
'pg_maintenance --force succeeds');
like $$outref, qr/^Doing/, 'pg_maintenance --force always handles cluster';
like_program_out 0, 'pg_maintenance --force', 0, qr/^Doing/,
'pg_maintenance --force always handles cluster';
# Drop database and user again.
sleep 1;
is ((exec_as 'nobody', 'dropdb nobodydb'), 0, 'dropdb nobodydb');
is ((exec_as 'postgres', 'dropuser nobody'), 0, 'dropuser nobody');
is ((exec_as 'nobody', 'dropdb nobodydb', $outref, 0), 0, 'dropdb nobodydb', );
is ((exec_as 'postgres', 'dropuser nobody', $outref, 0), 0, 'dropuser nobody');
# stop server, clean up, check for leftovers
ok ((system "pg_dropcluster $v main --stop-server") == 0,
......
......@@ -6,7 +6,7 @@ use strict;
use lib 't';
use TestLib;
use Test::More tests => 33;
use Test::More tests => 37;
use lib '/usr/share/postgresql-common';
use PgCommon;
......@@ -73,57 +73,49 @@ ok_dir $socketdir, [], "No sockets in $socketdir";
rename "/var/lib/postgresql/$version/main/postmaster.pid",
"/var/lib/postgresql/$version/main/postmaster.pid.orig" or die "rename: $!";
create_foo_pid;
is ((exec_as 'postgres', "pg_ctlcluster $version main stop", my $outref), 1,
'pg_ctlcluster fails with corrupted PID file');
is $$outref, "Error: pid file is invalid, please manually kill the stale server process.\n",
'correct pg_ctlcluster error message';
like (`pg_lsclusters -h`, qr/online/, 'cluster is still online');
is_program_out 'postgres', "pg_ctlcluster $version main stop", 1,
"Error: pid file is invalid, please manually kill the stale server process.\n",
'pg_ctlcluster fails with corrupted PID file';
like_program_out 'postgres', 'pg_lsclusters -h', 0, qr/online/, 'cluster is still online';
# restore PID file
(system "cp /var/lib/postgresql/$version/main/postmaster.pid.orig /var/lib/postgresql/$version/main/postmaster.pid") == 0 or die "cp: $!";
is ((exec_as 'postgres', "pg_ctlcluster $version main stop"), 0,
'pg_ctlcluster succeeds with restored PID file');
like (`pg_lsclusters -h`, qr/down/, 'cluster is down');
like_program_out 'postgres', 'pg_lsclusters -h', 0, qr/down/, 'cluster is down';
# stop stopped server
is ((exec_as 'postgres', "pg_ctlcluster $version main stop", $outref), 1,
'pg_ctlcluster stop fails on stopped cluster');
is $$outref, "Error: cluster is not running\n",
'correct pg_ctlcluster error message';
is_program_out 'postgres', "pg_ctlcluster $version main stop", 1,
"Error: cluster is not running\n", 'pg_ctlcluster stop fails on stopped cluster';
# simulate crashed server
rename "/var/lib/postgresql/$version/main/postmaster.pid.orig",
"/var/lib/postgresql/$version/main/postmaster.pid" or die "rename: $!";
is ((exec_as 'postgres', "pg_ctlcluster $version main start", $outref), 0,
'pg_ctlcluster succeeds with already existing PID file');
is $$outref, "Removed stale pid file.\n", 'correct pg_ctlcluster warning message';
like (`pg_lsclusters -h`, qr/online/, 'cluster is online');
is_program_out 'postgres', "pg_ctlcluster $version main start", 0,
"Removed stale pid file.\n", 'pg_ctlcluster succeeds with already existing PID file';
like_program_out 'postgres', 'pg_lsclusters -h', 0, qr/online/, 'cluster is online';
is ((exec_as 'postgres', "pg_ctlcluster $version main stop"), 0,
'pg_ctlcluster stop succeeds');
# corrupt PID file while server is down
create_foo_pid;
is ((exec_as 'postgres', "pg_ctlcluster $version main start", $outref), 0,
'pg_ctlcluster succeeds with corrupted PID file');
is $$outref, "Removed stale pid file.\n", 'correct pg_ctlcluster warning message';
like (`pg_lsclusters -h`, qr/online/, 'cluster is online');
is_program_out 'postgres', "pg_ctlcluster $version main start", 0,
"Removed stale pid file.\n", 'pg_ctlcluster succeeds with corrupted PID file';
like_program_out 'postgres', 'pg_lsclusters -h', 0, qr/online/, 'cluster is online';
# start running server
is ((exec_as 'postgres', "pg_ctlcluster $version main start", $outref), 1,
'pg_ctlcluster start fails on running cluster');
is $$outref, "Cluster is already running.\n", 'correct pg_ctlcluster error message';
is_program_out 'postgres', "pg_ctlcluster $version main start", 1,
"Cluster is already running.\n", 'pg_ctlcluster start fails on running cluster';
# stop server, test various invalid configurations
is ((exec_as 'postgres', "pg_ctlcluster $version main stop", $outref), 0,
'pg_ctlcluster stop');
# stop server, test invalid configuration
is ((exec_as 'postgres', "pg_ctlcluster $version main stop"), 0, 'pg_ctlcluster stop');
PgCommon::set_conf_value $version, 'main', 'postgresql.conf',
'log_statement_stats', 'true';
PgCommon::set_conf_value $version, 'main', 'postgresql.conf',
'log_planner_stats', 'true';
is ((exec_as 'postgres', "pg_ctlcluster $version main start", $outref), 1,
'pg_ctlcluster start fails with invalid configuration');
is $$outref, "Error: invalid postgresql.conf: log_statement_stats and the other log_*_stats options are mutually exclusive\n",
'correct pg_ctlcluster error message';
like_program_out 'postgres', "pg_ctlcluster $version main start", 1,
qr/Error: invalid postgresql.conf.*log_.*mutually exclusive/,
'pg_ctlcluster start fails with invalid configuration';
# remove cluster and directory
ok ((system "pg_dropcluster $version main") == 0,
......
......@@ -25,11 +25,8 @@ is ((exec_as 'nobody', 'psql test -c "insert into phone values (\'Alice\', 2)"')
is ((exec_as 'nobody', 'psql test -c "insert into phone values (\'Bob\', 1)"'), 0, 'insert Bob into phone table');
# Check clusters
my $outref;
is ((exec_as 'nobody', 'pg_lsclusters -h', $outref), 0, 'pg_lsclusters succeeds');
$$outref =~ s/\s*$//;
is $$outref, "$MAJORS[0] upgr 5432 online postgres /var/lib/postgresql/$MAJORS[0]/upgr /var/log/postgresql/postgresql-$MAJORS[0]-upgr.log",
'correct pg_lsclusters output';
like_program_out 'nobody', 'pg_lsclusters -h', 0,
qr/^$MAJORS[0]\s+upgr\s+5432 online postgres/;
# Check SELECT in original cluster
my $select_old;
......@@ -39,31 +36,27 @@ Bob|1
', 'check SELECT output');
# Upgrade to latest version
is ((exec_as 0, "pg_upgradecluster $MAJORS[0] upgr", $outref), 0, 'pg_upgradecluster succeeds');
my $outref;
is ((exec_as 0, "pg_upgradecluster $MAJORS[0] upgr", $outref, 0), 0, 'pg_upgradecluster succeeds');
like $$outref, qr/Starting target cluster/, 'pg_upgradecluster reported cluster startup';
like $$outref, qr/Doing maintenance/, 'pg_upgradecluster reported successful maintenance';
like $$outref, qr/Success. Please check/, 'pg_upgradecluster reported successful operation';
# Check clusters
is ((exec_as 'nobody', 'pg_lsclusters -h', $outref), 0, 'pg_lsclusters succeeds');
$$outref =~ s/\s*$//;
is $$outref, "$MAJORS[0] upgr 5433 down postgres /var/lib/postgresql/$MAJORS[0]/upgr /var/log/postgresql/postgresql-$MAJORS[0]-upgr.log
$LATEST_MAJOR upgr 5432 online postgres /var/lib/postgresql/$LATEST_MAJOR/upgr /var/log/postgresql/postgresql-$LATEST_MAJOR-upgr.log",
'correct pg_lsclusters output';
is_program_out 'nobody', 'pg_lsclusters -h', 0,
"$MAJORS[0] upgr 5433 down postgres /var/lib/postgresql/$MAJORS[0]/upgr /var/log/postgresql/postgresql-$MAJORS[0]-upgr.log
$LATEST_MAJOR upgr 5432 online postgres /var/lib/postgresql/$LATEST_MAJOR/upgr /var/log/postgresql/postgresql-$LATEST_MAJOR-upgr.log
", 'pg_lsclusters output';
# Check that SELECT output is identical
my $select_new;
is ((exec_as 'nobody', 'psql -tAc "select * from phone order by name" test', $select_new), 0, 'SELECT in upgraded cluster succeeds');
is ($$select_old, $$select_new, 'SELECT output is the same in original and upgraded cluster');
is_program_out 'nobody', 'psql -tAc "select * from phone order by name" test', 0,
$$select_old, 'SELECT output is the same in original and upgraded cluster';
# stop servers, clean up
ok ((system "pg_dropcluster $MAJORS[0] upgr --stop-server") == 0,
'Dropping original cluster');
ok ((system "pg_dropcluster $LATEST_MAJOR upgr --stop-server") == 0,
'Dropping upgraded cluster');
is ((system "pg_dropcluster $MAJORS[0] upgr --stop-server"), 0, 'Dropping original cluster');
is ((system "pg_dropcluster $LATEST_MAJOR upgr --stop-server"), 0, 'Dropping upgraded cluster');
# Check clusters
is ((exec_as 'postgres', 'pg_lsclusters -h', $outref), 0, 'pg_lsclusters succeeds');
is $$outref, '', 'empty pg_lsclusters output';
is_program_out 'postgres', 'pg_lsclusters -h', 0, '', 'empty pg_lsclusters output';
# vim: filetype=perl
......@@ -19,10 +19,10 @@ sub check_cluster {
my $cluster_name = $locale;
if (defined $enc) {
$cluster_name .= "_$enc";
ok ((system "LC_ALL='$locale' pg_createcluster --encoding $enc --start $v $cluster_name >/dev/null 2>&1") == 0,
is ((system "LC_ALL='$locale' pg_createcluster --encoding $enc --start $v $cluster_name >/dev/null 2>&1"), 0,
"pg_createcluster for $locale with --encoding succeeded");
} else {
ok ((system "LC_ALL='$locale' pg_createcluster --start $v $cluster_name >/dev/null 2>&1") == 0,
is ((system "LC_ALL='$locale' pg_createcluster --start $v $cluster_name >/dev/null 2>&1"), 0,
"pg_createcluster for $locale without --encoding succeeded");
}
......@@ -35,7 +35,7 @@ sub check_cluster {
# check encoding
sleep 1;
is ((exec_as 'postgres', "psql -Atl --cluster $v/$cluster_name", $outref), 0,
is ((exec_as 'postgres', "psql -Atl --cluster $v/$cluster_name", $outref, 0), 0,
'psql -l succeeds');
my $is_unicode = 0;
$is_unicode = 1 if defined $enc && $enc =~ /(UNICODE|UTF-8)/;
......@@ -48,8 +48,7 @@ sub check_cluster {
# drop cluster again if requested
if (defined $del) {
ok ((system "pg_dropcluster $v $cluster_name --stop-server") == 0,
'Dropping cluster');
is ((system "pg_dropcluster $v $cluster_name --stop-server"), 0, 'Dropping cluster');
}
}
......@@ -62,8 +61,6 @@ check_cluster $LATEST_MAJOR, 'en_US', 1, 'UTF-8';
check_cluster $LATEST_MAJOR, 'en_US.UTF-8', 1;
# Check clusters
my $outref;
is ((exec_as 'postgres', 'pg_lsclusters -h', $outref), 0, 'pg_lsclusters succeeds');
is $$outref, '', 'empty pg_lsclusters output';
is_program_out 'postgres', 'pg_lsclusters -h', 0, '', 'empty pg_lsclusters output';
# vim: filetype=perl
......@@ -8,11 +8,10 @@ use strict;
use lib 't';
use TestLib;
use Test::More tests => 7 + $#MAJORS * 4;
use Test::More tests => 7 + $#MAJORS * 5;
# create cluster
ok ((system "pg_createcluster $MAJORS[0] main >/dev/null") == 0,
"pg_createcluster $MAJORS[0] main");
is ((system "pg_createcluster $MAJORS[0] main >/dev/null"), 0, "pg_createcluster $MAJORS[0] main");
open F, ">/etc/postgresql/$MAJORS[0]/main/postgresql.conf" or
die "could not open /etc/postgresql/$MAJORS[0]/main/postgresql.conf";
......@@ -116,38 +115,30 @@ transform_null_equals = false
is ((exec_as 'postgres', "pg_ctlcluster $MAJORS[0] main start 2>/dev/null"), 0,
'pg_ctlcluster start');
my $outref;
# Check clusters
is ((exec_as 'postgres', 'pg_lsclusters -h', $outref), 0, 'pg_lsclusters succeeds');
like $$outref, qr/$MAJORS[0].*online/, 'pg_lsclusters shows running cluster';
like_program_out 'postgres', 'pg_lsclusters -h', 0, qr/$MAJORS[0].*online/;
my $oldv = $MAJORS[0];
my @testv = @MAJORS;
shift @testv;
for my $v (@testv) {
# Upgrade cluster
is ((exec_as 0, "pg_upgradecluster -v $v $oldv main", $outref), 0,
"pg_upgradecluster from $oldv to $v succeeds");
print $$outref if $$outref !~ /^Success/im;
like_program_out 0, "pg_upgradecluster -v $v $oldv main", 0, qr/^Success/im;
# remove old cluster and directory
ok ((system "pg_dropcluster $oldv main") == 0,
'pg_dropcluster old cluster');
is ((system "pg_dropcluster $oldv main"), 0, 'pg_dropcluster old cluster');
# Check clusters
is ((exec_as 'postgres', 'pg_lsclusters -h', $outref), 0, 'pg_lsclusters succeeds');
like $$outref, qr/$v.*online/, 'pg_lsclusters shows running upgraded cluster';
like_program_out 'postgres', 'pg_lsclusters -h', 0, qr/$v.*online/,
'pg_lsclusters shows running upgraded cluster';
$oldv = $v;
}
# remove latest cluster and directory
ok ((system "pg_dropcluster $MAJORS[-1] main --stop-server") == 0,
'pg_dropcluster');
is ((system "pg_dropcluster $MAJORS[-1] main --stop-server"), 0, 'pg_dropcluster');
# Check clusters
is ((exec_as 'postgres', 'pg_lsclusters -h', $outref), 0, 'pg_lsclusters succeeds');
is $$outref, '', 'empty pg_lsclusters output';
is_program_out 'postgres', 'pg_lsclusters -h', 0, '', 'empty pg_lsclusters output';
# vim: filetype=perl
......@@ -13,7 +13,7 @@ my $owner = 'nobody';
# create cluster
for my $v (@MAJORS[0, -1]) {
ok ((system "pg_createcluster -u $owner $v main --start >/dev/null") == 0,
is ((system "pg_createcluster -u $owner $v main --start >/dev/null"), 0,
"pg_createcluster $v main for owner $owner");
# Check cluster
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment