Hi all, While investigating the issue that has been committed as ebd092b to fix FK dependencies in pg_dump for tables in extensions, I developed a small test case aimed for integration in src/test/modules to ensure that this does not break again in the future. Note that as the regression tests of this test module use TAP tests to run a set of pg_dump commands and check the sanity of FK dependency tracking with extensions, this has needed a one-line tweak of the target prove_check to be able to install the contents of the current directory to the temp install folder before running the tests.
I imagine that it would be nice to integrate this test case to improve test coverage of pg_dump, extending at the same time TAP support for extensions, so attached are patches for this purpose. Those patches are really simple, but then perhaps there are better or simpler ways than what is attached, so feel free to comment if you have any ideas. Regards, -- Michael
From 476f44b54c1ea4828b76b32b64d9a36f80817f40 Mon Sep 17 00:00:00 2001 From: Michael Paquier <michael@otacoo.com> Date: Tue, 17 Feb 2015 22:29:28 +0900 Subject: [PATCH 1/2] Make prove_check install contents of current directory as well This is useful for example for TAP tests in extensions. --- src/Makefile.global.in | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.global.in b/src/Makefile.global.in index 7c39d82..7c15423 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -323,6 +323,7 @@ endef define prove_check $(MKDIR_P) tmp_check/log $(MAKE) -C $(top_builddir) DESTDIR='$(CURDIR)'/tmp_check/install install >'$(CURDIR)'/tmp_check/log/install.log 2>&1 +$(MAKE) -C $(CURDIR) DESTDIR='$(CURDIR)'/tmp_check/install install >>'$(CURDIR)'/tmp_check/log/install.log 2>&1 cd $(srcdir) && TESTDIR='$(CURDIR)' PATH="$(CURDIR)/tmp_check/install$(bindir):$$PATH" $(call add_to_path,$(ld_library_path_var),$(CURDIR)/tmp_check/install$(libdir)) top_builddir='$(CURDIR)/$(top_builddir)' PGPORT='6$(DEF_PGPORT)' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl endef -- 2.3.1
From 9bca873a65ae9147f543aafe3a76ea779a0e9f68 Mon Sep 17 00:00:00 2001 From: Michael Paquier <michael@otacoo.com> Date: Tue, 17 Feb 2015 22:36:49 +0900 Subject: [PATCH 2/2] Add dump_test, test module to check pg_dump with extensions It works with TAP tests. --- src/test/modules/Makefile | 1 + src/test/modules/dump_test/.gitignore | 4 ++++ src/test/modules/dump_test/Makefile | 22 ++++++++++++++++++++++ src/test/modules/dump_test/README | 5 +++++ src/test/modules/dump_test/dump_test--1.0.sql | 20 ++++++++++++++++++++ src/test/modules/dump_test/dump_test.control | 5 +++++ src/test/modules/dump_test/t/001_dump_test.pl | 27 +++++++++++++++++++++++++++ 7 files changed, 84 insertions(+) create mode 100644 src/test/modules/dump_test/.gitignore create mode 100644 src/test/modules/dump_test/Makefile create mode 100644 src/test/modules/dump_test/README create mode 100644 src/test/modules/dump_test/dump_test--1.0.sql create mode 100644 src/test/modules/dump_test/dump_test.control create mode 100644 src/test/modules/dump_test/t/001_dump_test.pl diff --git a/src/test/modules/Makefile b/src/test/modules/Makefile index 93d93af..6ad3b4e 100644 --- a/src/test/modules/Makefile +++ b/src/test/modules/Makefile @@ -6,6 +6,7 @@ include $(top_builddir)/src/Makefile.global SUBDIRS = \ commit_ts \ + dump_test \ worker_spi \ dummy_seclabel \ test_shm_mq \ diff --git a/src/test/modules/dump_test/.gitignore b/src/test/modules/dump_test/.gitignore new file mode 100644 index 0000000..5dcb3ff --- /dev/null +++ b/src/test/modules/dump_test/.gitignore @@ -0,0 +1,4 @@ +# Generated subdirectories +/log/ +/results/ +/tmp_check/ diff --git a/src/test/modules/dump_test/Makefile b/src/test/modules/dump_test/Makefile new file mode 100644 index 0000000..08cd215 --- /dev/null +++ b/src/test/modules/dump_test/Makefile @@ -0,0 +1,22 @@ +# src/test/modules/dump_test/Makefile + +EXTENSION = dump_test +DATA = dump_test--1.0.sql +PGFILEDESC = "dump_test - test pg_dump with extensions" + +ifdef USE_PGXS +PG_CONFIG = pg_config +PGXS := $(shell $(PG_CONFIG) --pgxs) +include $(PGXS) +else +subdir = src/test/modules/dump_test +top_builddir = ../../../.. +include $(top_builddir)/src/Makefile.global +include $(top_srcdir)/contrib/contrib-global.mk +endif + +check: all + $(prove_check) + +installcheck: install + $(prove_installcheck) diff --git a/src/test/modules/dump_test/README b/src/test/modules/dump_test/README new file mode 100644 index 0000000..9ebfa19 --- /dev/null +++ b/src/test/modules/dump_test/README @@ -0,0 +1,5 @@ +dump_test +========= + +Simple module used to test consistency of pg_dump with objects in +extensions. diff --git a/src/test/modules/dump_test/dump_test--1.0.sql b/src/test/modules/dump_test/dump_test--1.0.sql new file mode 100644 index 0000000..d684855 --- /dev/null +++ b/src/test/modules/dump_test/dump_test--1.0.sql @@ -0,0 +1,20 @@ +/* src/test/modules/dump_test/dump_test--1.0.sql */ + +-- complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "CREATE EXTENSION dump_test" to load this file. \quit + +CREATE TABLE IF NOT EXISTS cc_tab_fkey ( + id int PRIMARY KEY +); + +CREATE TABLE IF NOT EXISTS bb_tab_fkey ( + id int PRIMARY KEY REFERENCES cc_tab_fkey(id) +); + +CREATE TABLE IF NOT EXISTS aa_tab_fkey ( + id int REFERENCES bb_tab_fkey(id) +); + +SELECT pg_catalog.pg_extension_config_dump('aa_tab_fkey', ''); +SELECT pg_catalog.pg_extension_config_dump('bb_tab_fkey', ''); +SELECT pg_catalog.pg_extension_config_dump('cc_tab_fkey', ''); diff --git a/src/test/modules/dump_test/dump_test.control b/src/test/modules/dump_test/dump_test.control new file mode 100644 index 0000000..b32c99c --- /dev/null +++ b/src/test/modules/dump_test/dump_test.control @@ -0,0 +1,5 @@ +# dump_test extension +comment = 'dump_test - test pg_dump with extensions' +default_version = '1.0' +module_pathname = '$libdir/dump_test' +relocatable = true diff --git a/src/test/modules/dump_test/t/001_dump_test.pl b/src/test/modules/dump_test/t/001_dump_test.pl new file mode 100644 index 0000000..18a1135 --- /dev/null +++ b/src/test/modules/dump_test/t/001_dump_test.pl @@ -0,0 +1,27 @@ +use strict; +use warnings; +use TestLib; +use Test::More tests => 3; + +my $tempdir = tempdir; + +start_test_server $tempdir; + +psql 'postgres', 'CREATE EXTENSION dump_test'; + +# Insert some data before running the dump, this is needed to check +# consistent data dump of tables with foreign key dependencies +psql 'postgres', 'INSERT INTO cc_tab_fkey VALUES (1)'; +psql 'postgres', 'INSERT INTO bb_tab_fkey VALUES (1)'; +psql 'postgres', 'INSERT INTO aa_tab_fkey VALUES (1)'; + +# Create a table depending on a FK defined in the extension +psql 'postgres', 'CREATE TABLE dd_tab_fkey (id int REFERENCES bb_tab_fkey(id))'; +psql 'postgres', 'INSERT INTO dd_tab_fkey VALUES (1)'; + +# Take a dump then re-deploy it to a new database +command_ok(['pg_dump', '-d', 'postgres', '-f', "$tempdir/dump.sql"], + 'taken dump with installed extension'); +command_ok(['createdb', 'foobar1'], 'created new database to redeploy dump'); +command_ok(['psql', '--set=ON_ERROR_STOP=on', '-d', 'foobar1', '-f', + "$tempdir/dump.sql"], 'dump restored'); -- 2.3.1
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers