Skip to content

Commit 98470fd

Browse files
committed
pg_archivecleanup: Add test suite
Reviewed-by: David Steele <david@pgmasters.net>
1 parent af7211e commit 98470fd

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

src/bin/pg_archivecleanup/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/pg_archivecleanup
2+
3+
/tmp_check/

src/bin/pg_archivecleanup/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ uninstall:
2525

2626
clean distclean maintainer-clean:
2727
rm -f pg_archivecleanup$(X) $(OBJS)
28+
rm -rf tmp_check
29+
30+
check:
31+
$(prove_check)
32+
33+
installcheck:
34+
$(prove_installcheck)
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
use strict;
2+
use warnings;
3+
use TestLib;
4+
use Test::More tests => 42;
5+
6+
program_help_ok('pg_archivecleanup');
7+
program_version_ok('pg_archivecleanup');
8+
program_options_handling_ok('pg_archivecleanup');
9+
10+
my $tempdir = TestLib::tempdir;
11+
12+
my @walfiles = (
13+
'00000001000000370000000C.gz',
14+
'00000001000000370000000D',
15+
'00000001000000370000000E',
16+
'00000001000000370000000F.partial',
17+
);
18+
19+
sub create_files
20+
{
21+
foreach my $fn (@walfiles, 'unrelated_file')
22+
{
23+
open my $file, '>', "$tempdir/$fn";
24+
print $file 'CONTENT';
25+
close $file;
26+
}
27+
}
28+
29+
create_files();
30+
31+
command_fails_like(['pg_archivecleanup'],
32+
qr/must specify archive location/,
33+
'fails if archive location is not specified');
34+
35+
command_fails_like(['pg_archivecleanup', $tempdir],
36+
qr/must specify oldest kept WAL file/,
37+
'fails if oldest kept WAL file name is not specified');
38+
39+
command_fails_like(['pg_archivecleanup', 'notexist', 'foo'],
40+
qr/archive location .* does not exist/,
41+
'fails if archive location does not exist');
42+
43+
command_fails_like(['pg_archivecleanup', $tempdir, 'foo', 'bar'],
44+
qr/too many command-line arguments/,
45+
'fails with too many command-line arguments');
46+
47+
command_fails_like(['pg_archivecleanup', $tempdir, 'foo'],
48+
qr/invalid file name argument/,
49+
'fails with invalid restart file name');
50+
51+
{
52+
# like command_like but checking stderr
53+
my $stderr;
54+
my $result = IPC::Run::run ['pg_archivecleanup', '-d', '-n', $tempdir, $walfiles[2]], '2>', \$stderr;
55+
ok($result, "pg_archivecleanup dry run: exit code 0");
56+
like($stderr, qr/$walfiles[1].*would be removed/, "pg_archivecleanup dry run: matches");
57+
foreach my $fn (@walfiles)
58+
{
59+
ok(-f "$tempdir/$fn", "$fn not removed");
60+
}
61+
}
62+
63+
sub run_check
64+
{
65+
my ($suffix, $test_name) = @_;
66+
67+
create_files();
68+
69+
command_ok(['pg_archivecleanup', '-x', '.gz', $tempdir, $walfiles[2] . $suffix],
70+
"$test_name: runs");
71+
72+
ok(! -f "$tempdir/$walfiles[0]", "$test_name: first older WAL file was cleaned up");
73+
ok(! -f "$tempdir/$walfiles[1]", "$test_name: second older WAL file was cleaned up");
74+
ok(-f "$tempdir/$walfiles[2]", "$test_name: restartfile was not cleaned up");
75+
ok(-f "$tempdir/$walfiles[3]", "$test_name: newer WAL file was not cleaned up");
76+
ok(-f "$tempdir/unrelated_file", "$test_name: unrelated file was not cleaned up");
77+
}
78+
79+
run_check('', 'pg_archivecleanup');
80+
run_check('.partial', 'pg_archivecleanup with .partial file');
81+
run_check('.00000020.backup', 'pg_archivecleanup with .backup file');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy