Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2636453

Browse files
committed
Hopefully-portable regression tests for CREATE/ALTER/DROP COLLATION.
The collate.linux.utf8 test covers some of the same territory, but isn't portable and so probably does not get run often, or on non-Linux platforms. If this approach turns out to be sufficiently portable, we may want to look at trimming the redundant tests out of that file to avoid duplication. Robins Tharakan, reviewed by Michael Paquier and Fabien Coelho, with further changes and cleanup by me.
1 parent 5530a82 commit 2636453

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

src/test/regress/expected/collate.out

+46
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,51 @@ SELECT collation for ((SELECT b FROM collate_test1 LIMIT 1));
626626
"C"
627627
(1 row)
628628

629+
-- CREATE COLLATE tests
630+
CREATE COLLATION collate_coll2 FROM "C";
631+
-- Ensure non-OWNER ROLEs are not able to ALTER/DROP COLLATION
632+
CREATE ROLE regress_rol_col1;
633+
GRANT USAGE ON SCHEMA collate_tests TO regress_rol_col1;
634+
SET ROLE regress_rol_col1;
635+
DROP COLLATION IF EXISTS collate_tests.collate_coll2;
636+
ERROR: must be owner of collation collate_tests.collate_coll2
637+
RESET ROLE;
638+
-- Ensure ALTER COLLATION SET SCHEMA works as expected
639+
CREATE SCHEMA collate_tests2;
640+
ALTER COLLATION collate_coll2 SET SCHEMA collate_tests2;
641+
DROP COLLATION collate_tests2.collate_coll2;
642+
DROP SCHEMA collate_tests2;
643+
-- Should work. Classic cases of CREATE/ALTER COLLATION
644+
CREATE COLLATION collate_coll3 (LOCALE = 'C');
645+
ALTER COLLATION collate_coll3 OWNER TO regress_rol_col1;
646+
ALTER COLLATION collate_coll3 RENAME TO collate_coll33;
647+
DROP COLLATION collate_coll33;
648+
-- Should fail. Give redundant options
649+
CREATE COLLATION collate_coll3a (LOCALE = 'C', LC_COLLATE = 'C', LC_CTYPE= 'C');
650+
ERROR: conflicting or redundant options
651+
-- Should fail. LC_COLLATE must be specified
652+
CREATE COLLATION collate_coll5 (LC_CTYPE= 'C');
653+
ERROR: parameter "lc_collate" must be specified
654+
-- Should fail. Give value options without value
655+
CREATE COLLATION collate_coll4a (LC_COLLATE = '');
656+
ERROR: parameter "lc_ctype" must be specified
657+
CREATE COLLATION collate_coll5a (LC_CTYPE= '');
658+
ERROR: parameter "lc_collate" must be specified
659+
-- Should fail. Give invalid option name
660+
CREATE COLLATION collate_coll6 (ASDF = 'C');
661+
ERROR: collation attribute "asdf" not recognized
662+
-- Ensure ROLEs without USAGE access can't CREATE/ALTER COLLATION
663+
CREATE SCHEMA collate_tests4;
664+
CREATE COLLATION collate_tests4.collate_coll9 (LOCALE = 'C');
665+
REVOKE USAGE ON SCHEMA collate_tests4 FROM regress_rol_col1;
666+
SET ROLE regress_rol_col1;
667+
ALTER COLLATION collate_tests4.collate_coll9 RENAME TO collate_coll9b;
668+
ERROR: permission denied for schema collate_tests4
669+
CREATE COLLATION collate_tests4.collate_coll10 (LOCALE = 'C');
670+
ERROR: permission denied for schema collate_tests4
671+
RESET ROLE;
672+
DROP SCHEMA collate_tests4 CASCADE;
673+
NOTICE: drop cascades to collation collate_coll9
629674
--
630675
-- Clean up. Many of these table names will be re-used if the user is
631676
-- trying to run any platform-specific collation tests later, so we
@@ -648,3 +693,4 @@ drop cascades to function dup(anyelement)
648693
drop cascades to table collate_test20
649694
drop cascades to table collate_test21
650695
drop cascades to table collate_test22
696+
DROP ROLE regress_rol_col1;

src/test/regress/sql/collate.sql

+45
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,55 @@ SELECT collation for ('foo'::text);
231231
SELECT collation for ((SELECT a FROM collate_test1 LIMIT 1)); -- non-collatable type - error
232232
SELECT collation for ((SELECT b FROM collate_test1 LIMIT 1));
233233

234+
-- CREATE COLLATE tests
235+
CREATE COLLATION collate_coll2 FROM "C";
236+
237+
-- Ensure non-OWNER ROLEs are not able to ALTER/DROP COLLATION
238+
CREATE ROLE regress_rol_col1;
239+
GRANT USAGE ON SCHEMA collate_tests TO regress_rol_col1;
240+
SET ROLE regress_rol_col1;
241+
DROP COLLATION IF EXISTS collate_tests.collate_coll2;
242+
RESET ROLE;
243+
244+
-- Ensure ALTER COLLATION SET SCHEMA works as expected
245+
CREATE SCHEMA collate_tests2;
246+
ALTER COLLATION collate_coll2 SET SCHEMA collate_tests2;
247+
DROP COLLATION collate_tests2.collate_coll2;
248+
DROP SCHEMA collate_tests2;
249+
250+
-- Should work. Classic cases of CREATE/ALTER COLLATION
251+
CREATE COLLATION collate_coll3 (LOCALE = 'C');
252+
ALTER COLLATION collate_coll3 OWNER TO regress_rol_col1;
253+
ALTER COLLATION collate_coll3 RENAME TO collate_coll33;
254+
DROP COLLATION collate_coll33;
255+
256+
-- Should fail. Give redundant options
257+
CREATE COLLATION collate_coll3a (LOCALE = 'C', LC_COLLATE = 'C', LC_CTYPE= 'C');
258+
259+
-- Should fail. LC_COLLATE must be specified
260+
CREATE COLLATION collate_coll5 (LC_CTYPE= 'C');
261+
262+
-- Should fail. Give value options without value
263+
CREATE COLLATION collate_coll4a (LC_COLLATE = '');
264+
CREATE COLLATION collate_coll5a (LC_CTYPE= '');
265+
266+
-- Should fail. Give invalid option name
267+
CREATE COLLATION collate_coll6 (ASDF = 'C');
268+
269+
-- Ensure ROLEs without USAGE access can't CREATE/ALTER COLLATION
270+
CREATE SCHEMA collate_tests4;
271+
CREATE COLLATION collate_tests4.collate_coll9 (LOCALE = 'C');
272+
REVOKE USAGE ON SCHEMA collate_tests4 FROM regress_rol_col1;
273+
SET ROLE regress_rol_col1;
274+
ALTER COLLATION collate_tests4.collate_coll9 RENAME TO collate_coll9b;
275+
CREATE COLLATION collate_tests4.collate_coll10 (LOCALE = 'C');
276+
RESET ROLE;
277+
DROP SCHEMA collate_tests4 CASCADE;
234278

235279
--
236280
-- Clean up. Many of these table names will be re-used if the user is
237281
-- trying to run any platform-specific collation tests later, so we
238282
-- must get rid of them.
239283
--
240284
DROP SCHEMA collate_tests CASCADE;
285+
DROP ROLE regress_rol_col1;

0 commit comments

Comments
 (0)