From 4f0c4e17ac17dd8fd36cbfc4f887fff8cfecb1f6 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon, 13 Oct 2025 16:30:55 -0400
Subject: [PATCH v4 3/4] Include compression of toc.dat in manually-compressed
 test cases.

We would have found the bug fixed in commit a239c4a0c much sooner
if we'd done this.  As far as I can tell, this doesn't reduce
test coverage at all, since there are other tests of directory
format that still use an uncompressed toc.dat.  And its effect
on the total runtime of 002_pg_dump.pl seems lost in the noise.

While here, fix a glitch that I noticed in testing: the
$glob_patterns tests were incapable of failing, because glob()
will return 'foo' as 'foo' whether there is a matching file or
not.  (Indeed, the stanza just above this one relies on that.)

I'm slightly tempted to back-patch this part.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/3515357.1760128017@sss.pgh.pa.us
Discussion: https://postgr.es/m/25345.1760289877@sss.pgh.pa.us
---
 src/bin/pg_dump/t/002_pg_dump.pl | 41 +++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 17 deletions(-)

diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 8a08f9a5f6f..8b287a673bf 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -140,15 +140,18 @@ my %pgdump_runs = (
 			'--statistics',
 			'postgres',
 		],
-		# Give coverage for manually compressed blobs.toc files during
-		# restore.
+		# Give coverage for manually-compressed TOC files during restore.
 		compress_cmd => {
 			program => $ENV{'GZIP_PROGRAM'},
-			args => [ '-f', "$tempdir/compression_gzip_dir/blobs_*.toc", ],
+			args => [
+				'-f',
+				"$tempdir/compression_gzip_dir/toc.dat",
+				"$tempdir/compression_gzip_dir/blobs_*.toc",
+			],
 		},
-		# Verify that only data files were compressed
+		# Verify that TOC and data files were compressed
 		glob_patterns => [
-			"$tempdir/compression_gzip_dir/toc.dat",
+			"$tempdir/compression_gzip_dir/toc.dat.gz",
 			"$tempdir/compression_gzip_dir/*.dat.gz",
 		],
 		restore_cmd => [
@@ -219,18 +222,18 @@ my %pgdump_runs = (
 			'--statistics',
 			'postgres',
 		],
-		# Give coverage for manually compressed blobs.toc files during
-		# restore.
+		# Give coverage for manually-compressed TOC files during restore.
 		compress_cmd => {
 			program => $ENV{'LZ4'},
 			args => [
 				'-z', '-f', '-m', '--rm',
+				"$tempdir/compression_lz4_dir/toc.dat",
 				"$tempdir/compression_lz4_dir/blobs_*.toc",
 			],
 		},
-		# Verify that data files were compressed
+		# Verify that TOC and data files were compressed
 		glob_patterns => [
-			"$tempdir/compression_lz4_dir/toc.dat",
+			"$tempdir/compression_lz4_dir/toc.dat.lz4",
 			"$tempdir/compression_lz4_dir/*.dat.lz4",
 		],
 		restore_cmd => [
@@ -303,18 +306,18 @@ my %pgdump_runs = (
 			'--statistics',
 			'postgres',
 		],
-		# Give coverage for manually compressed blobs.toc files during
-		# restore.
+		# Give coverage for manually-compressed TOC files during restore.
 		compress_cmd => {
 			program => $ENV{'ZSTD'},
 			args => [
-				'-z', '-f',
-				'--rm', "$tempdir/compression_zstd_dir/blobs_*.toc",
+				'-z', '-f', '--rm',
+				"$tempdir/compression_zstd_dir/toc.dat",
+				"$tempdir/compression_zstd_dir/blobs_*.toc",
 			],
 		},
-		# Verify that data files were compressed
+		# Verify that TOC and data files were compressed
 		glob_patterns => [
-			"$tempdir/compression_zstd_dir/toc.dat",
+			"$tempdir/compression_zstd_dir/toc.dat.zst",
 			"$tempdir/compression_zstd_dir/*.dat.zst",
 		],
 		restore_cmd => [
@@ -5523,8 +5526,12 @@ foreach my $run (sort keys %pgdump_runs)
 		foreach my $glob_pattern (@{$glob_patterns})
 		{
 			my @glob_output = glob($glob_pattern);
-			is(scalar(@glob_output) > 0,
-				1, "$run: glob check for $glob_pattern");
+			my $ok = 0;
+			# certainly found some files if glob() returned multiple matches
+			$ok = 1 if (scalar(@glob_output) > 1);
+			# if just one match, we need to check if it's real
+			$ok = 1 if (scalar(@glob_output) == 1 && -f $glob_output[0]);
+			is($ok, 1, "$run: glob check for $glob_pattern");
 		}
 	}
 
-- 
2.43.7

