Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit98470fd

Browse files
committed
pg_archivecleanup: Add test suite
Reviewed-by: David Steele <david@pgmasters.net>
1 parentaf7211e commit98470fd

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
cleandistcleanmaintainer-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::Moretests=> 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+
subcreate_files
20+
{
21+
foreachmy$fn (@walfiles,'unrelated_file')
22+
{
23+
openmy$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+
foreachmy$fn (@walfiles)
58+
{
59+
ok(-f"$tempdir/$fn","$fn not removed");
60+
}
61+
}
62+
63+
subrun_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)

[8]ページ先頭

©2009-2025 Movatter.jp