Add some simple tests for the archive and restore command

These error paths are annoying to test with the whole setup so we call
the CLI tools directly. Plus add a couple of tests for the --help
argument.
pull/238/head
Andreas Karlsson 3 weeks ago committed by Andreas Karlsson
parent 1b13757895
commit 72e3b597c8
  1. 8
      contrib/pg_tde/t/pg_tde_change_key_provider.pl
  2. 73
      contrib/pg_tde/t/wal_archiving.pl

@ -6,6 +6,14 @@ use Test::More;
use JSON;
command_like([ 'pg_tde_change_key_provider', '--help' ],
qr/Usage:/, 'displays help');
command_like(
[ 'pg_tde_change_key_provider', '--version' ],
qr/pg_tde_change_key_provider \(PostgreSQL\) /,
'displays version');
my $node = PostgreSQL::Test::Cluster->new('main');
$node->init;
$node->append_conf('postgresql.conf', q{shared_preload_libraries = 'pg_tde'});

@ -6,9 +6,82 @@ use File::Basename;
use Test::More;
use lib 't';
use pgtde;
use PostgreSQL::Test::Utils;
unlink('/tmp/wal_archiving.per');
# Test CLI tools directly
command_like(
[ 'pg_tde_archive_decrypt', '--help' ],
qr/wraps an archive command to give the command unencrypted WAL/,
'pg_tde_archive_decrypt displays help');
command_like(
[ 'pg_tde_restore_encrypt', '--help' ],
qr/wraps a restore command to encrypt its returned WAL/,
'pg_tde_restore_encrypt displays help');
command_like(
[ 'pg_tde_archive_decrypt', '--version' ],
qr/pg_tde_archive_decrypt \(PostgreSQL\) /,
'pg_tde_archive_decrypt displays version');
command_like(
[ 'pg_tde_restore_encrypt', '--version' ],
qr/pg_tde_restore_encrypt \(PostgreSQL\) /,
'pg_tde_restore_encrypt displays version');
command_fails_like(
[ 'pg_tde_archive_decrypt', 'a', 'b' ],
qr/error: wrong number of arguments, 3 expected/,
'pg_tde_archive_decrypt checks for number of arguments');
command_fails_like(
[ 'pg_tde_restore_encrypt', 'a', 'b' ],
qr/error: wrong number of arguments, 3 expected/,
'pg_tde_restore_encrypt checks for number of arguments');
command_fails_like(
[ 'pg_tde_archive_decrypt', 'file', 'pg_wal/file', 'false %q' ],
qr/error: invalid value for parameter "ARCHIVE-COMMAND": "false %q"\n.*?detail: String contains unexpected placeholder "%q"/,
'pg_tde_archive_decrypt gives error if command not found');
command_fails_like(
[ 'pg_tde_restore_encrypt', 'file', 'pg_wal/file', 'false %q' ],
qr/error: invalid value for parameter "RESTORE-COMMAND": "false %q"\n.*?detail: String contains unexpected placeholder "%q"/,
'pg_tde_restore_encrypt gives error if command not found');
command_fails_like(
[ 'pg_tde_archive_decrypt', 'file', 'pg_wal/file', 'unknown_command_42' ],
qr/error: ARCHIVE-COMMAND "unknown_command_42" failed with exit code 127/,
'pg_tde_archive_decrypt gives error if command not found');
command_fails_like(
[ 'pg_tde_restore_encrypt', 'file', 'pg_wal/file', 'unknown_command_42' ],
qr/error: RESTORE-COMMAND "unknown_command_42" failed with exit code 127/,
'pg_tde_restore_encrypt gives error if command not found');
command_fails_like(
[ 'pg_tde_archive_decrypt', 'file', 'pg_wal/file', 'false' ],
qr/error: ARCHIVE-COMMAND "false" failed with exit code 1/,
'pg_tde_archive_decrypt prints return code of failed command');
command_fails_like(
[ 'pg_tde_restore_encrypt', 'file', 'pg_wal/file', 'false' ],
qr/error: RESTORE-COMMAND "false" failed with exit code 1/,
'pg_tde_restore_encrypt prints return code of failed command');
command_fails_like(
[ 'pg_tde_archive_decrypt', 'file', 'pg_wal/file', 'kill $$; sleep' ],
qr/error: ARCHIVE-COMMAND "kill \$\$; sleep" was terminated by signal 15: Terminated/,
'pg_tde_archive_decrypt prints which signal killed the command');
command_fails_like(
[ 'pg_tde_restore_encrypt', 'file', 'pg_wal/file', 'kill $$; sleep' ],
qr/error: RESTORE-COMMAND "kill \$\$; sleep" was terminated by signal 15: Terminated/,
'pg_tde_restore_encrypt prints which signal killed the command');
# Test archive_command
my $primary = PostgreSQL::Test::Cluster->new('primary');

Loading…
Cancel
Save