From 3db22794b76eb0548f002f02a607ebcd101fc68e Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 17 May 2017 12:22:56 -0400 Subject: [PATCH] Add more tests for CREATE SUBSCRIPTION Add some tests for parsing different option combinations. Fix some of the resulting error messages for recent changes in option naming. Author: Masahiko Sawada --- src/backend/commands/subscriptioncmds.c | 10 +++++----- src/test/regress/expected/subscription.out | 20 ++++++++++++++++++++ src/test/regress/sql/subscription.sql | 15 +++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index 265f2efd62..1f7274bc57 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -181,17 +181,17 @@ parse_subscription_options(List *options, bool *connect, bool *enabled_given, if (enabled && *enabled_given && *enabled) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("noconnect and enabled are mutually exclusive options"))); + errmsg("connect = false and enabled = true are mutually exclusive options"))); if (create_slot && create_slot_given && *create_slot) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("noconnect and create slot are mutually exclusive options"))); + errmsg("connect = false and create_slot = true are mutually exclusive options"))); if (copy_data && copy_data_given && *copy_data) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("noconnect and copy data are mutually exclusive options"))); + errmsg("connect = false and copy_data = true are mutually exclusive options"))); /* Change the defaults of other options. */ *enabled = false; @@ -208,12 +208,12 @@ parse_subscription_options(List *options, bool *connect, bool *enabled_given, if (enabled && *enabled_given && *enabled) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("slot_name = NONE and enabled are mutually exclusive options"))); + errmsg("slot_name = NONE and enabled = true are mutually exclusive options"))); if (create_slot && create_slot_given && *create_slot) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("slot_name = NONE and create slot are mutually exclusive options"))); + errmsg("slot_name = NONE and create_slot = true are mutually exclusive options"))); } } diff --git a/src/test/regress/expected/subscription.out b/src/test/regress/expected/subscription.out index 10c3644e51..1c42013b47 100644 --- a/src/test/regress/expected/subscription.out +++ b/src/test/regress/expected/subscription.out @@ -45,6 +45,26 @@ SET SESSION AUTHORIZATION 'regress_subscription_user2'; CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION foo WITH (connect = false); ERROR: must be superuser to create subscriptions SET SESSION AUTHORIZATION 'regress_subscription_user'; +-- fail - invalid option combinations +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, copy_data = true); +ERROR: connect = false and copy_data = true are mutually exclusive options +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, enabled = true); +ERROR: connect = false and enabled = true are mutually exclusive options +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, create_slot = true); +ERROR: connect = false and create_slot = true are mutually exclusive options +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = true); +ERROR: slot_name = NONE and enabled = true are mutually exclusive options +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, create_slot = true); +ERROR: slot_name = NONE and create_slot = true are mutually exclusive options +-- ok - with slot_name = NONE +CREATE SUBSCRIPTION testsub3 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, connect = false); +WARNING: tables were not subscribed, you will have to run ALTER SUBSCRIPTION ... REFRESH PUBLICATION to subscribe the tables +-- fail +ALTER SUBSCRIPTION testsub3 ENABLE; +ERROR: cannot enable subscription that does not have a slot name +ALTER SUBSCRIPTION testsub3 REFRESH PUBLICATION; +ERROR: ALTER SUBSCRIPTION ... REFRESH is not allowed for disabled subscriptions +DROP SUBSCRIPTION testsub3; -- fail - invalid connection string ALTER SUBSCRIPTION testsub CONNECTION 'foobar'; ERROR: invalid connection string syntax: missing "=" after "foobar" in connection info string diff --git a/src/test/regress/sql/subscription.sql b/src/test/regress/sql/subscription.sql index 798bb0dbd3..36cdd96c77 100644 --- a/src/test/regress/sql/subscription.sql +++ b/src/test/regress/sql/subscription.sql @@ -38,6 +38,21 @@ SET SESSION AUTHORIZATION 'regress_subscription_user2'; CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION foo WITH (connect = false); SET SESSION AUTHORIZATION 'regress_subscription_user'; +-- fail - invalid option combinations +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, copy_data = true); +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, enabled = true); +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, create_slot = true); +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = true); +CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, create_slot = true); + +-- ok - with slot_name = NONE +CREATE SUBSCRIPTION testsub3 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, connect = false); +-- fail +ALTER SUBSCRIPTION testsub3 ENABLE; +ALTER SUBSCRIPTION testsub3 REFRESH PUBLICATION; + +DROP SUBSCRIPTION testsub3; + -- fail - invalid connection string ALTER SUBSCRIPTION testsub CONNECTION 'foobar'; -- 2.40.0