From ec26ad40b5bb023727045ed54c16b046c7da065a Mon Sep 17 00:00:00 2001
From: Nitin Motiani <nitinmotiani@google.com>
Date: Thu, 22 May 2025 10:20:15 +0000
Subject: [PATCH v5 5/5] [WIP] This is WIP patch for adding tests to pg_dump.pl

* The first test in the patch was the test we were originally
  trying to add but it kept failing.

* The 3 tests at the bottom were part of the debugging process and
  the logs showed that those tests would fail whenever a pipe
  was used inside the pipe command i.e. 'cat | gzip' or
  'cat > <file>'. But simple 'cat' or 'gzip' without pipe worked.

* The tests need to be cleaned up and rerun to get the exact error messages.
---
 src/bin/pg_dump/t/002_pg_dump.pl | 38 ++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 386e21e0c59..22222b2f2eb 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -476,6 +476,15 @@ my %pgdump_runs = (
 		],
 	},
 
+	# This test kept failing.
+	defaults_dir_format_pipe => {
+		test_key => 'defaults',
+		dump_cmd => [
+			'pg_dump', '-Fd', 'postgres',
+			"--pipe-command=\"cat > $tempdir/defaults_dir_format/%f\"",
+		],
+	},
+
 	# Do not use --no-sync to give test coverage for data sync.
 	defaults_parallel => {
 		test_key => 'defaults',
@@ -5103,6 +5112,35 @@ foreach my $db (sort keys %create_sql)
 	$node->safe_psql($db, $create_sql{$db});
 }
 
+# These four tests were added temporarily to more easily look through the output.
+# They failed as soon as we used a pipe of any kind whether to file or just to another
+# command. Those commands worked fine manually. So the second & fourth test where
+# we only have cat and gzip without any pipe, they work fine. But the rest don't.
+$node->command_fails_like(
+		[
+			'pg_dump', '-Fd', '-B', 'postgres',
+			"--pipe-command=\"cat > $tempdir/%f\"",],
+	qr/pg_dump: error: Failure in cat to file/,
+	'pg_dump: Failure in cat to file using pipe-command');
+
+
+$node->command_ok(
+		[
+			'pg_dump', '-Fd', '-B', 'postgres',
+			"--pipe-command=\"cat\"",], "Testing just with cat");
+
+$node->command_ok(
+		[
+			'pg_dump', '-Fd', '-B', 'postgres',
+			"--pipe-command=\"cat | gzip\"",], "Testing with cat piped to gzip");
+
+
+$node->command_ok(
+		[
+			'pg_dump', '-Fd', '-B', '-x', 'postgres',
+			"--pipe-command=\"gzip\"",], "Testing just with gzip");
+
+
 #########################################
 # Test connecting to a non-existent database
 
-- 
2.49.0.1266.g31b7d2e469-goog

