|
6 | 6 | use Test::More; |
7 | 7 | use lib 't'; |
8 | 8 | use pgtde; |
| 9 | +use PostgreSQL::Test::Utils; |
9 | 10 |
|
10 | 11 | unlink('/tmp/wal_archiving.per'); |
11 | 12 |
|
| 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 | + |
12 | 85 | # Test archive_command |
13 | 86 |
|
14 | 87 | my $primary = PostgreSQL::Test::Cluster->new('primary'); |
|
0 commit comments