summaryrefslogtreecommitdiffstats
path: root/src/bin/pg_controldata/t
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:46:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:46:48 +0000
commit311bcfc6b3acdd6fd152798c7f287ddf74fa2a98 (patch)
tree0ec307299b1dada3701e42f4ca6eda57d708261e /src/bin/pg_controldata/t
parentInitial commit. (diff)
downloadpostgresql-15-311bcfc6b3acdd6fd152798c7f287ddf74fa2a98.tar.xz
postgresql-15-311bcfc6b3acdd6fd152798c7f287ddf74fa2a98.zip
Adding upstream version 15.4.upstream/15.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/bin/pg_controldata/t')
-rw-r--r--src/bin/pg_controldata/t/001_pg_controldata.pl46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/bin/pg_controldata/t/001_pg_controldata.pl b/src/bin/pg_controldata/t/001_pg_controldata.pl
new file mode 100644
index 0000000..adb9af4
--- /dev/null
+++ b/src/bin/pg_controldata/t/001_pg_controldata.pl
@@ -0,0 +1,46 @@
+
+# Copyright (c) 2021-2022, PostgreSQL Global Development Group
+
+use strict;
+use warnings;
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+program_help_ok('pg_controldata');
+program_version_ok('pg_controldata');
+program_options_handling_ok('pg_controldata');
+command_fails(['pg_controldata'], 'pg_controldata without arguments fails');
+command_fails([ 'pg_controldata', 'nonexistent' ],
+ 'pg_controldata with nonexistent directory fails');
+
+my $node = PostgreSQL::Test::Cluster->new('main');
+$node->init;
+
+command_like([ 'pg_controldata', $node->data_dir ],
+ qr/checkpoint/, 'pg_controldata produces output');
+
+
+# check with a corrupted pg_control
+
+my $pg_control = $node->data_dir . '/global/pg_control';
+my $size = (stat($pg_control))[7];
+
+open my $fh, '>', $pg_control or BAIL_OUT($!);
+binmode $fh;
+
+# fill file with zeros
+print $fh pack("x[$size]");
+close $fh;
+
+command_checks_all(
+ [ 'pg_controldata', $node->data_dir ],
+ 0,
+ [
+ qr/WARNING: Calculated CRC checksum does not match value stored in file/,
+ qr/WARNING: invalid WAL segment size/
+ ],
+ [qr/^$/],
+ 'pg_controldata with corrupted pg_control');
+
+done_testing();