Clean up some pg_dump tests
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 18 Oct 2023 06:03:39 +0000 (08:03 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 18 Oct 2023 06:08:17 +0000 (08:08 +0200)
1) Remove useless entries from "unlike" lists.  Runs that are not
   listed in "like" don't need to be excluded in "unlike".

2) Ensure there is always a "like" list, even if it is empty.  This
   makes the test more self-documenting.

3) Use predefined lists such as %full_runs where appropriate, instead
   of listing all runs separately.

Also add code that checks 1 and 2 automatically and dies with an error
for violations.

Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/1f8cb371-e84e-434e-0367-6b716fb16fa1@eisentraut.org

src/bin/pg_dump/t/002_pg_dump.pl

index 326c9a763944a9f8b1968b8377869ba6482aeade..eb3ec534b4d8e9e8f77e93ae4f93c57a52aa56bf 100644 (file)
@@ -818,7 +818,7 @@ my %tests = (
                regexp => qr/^\QALTER COLLATION public.test0 OWNER TO \E.+;/m,
                collation => 1,
                like => { %full_runs, section_pre_data => 1, },
-               unlike => { %dump_test_schema_runs, no_owner => 1, },
+               unlike => { no_owner => 1, },
        },
 
        'ALTER FOREIGN DATA WRAPPER dummy OWNER TO' => {
@@ -977,7 +977,7 @@ my %tests = (
                create_sql =>
                  'ALTER SCHEMA public OWNER TO "regress_quoted  \"" role";',
                regexp => qr/^(GRANT|REVOKE)/m,
-               unlike => { defaults_public_owner => 1 },
+               like => {},
        },
 
        'ALTER SEQUENCE test_table_col1_seq' => {
@@ -1285,9 +1285,7 @@ my %tests = (
                  { %full_runs, %dump_test_schema_runs, section_pre_data => 1, },
                unlike => {
                        exclude_dump_test_schema => 1,
-                       only_dump_test_table => 1,
                        no_owner => 1,
-                       role => 1,
                        only_dump_measurement => 1,
                },
        },
@@ -1351,7 +1349,6 @@ my %tests = (
                        binary_upgrade => 1,
                        no_large_objects => 1,
                        schema_only => 1,
-                       section_pre_data => 1,
                },
        },
 
@@ -3210,7 +3207,6 @@ my %tests = (
                        binary_upgrade => 1,
                        exclude_dump_test_schema => 1,
                        schema_only => 1,
-                       only_dump_measurement => 1,
                },
        },
 
@@ -3457,7 +3453,6 @@ my %tests = (
        'Disabled trigger on partition is not created' => {
                regexp => qr/CREATE TRIGGER test_trigger.*ON dump_test_second_schema/,
                like => {},
-               unlike => { %full_runs, %dump_test_schema_runs },
        },
 
        # Triggers on partitions should not be dropped individually
@@ -3834,35 +3829,12 @@ my %tests = (
                \QCREATE INDEX measurement_city_id_logdate_idx ON ONLY dump_test.measurement USING\E
                /xm,
                like => {
-                       binary_upgrade => 1,
-                       clean => 1,
-                       clean_if_exists => 1,
-                       compression => 1,
-                       createdb => 1,
-                       defaults => 1,
-                       exclude_test_table => 1,
-                       exclude_test_table_data => 1,
-                       no_toast_compression => 1,
-                       no_large_objects => 1,
-                       no_privs => 1,
-                       no_owner => 1,
-                       no_table_access_method => 1,
-                       only_dump_test_schema => 1,
-                       pg_dumpall_dbprivs => 1,
-                       pg_dumpall_exclude => 1,
-                       schema_only => 1,
+                       %full_runs,
+                       %dump_test_schema_runs,
                        section_post_data => 1,
-                       test_schema_plus_large_objects => 1,
-                       only_dump_measurement => 1,
-                       exclude_measurement_data => 1,
                },
                unlike => {
                        exclude_dump_test_schema => 1,
-                       only_dump_test_table => 1,
-                       pg_dumpall_globals => 1,
-                       pg_dumpall_globals_clean => 1,
-                       role => 1,
-                       section_pre_data => 1,
                        exclude_measurement => 1,
                },
        },
@@ -3913,7 +3885,6 @@ my %tests = (
                        role => 1,
                        section_post_data => 1,
                        only_dump_measurement => 1,
-                       exclude_measurement_data => 1,
                },
                unlike => {
                        exclude_measurement => 1,
@@ -3927,35 +3898,12 @@ my %tests = (
                \QALTER INDEX dump_test.measurement_pkey ATTACH PARTITION dump_test_second_schema.measurement_y2006m2_pkey\E
                /xm,
                like => {
-                       binary_upgrade => 1,
-                       clean => 1,
-                       clean_if_exists => 1,
-                       compression => 1,
-                       createdb => 1,
-                       defaults => 1,
-                       exclude_dump_test_schema => 1,
-                       exclude_test_table => 1,
-                       exclude_test_table_data => 1,
-                       no_toast_compression => 1,
-                       no_large_objects => 1,
-                       no_privs => 1,
-                       no_owner => 1,
-                       no_table_access_method => 1,
-                       pg_dumpall_dbprivs => 1,
-                       pg_dumpall_exclude => 1,
+                       %full_runs,
                        role => 1,
-                       schema_only => 1,
                        section_post_data => 1,
                        only_dump_measurement => 1,
-                       exclude_measurement_data => 1,
                },
                unlike => {
-                       only_dump_test_schema => 1,
-                       only_dump_test_table => 1,
-                       pg_dumpall_globals => 1,
-                       pg_dumpall_globals_clean => 1,
-                       section_pre_data => 1,
-                       test_schema_plus_large_objects => 1,
                        exclude_measurement => 1,
                },
        },
@@ -4929,6 +4877,22 @@ foreach my $run (sort keys %pgdump_runs)
                        $test_db = $tests{$test}->{database};
                }
 
+               # Check for proper test definitions
+               #
+               # There should be a "like" list, even if it is empty.  (This
+               # makes the test more self-documenting.)
+               if (!defined($tests{$test}->{like}))
+               {
+                       die "missing \"like\" in test \"$test\"";
+               }
+               # Check for useless entries in "unlike" list.  Runs that are
+               # not listed in "like" don't need to be excluded in "unlike".
+               if ($tests{$test}->{unlike}->{$test_key} &&
+                       !defined($tests{$test}->{like}->{$test_key}))
+               {
+                       die "useless \"unlike\" entry \"$test_key\" in test \"$test\"";
+               }
+
                # Skip any collation-related commands if there is no collation support
                if (!$collation_support && defined($tests{$test}->{collation}))
                {