From 24189277f6ff3169b15c7bc82926a372ca7f2dbf Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Fri, 12 Mar 2021 20:11:47 -0500
Subject: [PATCH] pg_amcheck: Try to fix still more test failures.

Avoid use of non-portable option ordering in command_checks_all().
The use of bare command line arguments before switches doesn't work
everywhere.  Per buildfarm members drongo and hoverfly.

Avoid testing for the message "role \"%s\" does not exist", because
some buildfarm machines report a different error. fairywren complains
about "SSPI authentication failed for user \"%s\"", for example.

Mark Dilger

Discussion: http://postgr.es/m/9E76E46A-48B2-4869-BD0C-422204C1F767@enterprisedb.com
Discussion: http://postgr.es/m/F0A1FD70-A2F4-4528-8A03-8650CAEC0554%40enterprisedb.com
---
 src/bin/pg_amcheck/t/002_nonesuch.pl |  4 ++--
 src/bin/pg_amcheck/t/003_check.pl    | 26 +++++++++++++-------------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/bin/pg_amcheck/t/002_nonesuch.pl b/src/bin/pg_amcheck/t/002_nonesuch.pl
index a2c3537f14a..4df17885f97 100644
--- a/src/bin/pg_amcheck/t/002_nonesuch.pl
+++ b/src/bin/pg_amcheck/t/002_nonesuch.pl
@@ -3,7 +3,7 @@ use warnings;
 
 use PostgresNode;
 use TestLib;
-use Test::More tests => 76;
+use Test::More tests => 75;
 
 # Test set-up
 my ($node, $port);
@@ -68,7 +68,7 @@ $node->command_checks_all(
 	[ 'pg_amcheck', '-U', 'no_such_user', 'postgres' ],
 	1,
 	[ qr/^$/ ],
-	[ qr/role "no_such_user" does not exist/ ],
+	[ ],
 	'checking with a non-existent user');
 
 # Failing to connect to the initial database due to bad username is an still an
diff --git a/src/bin/pg_amcheck/t/003_check.pl b/src/bin/pg_amcheck/t/003_check.pl
index 620634875e6..0a7795bb64d 100644
--- a/src/bin/pg_amcheck/t/003_check.pl
+++ b/src/bin/pg_amcheck/t/003_check.pl
@@ -375,7 +375,7 @@ $node->command_checks_all(
 # are quiet.
 #
 $node->command_checks_all(
-	[ @cmd, 'db1', '-t', 's1.*', '--no-dependent-indexes' ],
+	[ @cmd, '-t', 's1.*', '--no-dependent-indexes', 'db1' ],
 	0,
 	[ $no_output_re ],
 	[ $no_output_re ],
@@ -384,7 +384,7 @@ $node->command_checks_all(
 # Checking db2.s1 should show table corruptions if indexes are excluded
 #
 $node->command_checks_all(
-	[ @cmd, 'db2', '-t', 's1.*', '--no-dependent-indexes' ],
+	[ @cmd, '-t', 's1.*', '--no-dependent-indexes', 'db2' ],
 	2,
 	[ $missing_file_re ],
 	[ $no_output_re ],
@@ -394,7 +394,7 @@ $node->command_checks_all(
 # corruption messages on stdout, and nothing on stderr.
 #
 $node->command_checks_all(
-	[ @cmd, 'db1', '-s', 's3' ],
+	[ @cmd, '-s', 's3', 'db1' ],
 	2,
 	[ $index_missing_relation_fork_re,
 	  $line_pointer_corruption_re,
@@ -407,14 +407,14 @@ $node->command_checks_all(
 # options the toast corruption is reported, but when excluding toast we get no
 # error reports.
 $node->command_checks_all(
-	[ @cmd, 'db1', '-s', 's4' ],
+	[ @cmd, '-s', 's4', 'db1' ],
 	2,
 	[ $missing_file_re ],
 	[ $no_output_re ],
 	'pg_amcheck in schema s4 reports toast corruption');
 
 $node->command_checks_all(
-	[ @cmd, '--no-dependent-toast', '--exclude-toast-pointers', 'db1', '-s', 's4' ],
+	[ @cmd, '--no-dependent-toast', '--exclude-toast-pointers', '-s', 's4', 'db1' ],
 	0,
 	[ $no_output_re ],
 	[ $no_output_re ],
@@ -422,7 +422,7 @@ $node->command_checks_all(
 
 # Check that no corruption is reported in schema db1.s5
 $node->command_checks_all(
-	[ @cmd, 'db1', '-s', 's5' ],
+	[ @cmd, '-s', 's5', 'db1' ],
 	0,
 	[ $no_output_re ],
 	[ $no_output_re ],
@@ -432,7 +432,7 @@ $node->command_checks_all(
 # the indexes, no corruption is reported about the schema.
 #
 $node->command_checks_all(
-	[ @cmd, 'db1', '-s', 's1', '-I', 't1_btree', '-I', 't2_btree' ],
+	[ @cmd, '-s', 's1', '-I', 't1_btree', '-I', 't2_btree', 'db1' ],
 	0,
 	[ $no_output_re ],
 	[ $no_output_re ],
@@ -443,7 +443,7 @@ $node->command_checks_all(
 # about the schema.
 #
 $node->command_checks_all(
-	[ @cmd, 'db1', '-t', 's1.*', '--no-dependent-indexes' ],
+	[ @cmd, '-t', 's1.*', '--no-dependent-indexes', 'db1' ],
 	0,
 	[ $no_output_re ],
 	[ $no_output_re ],
@@ -453,7 +453,7 @@ $node->command_checks_all(
 # tables that no corruption is reported.
 #
 $node->command_checks_all(
-	[ @cmd, 'db1', '-s', 's2', '-T', 't1', '-T', 't2' ],
+	[ @cmd, '-s', 's2', '-T', 't1', '-T', 't2', 'db1' ],
 	0,
 	[ $no_output_re ],
 	[ $no_output_re ],
@@ -463,7 +463,7 @@ $node->command_checks_all(
 # to avoid getting messages about corrupt tables or indexes.
 #
 command_fails_like(
-	[ @cmd, 'db1', '-s', 's5', '--startblock', 'junk' ],
+	[ @cmd, '-s', 's5', '--startblock', 'junk', 'db1' ],
 	qr/invalid start block/,
 	'pg_amcheck rejects garbage startblock');
 
@@ -473,7 +473,7 @@ command_fails_like(
 	'pg_amcheck rejects garbage endblock');
 
 command_fails_like(
-	[ @cmd, 'db1', '-s', 's5', '--startblock', '5', '--endblock', '4' ],
+	[ @cmd, '-s', 's5', '--startblock', '5', '--endblock', '4', 'db1' ],
 	qr/end block precedes start block/,
 	'pg_amcheck rejects invalid block range');
 
@@ -482,14 +482,14 @@ command_fails_like(
 # arguments are handled sensibly.
 #
 $node->command_checks_all(
-	[ @cmd, 'db1', '-s', 's1', '-i', 't1_btree', '--parent-check' ],
+	[ @cmd, '-s', 's1', '-i', 't1_btree', '--parent-check', 'db1' ],
 	2,
 	[ $index_missing_relation_fork_re ],
 	[ $no_output_re ],
 	'pg_amcheck smoke test --parent-check');
 
 $node->command_checks_all(
-	[ @cmd, 'db1', '-s', 's1', '-i', 't1_btree', '--heapallindexed', '--rootdescend' ],
+	[ @cmd, '-s', 's1', '-i', 't1_btree', '--heapallindexed', '--rootdescend', 'db1' ],
 	2,
 	[ $index_missing_relation_fork_re ],
 	[ $no_output_re ],