summaryrefslogtreecommitdiffstats
path: root/src/bin/pg_resetwal/t
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_resetwal/t')
-rw-r--r--src/bin/pg_resetwal/t/001_basic.pl32
-rw-r--r--src/bin/pg_resetwal/t/002_corrupted.pl58
2 files changed, 90 insertions, 0 deletions
diff --git a/src/bin/pg_resetwal/t/001_basic.pl b/src/bin/pg_resetwal/t/001_basic.pl
new file mode 100644
index 0000000..b4b192c
--- /dev/null
+++ b/src/bin/pg_resetwal/t/001_basic.pl
@@ -0,0 +1,32 @@
+
+# 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_resetwal');
+program_version_ok('pg_resetwal');
+program_options_handling_ok('pg_resetwal');
+
+my $node = PostgreSQL::Test::Cluster->new('main');
+$node->init;
+
+command_like([ 'pg_resetwal', '-n', $node->data_dir ],
+ qr/checkpoint/, 'pg_resetwal -n produces output');
+
+
+# Permissions on PGDATA should be default
+SKIP:
+{
+ skip "unix-style permissions not supported on Windows", 1
+ if ($windows_os);
+
+ ok(check_mode_recursive($node->data_dir, 0700, 0600),
+ 'check PGDATA permissions');
+}
+
+done_testing();
diff --git a/src/bin/pg_resetwal/t/002_corrupted.pl b/src/bin/pg_resetwal/t/002_corrupted.pl
new file mode 100644
index 0000000..cb4f451
--- /dev/null
+++ b/src/bin/pg_resetwal/t/002_corrupted.pl
@@ -0,0 +1,58 @@
+
+# Copyright (c) 2021-2022, PostgreSQL Global Development Group
+
+# Tests for handling a corrupted pg_control
+
+use strict;
+use warnings;
+
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+my $node = PostgreSQL::Test::Cluster->new('main');
+$node->init;
+
+my $pg_control = $node->data_dir . '/global/pg_control';
+my $size = (stat($pg_control))[7];
+
+# Read out the head of the file to get PG_CONTROL_VERSION in
+# particular.
+my $data;
+open my $fh, '<', $pg_control or BAIL_OUT($!);
+binmode $fh;
+read $fh, $data, 16;
+close $fh;
+
+# Fill pg_control with zeros
+open $fh, '>', $pg_control or BAIL_OUT($!);
+binmode $fh;
+print $fh pack("x[$size]");
+close $fh;
+
+command_checks_all(
+ [ 'pg_resetwal', '-n', $node->data_dir ],
+ 0,
+ [qr/pg_control version number/],
+ [
+ qr/pg_resetwal: warning: pg_control exists but is broken or wrong version; ignoring it/
+ ],
+ 'processes corrupted pg_control all zeroes');
+
+# Put in the previously saved header data. This uses a different code
+# path internally, allowing us to process a zero WAL segment size.
+open $fh, '>', $pg_control or BAIL_OUT($!);
+binmode $fh;
+print $fh $data, pack("x[" . ($size - 16) . "]");
+close $fh;
+
+command_checks_all(
+ [ 'pg_resetwal', '-n', $node->data_dir ],
+ 0,
+ [qr/pg_control version number/],
+ [
+ qr/\Qpg_resetwal: warning: pg_control specifies invalid WAL segment size (0 bytes); proceed with caution\E/
+ ],
+ 'processes zero WAL segment size');
+
+done_testing();