Skip to content

Commit 72e3b59

Browse files
committed
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.
1 parent 1b13757 commit 72e3b59

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

contrib/pg_tde/t/pg_tde_change_key_provider.pl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66

77
use JSON;
88

9+
command_like([ 'pg_tde_change_key_provider', '--help' ],
10+
qr/Usage:/, 'displays help');
11+
12+
command_like(
13+
[ 'pg_tde_change_key_provider', '--version' ],
14+
qr/pg_tde_change_key_provider \(PostgreSQL\) /,
15+
'displays version');
16+
917
my $node = PostgreSQL::Test::Cluster->new('main');
1018
$node->init;
1119
$node->append_conf('postgresql.conf', q{shared_preload_libraries = 'pg_tde'});

contrib/pg_tde/t/wal_archiving.pl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,82 @@
66
use Test::More;
77
use lib 't';
88
use pgtde;
9+
use PostgreSQL::Test::Utils;
910

1011
unlink('/tmp/wal_archiving.per');
1112

13+
# Test CLI tools directly
14+
15+
command_like(
16+
[ 'pg_tde_archive_decrypt', '--help' ],
17+
qr/wraps an archive command to give the command unencrypted WAL/,
18+
'pg_tde_archive_decrypt displays help');
19+
20+
command_like(
21+
[ 'pg_tde_restore_encrypt', '--help' ],
22+
qr/wraps a restore command to encrypt its returned WAL/,
23+
'pg_tde_restore_encrypt displays help');
24+
25+
command_like(
26+
[ 'pg_tde_archive_decrypt', '--version' ],
27+
qr/pg_tde_archive_decrypt \(PostgreSQL\) /,
28+
'pg_tde_archive_decrypt displays version');
29+
30+
command_like(
31+
[ 'pg_tde_restore_encrypt', '--version' ],
32+
qr/pg_tde_restore_encrypt \(PostgreSQL\) /,
33+
'pg_tde_restore_encrypt displays version');
34+
35+
command_fails_like(
36+
[ 'pg_tde_archive_decrypt', 'a', 'b' ],
37+
qr/error: wrong number of arguments, 3 expected/,
38+
'pg_tde_archive_decrypt checks for number of arguments');
39+
40+
command_fails_like(
41+
[ 'pg_tde_restore_encrypt', 'a', 'b' ],
42+
qr/error: wrong number of arguments, 3 expected/,
43+
'pg_tde_restore_encrypt checks for number of arguments');
44+
45+
command_fails_like(
46+
[ 'pg_tde_archive_decrypt', 'file', 'pg_wal/file', 'false %q' ],
47+
qr/error: invalid value for parameter "ARCHIVE-COMMAND": "false %q"\n.*?detail: String contains unexpected placeholder "%q"/,
48+
'pg_tde_archive_decrypt gives error if command not found');
49+
50+
command_fails_like(
51+
[ 'pg_tde_restore_encrypt', 'file', 'pg_wal/file', 'false %q' ],
52+
qr/error: invalid value for parameter "RESTORE-COMMAND": "false %q"\n.*?detail: String contains unexpected placeholder "%q"/,
53+
'pg_tde_restore_encrypt gives error if command not found');
54+
55+
command_fails_like(
56+
[ 'pg_tde_archive_decrypt', 'file', 'pg_wal/file', 'unknown_command_42' ],
57+
qr/error: ARCHIVE-COMMAND "unknown_command_42" failed with exit code 127/,
58+
'pg_tde_archive_decrypt gives error if command not found');
59+
60+
command_fails_like(
61+
[ 'pg_tde_restore_encrypt', 'file', 'pg_wal/file', 'unknown_command_42' ],
62+
qr/error: RESTORE-COMMAND "unknown_command_42" failed with exit code 127/,
63+
'pg_tde_restore_encrypt gives error if command not found');
64+
65+
command_fails_like(
66+
[ 'pg_tde_archive_decrypt', 'file', 'pg_wal/file', 'false' ],
67+
qr/error: ARCHIVE-COMMAND "false" failed with exit code 1/,
68+
'pg_tde_archive_decrypt prints return code of failed command');
69+
70+
command_fails_like(
71+
[ 'pg_tde_restore_encrypt', 'file', 'pg_wal/file', 'false' ],
72+
qr/error: RESTORE-COMMAND "false" failed with exit code 1/,
73+
'pg_tde_restore_encrypt prints return code of failed command');
74+
75+
command_fails_like(
76+
[ 'pg_tde_archive_decrypt', 'file', 'pg_wal/file', 'kill $$; sleep' ],
77+
qr/error: ARCHIVE-COMMAND "kill \$\$; sleep" was terminated by signal 15: Terminated/,
78+
'pg_tde_archive_decrypt prints which signal killed the command');
79+
80+
command_fails_like(
81+
[ 'pg_tde_restore_encrypt', 'file', 'pg_wal/file', 'kill $$; sleep' ],
82+
qr/error: RESTORE-COMMAND "kill \$\$; sleep" was terminated by signal 15: Terminated/,
83+
'pg_tde_restore_encrypt prints which signal killed the command');
84+
1285
# Test archive_command
1386

1487
my $primary = PostgreSQL::Test::Cluster->new('primary');

0 commit comments

Comments
 (0)