2 # Copyright (c) 2021, PostgreSQL Global Development Group
7 use Test
::More tests
=> 42;
9 program_help_ok
('pg_archivecleanup');
10 program_version_ok
('pg_archivecleanup');
11 program_options_handling_ok
('pg_archivecleanup');
13 my $tempdir = TestLib
::tempdir
;
16 '00000001000000370000000C.gz', '00000001000000370000000D',
17 '00000001000000370000000E', '00000001000000370000000F.partial',);
21 foreach my $fn (@walfiles, 'unrelated_file')
23 open my $file, '>', "$tempdir/$fn";
24 print $file 'CONTENT';
33 ['pg_archivecleanup'],
34 qr/must specify archive location/,
35 'fails if archive location is not specified');
38 [ 'pg_archivecleanup', $tempdir ],
39 qr/must specify oldest kept WAL file/,
40 'fails if oldest kept WAL file name is not specified');
43 [ 'pg_archivecleanup', 'notexist', 'foo' ],
44 qr/archive location .* does not exist/,
45 'fails if archive location does not exist');
48 [ 'pg_archivecleanup', $tempdir, 'foo', 'bar' ],
49 qr/too many command-line arguments/,
50 'fails with too many command-line arguments');
53 [ 'pg_archivecleanup', $tempdir, 'foo' ],
54 qr/invalid file name argument/,
55 'fails with invalid restart file name');
58 # like command_like but checking stderr
60 my $result = IPC
::Run
::run
[ 'pg_archivecleanup', '-d', '-n', $tempdir,
61 $walfiles[2] ], '2>', \
$stderr;
62 ok
($result, "pg_archivecleanup dry run: exit code 0");
65 qr/$walfiles[1].*would be removed/,
66 "pg_archivecleanup dry run: matches");
67 foreach my $fn (@walfiles)
69 ok
(-f
"$tempdir/$fn", "$fn not removed");
75 my ($suffix, $test_name) = @_;
81 'pg_archivecleanup', '-x', '.gz', $tempdir,
82 $walfiles[2] . $suffix
86 ok
(!-f
"$tempdir/$walfiles[0]",
87 "$test_name: first older WAL file was cleaned up");
88 ok
(!-f
"$tempdir/$walfiles[1]",
89 "$test_name: second older WAL file was cleaned up");
90 ok
(-f
"$tempdir/$walfiles[2]",
91 "$test_name: restartfile was not cleaned up");
92 ok
(-f
"$tempdir/$walfiles[3]",
93 "$test_name: newer WAL file was not cleaned up");
94 ok
(-f
"$tempdir/unrelated_file",
95 "$test_name: unrelated file was not cleaned up");
99 run_check
('', 'pg_archivecleanup');
100 run_check
('.partial', 'pg_archivecleanup with .partial file');
101 run_check
('.00000020.backup', 'pg_archivecleanup with .backup file');