summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2022-01-07 14:13:35 +0900
committerMichael Paquier <michael@paquier.xyz>2022-01-07 14:13:35 +0900
commit50e144193c779f3da3b4836fa00cf1ce64953543 (patch)
tree829e3d0979fe899a86ecdb434575f9713e9d011a /src
parent000f3adfdc4336df83777eba86ce48f36cb6c6e9 (diff)
downloadpostgresql-50e144193c779f3da3b4836fa00cf1ce64953543.tar.gz
Add TAP tests for pg_basebackup with compression
pg_basebackup is able to use gzip to compress the contents of backups with the tar format, but there were no tests for that. This adds a minimalistic set of tests to check the contents of such base backups, including sanity checks on the contents generated with gzip commands. The tests are skipped if Postgres is compiled --without-zlib, and the checks based on the gzip command are skipped if nothing can be found, following the same model as the existing tests for pg_receivewal. Reviewed-by: Georgios Kokolatos Discussion: https://postgr.es/m/Yb3GEgWwcu4wZDuA@paquier.xyz
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_basebackup/t/010_pg_basebackup.pl37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl
index e56825382c..8aff5dc362 100644
--- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl
+++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl
@@ -10,7 +10,7 @@ use File::Path qw(rmtree);
use Fcntl qw(:seek);
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
-use Test::More tests => 110;
+use Test::More tests => 113;
program_help_ok('pg_basebackup');
program_version_ok('pg_basebackup');
@@ -624,3 +624,38 @@ rmtree("$tempdir/backup_corrupt4");
$node->safe_psql('postgres', "DROP TABLE corrupt1;");
$node->safe_psql('postgres', "DROP TABLE corrupt2;");
+
+note "Testing pg_basebackup with compression methods";
+
+# Check ZLIB compression if available.
+SKIP:
+{
+ skip "postgres was not built with ZLIB support", 3
+ if (!check_pg_config("#define HAVE_LIBZ 1"));
+
+ $node->command_ok(
+ [
+ 'pg_basebackup', '-D',
+ "$tempdir/backup_gzip", '--compress',
+ '1', '--no-sync',
+ '--format', 't'
+ ],
+ 'pg_basebackup with --compress');
+
+ # Verify that the stored files are generated with their expected
+ # names.
+ my @zlib_files = glob "$tempdir/backup_gzip/*.tar.gz";
+ is(scalar(@zlib_files), 2,
+ "two files created with gzip (base.tar.gz and pg_wal.tar.gz)");
+
+ # Check the integrity of the files generated.
+ my $gzip = $ENV{GZIP_PROGRAM};
+ skip "program gzip is not found in your system", 1
+ if ( !defined $gzip
+ || $gzip eq ''
+ || system_log($gzip, '--version') != 0);
+
+ my $gzip_is_valid = system_log($gzip, '--test', @zlib_files);
+ is($gzip_is_valid, 0, "gzip verified the integrity of compressed data");
+ rmtree("$tempdir/backup_gzip");
+}