Hi, On 2017/05/05 9:38, Mark Dilger wrote: > Hackers, > > just FYI, I cannot find any regression test coverage of this part of the > grammar, not > even in the contrib/ directory or TAP tests. I was going to submit a patch > to help out, > and discovered it is not so easy to do, and perhaps that is why the coverage > is missing.
I think we could add the coverage by defining a dummy C FDW handler function in regress.c. I see that some other regression tests use C functions defined there, such as test_atomic_ops(). What do you think about the attached patch? I am assuming you only meant to add tests for the code in foreigncmds.c (CREATE/ALTER FOREIGN DATA WRAPPER). Thanks, Amit
>From 402d9212a07b75474145abd3358d4806f77476d7 Mon Sep 17 00:00:00 2001 From: amit <amitlangot...@gmail.com> Date: Mon, 8 May 2017 17:39:40 +0900 Subject: [PATCH] Add some FDW HANDLER DDL tests --- src/test/regress/expected/foreign_data.out | 14 ++++++++++++++ src/test/regress/input/create_function_1.source | 3 +++ src/test/regress/output/create_function_1.source | 2 ++ src/test/regress/regress.c | 7 +++++++ src/test/regress/sql/foreign_data.sql | 12 ++++++++++++ 5 files changed, 38 insertions(+) diff --git a/src/test/regress/expected/foreign_data.out b/src/test/regress/expected/foreign_data.out index 1c7a7593f9..035dd282ad 100644 --- a/src/test/regress/expected/foreign_data.out +++ b/src/test/regress/expected/foreign_data.out @@ -89,6 +89,14 @@ CREATE FOREIGN DATA WRAPPER foo VALIDATOR postgresql_fdw_validator; postgresql | regress_foreign_data_user | - | postgresql_fdw_validator | | | (3 rows) +-- HANDLER related checks +CREATE FUNCTION invalid_fdw_handler() RETURNS int LANGUAGE SQL AS 'SELECT 1;'; +CREATE FOREIGN DATA WRAPPER test_fdw HANDLER invalid_fdw_handler; -- ERROR +ERROR: function invalid_fdw_handler must return type fdw_handler +CREATE FOREIGN DATA WRAPPER test_fdw HANDLER test_fdw_handler HANDLER invalid_fdw_handler; -- ERROR +ERROR: conflicting or redundant options +CREATE FOREIGN DATA WRAPPER test_fdw HANDLER test_fdw_handler; +DROP FOREIGN DATA WRAPPER test_fdw; -- ALTER FOREIGN DATA WRAPPER ALTER FOREIGN DATA WRAPPER foo; -- ERROR ERROR: syntax error at or near ";" @@ -188,6 +196,12 @@ ALTER FOREIGN DATA WRAPPER foo RENAME TO foo1; (3 rows) ALTER FOREIGN DATA WRAPPER foo1 RENAME TO foo; +-- HANDLER related checks +ALTER FOREIGN DATA WRAPPER foo HANDLER invalid_fdw_handler; -- ERROR +ERROR: function invalid_fdw_handler must return type fdw_handler +ALTER FOREIGN DATA WRAPPER foo HANDLER test_fdw_handler HANDLER anything; -- ERROR +ERROR: conflicting or redundant options +DROP FUNCTION invalid_fdw_handler(); -- DROP FOREIGN DATA WRAPPER DROP FOREIGN DATA WRAPPER nonexistent; -- ERROR ERROR: foreign-data wrapper "nonexistent" does not exist diff --git a/src/test/regress/input/create_function_1.source b/src/test/regress/input/create_function_1.source index f2b1561cc2..669a5355b0 100644 --- a/src/test/regress/input/create_function_1.source +++ b/src/test/regress/input/create_function_1.source @@ -87,3 +87,6 @@ CREATE FUNCTION test1 (int) RETURNS int LANGUAGE C CREATE FUNCTION test1 (int) RETURNS int LANGUAGE internal AS 'nosuch'; + +CREATE FUNCTION test_fdw_handler () RETURNS fdw_handler LANGUAGE C + AS '@libdir@/regress@DLSUFFIX@', 'test_fdw_handler'; diff --git a/src/test/regress/output/create_function_1.source b/src/test/regress/output/create_function_1.source index 957595c51e..54e572d7a7 100644 --- a/src/test/regress/output/create_function_1.source +++ b/src/test/regress/output/create_function_1.source @@ -88,3 +88,5 @@ ERROR: could not find function "nosuchsymbol" in file "@libdir@/regress@DLSUFFI CREATE FUNCTION test1 (int) RETURNS int LANGUAGE internal AS 'nosuch'; ERROR: there is no built-in function named "nosuch" +CREATE FUNCTION test_fdw_handler () RETURNS fdw_handler LANGUAGE C + AS '@libdir@/regress@DLSUFFIX@', 'test_fdw_handler'; diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index 80d0929df3..311b613659 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -1098,3 +1098,10 @@ test_atomic_ops(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); } + +PG_FUNCTION_INFO_V1(test_fdw_handler); +Datum +test_fdw_handler(PG_FUNCTION_ARGS) +{ + PG_RETURN_NULL(); +} diff --git a/src/test/regress/sql/foreign_data.sql b/src/test/regress/sql/foreign_data.sql index aaf079cf52..cc43535c30 100644 --- a/src/test/regress/sql/foreign_data.sql +++ b/src/test/regress/sql/foreign_data.sql @@ -51,6 +51,13 @@ RESET ROLE; CREATE FOREIGN DATA WRAPPER foo VALIDATOR postgresql_fdw_validator; \dew+ +-- HANDLER related checks +CREATE FUNCTION invalid_fdw_handler() RETURNS int LANGUAGE SQL AS 'SELECT 1;'; +CREATE FOREIGN DATA WRAPPER test_fdw HANDLER invalid_fdw_handler; -- ERROR +CREATE FOREIGN DATA WRAPPER test_fdw HANDLER test_fdw_handler HANDLER invalid_fdw_handler; -- ERROR +CREATE FOREIGN DATA WRAPPER test_fdw HANDLER test_fdw_handler; +DROP FOREIGN DATA WRAPPER test_fdw; + -- ALTER FOREIGN DATA WRAPPER ALTER FOREIGN DATA WRAPPER foo; -- ERROR ALTER FOREIGN DATA WRAPPER foo VALIDATOR bar; -- ERROR @@ -88,6 +95,11 @@ ALTER FOREIGN DATA WRAPPER foo RENAME TO foo1; \dew+ ALTER FOREIGN DATA WRAPPER foo1 RENAME TO foo; +-- HANDLER related checks +ALTER FOREIGN DATA WRAPPER foo HANDLER invalid_fdw_handler; -- ERROR +ALTER FOREIGN DATA WRAPPER foo HANDLER test_fdw_handler HANDLER anything; -- ERROR +DROP FUNCTION invalid_fdw_handler(); + -- DROP FOREIGN DATA WRAPPER DROP FOREIGN DATA WRAPPER nonexistent; -- ERROR DROP FOREIGN DATA WRAPPER IF EXISTS nonexistent; -- 2.11.0
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers