8000 Add more tests for CREATE SUBSCRIPTION · micdev42/postgres@3db2279 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 3db2279

Browse files
committed
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 <sawada.mshk@gmail.com>
1 parent 9485516 commit 3db2279

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

src/backend/commands/subscriptioncmds.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,17 @@ parse_subscription_options(List *options, bool *connect, bool *enabled_given,
181181
if (enabled && *enabled_given && *enabled)
182182
ereport(ERROR,
183183
(errcode(ERRCODE_SYNTAX_ERROR),
184-
errmsg("noconnect and enabled are mutually exclusive options")));
184+
errmsg("connect = false and enabled = true are mutually exclusive options")));
185185

186186
if (create_slot && create_slot_given && *create_slot)
187187
ereport(ERROR,
188188
(errcode(ERRCODE_SYNTAX_ERROR),
189-
errmsg("noconnect and create slot are mutually exclusive options")));
189+
errmsg("connect = false and create_slot = true are mutually exclusive options")));
190190

191191
if (copy_data && copy_data_given && *copy_data)
192192
ereport(ERROR,
193193
(errcode(ERRCODE_SYNTAX_ERROR),
194-
errmsg("noconnect and copy data are mutually exclusive options")));
194+
errmsg("connect = false and copy_data = true are mutually exclusive options")));
195195

196196
/* Change the defaults of other options. */
197197
*enabled = false;
@@ -208,12 +208,12 @@ parse_subscription_options(List *options, bool *connect, bool *enabled_given,
208208
if (enabled && *enabled_given && *enabled)
209209
ereport(ERROR,
210210
(errcode(ERRCODE_SYNTAX_ERROR),
211-
errmsg("slot_name = NONE and enabled are mutually exclusive options")));
211+
errmsg("slot_name = NONE and enabled = true are mutually exclusive options")));
212212

213213
if (create_slot && create_slot_given && *create_slot)
214214
ereport(ERROR,
215215
(errcode(ERRCODE_SYNTAX_ERROR),
216-
errmsg("slot_name = NONE and create slot are mutually exclusive options")));
216+
errmsg("slot_name = NONE and create_slot = true are mutually exclusive options")));
217217
}
218218
}
219219

src/test/regress/expected/subscription.out

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ SET SESSION AUTHORIZATION 'regress_subscription_user2';
4545
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION foo WITH (connect = false);
4646
ERROR: must be superuser to create subscriptions
4747
SET SESSION AUTHORIZATION 'regress_subscription_user';
48+
-- fail - invalid option combinations
49+
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, copy_data = true);
50+
ERROR: connect = false and copy_data = true are mutually exclusive options
51+
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, enabled = true);
52+
ERROR: connect = false and enabled = true are mutually exclusive options
53+
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, create_slot = true);
54+
ERROR: connect = false and create_slot = true are mutually exclusive options
55+
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = true);
56+
ERROR: slot_name = NONE and enabled = true are mutually exclusive options
57+
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, create_slot = true);
58+
ERROR: slot_name = NONE and create_slot = true are mutually exclusive options
59+
-- ok - with slot_name = NONE
60+
CREATE SUBSCRIPTION testsub3 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, connect = false);
61+
WARNING: tables were not subscribed, you will have to run ALTER SUBSCRIPTION ... REFRESH PUBLICATION to subscribe the tables
62+
-- fail
63+
ALTER SUBSCRIPTION testsub3 ENABLE;
64+
ERROR: cannot enable subscription that does not have a slot name
65+
ALTER SUBSCRIPTION testsub3 REFRESH PUBLICATION;
66+
ERROR: ALTER SUBSCRIPTION ... REFRESH is not allowed for disabled subscriptions
67+
DROP SUBSCRIPTION testsub3;
4868
-- fail - invalid connection string
4969
ALTER SUBSCRIPTION testsub CONNECTION 'foobar';
5070
ERROR: invalid connection string syntax: missing "=" after "foobar" in connection info string

src/test/regress/sql/subscription.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,21 @@ SET SESSION AUTHORIZATION 'regress_subscription_user2';
3838
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION foo WITH (connect = false);
3939
SET SESSION AUTHORIZATION 'regress_subscription_user';
4040

41+
-- fail - invalid option combinations
42+
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, copy_data = true);
43+
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, enabled = true);
44+
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (connect = false, create_slot = true);
45+
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, enabled = true);
46+
CREATE SUBSCRIPTION testsub2 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, create_slot = true);
47+
48+
-- ok - with slot_name = NONE
49+
CREATE SUBSCRIPTION testsub3 CONNECTION 'dbname=doesnotexist' PUBLICATION testpub WITH (slot_name = NONE, connect = false);
50+
-- fail
51+
ALTER SUBSCRIPTION testsub3 ENABLE;
52+
ALTER SUBSCRIPTION testsub3 REFRESH PUBLICATION;
53+
54+
DROP SUBSCRIPTION testsub3;
55+
4156
-- fail - invalid connection string
4257
ALTER SUBSCRIPTION testsub CONNECTION 'foobar';
4358

0 commit comments

Comments
 (0)
0