Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/deps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ SET client_min_messages = WARNING;
* the test/sql/ files). psql variables are session-local, not committed DB
* state, so they must still be (re)set per test file.
*
* The role names are also set by test/install/load.sql (which creates the
* roles); keep the two in sync. Add any OTHER per-test dependency
* \set/statements here; committed dependencies belong in test/install/load.sql.
* The role names live in exactly one place, test/roles.sql, \i'd here and by
* test/install/load.sql (which creates the roles). Add any OTHER per-test
* dependency \set/statements here; committed dependencies belong in
* test/install/load.sql.
*/
\set no_use_role cat_tools_testing__no_use_role
\set use_role cat_tools_testing__use_role
\i test/roles.sql
19 changes: 10 additions & 9 deletions test/install/load.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@
SET client_min_messages = WARNING;

/*
* The test-role names, set here and mirrored per-test by test/deps.sql (psql
* variables are session-local, so both this committed installer and each
* rolled-back test file must set them). Each :var holds the identifier; the
* pg_temp helper functions below receive it as a text literal (:'use_role') and
* quote it via format(%I).
* The test-role names live in one place, test/roles.sql, \i'd here and mirrored
* per-test by test/deps.sql (psql variables are session-local, so both this
* committed installer and each rolled-back test file must set them). Each :var
* holds the identifier; the pg_temp helper functions below receive it as a text
* literal (:'use_role') and quote it via format(%I); the identifier-position
* uses below (GRANT ... TO :"use_role") quote it directly. The names require
* quoting, so an unquoted reference would surface as a test failure.
*/
\set no_use_role cat_tools_testing__no_use_role
\set use_role cat_tools_testing__use_role
\i test/roles.sql

/*
* Mode selection. The Makefile always exports cat_tools.test_load_mode via
Expand Down Expand Up @@ -186,12 +187,12 @@ $$;
SELECT pg_temp.create_role(:'no_use_role');
SELECT pg_temp.create_role(:'use_role');

GRANT cat_tools__usage TO :use_role;
GRANT cat_tools__usage TO :"use_role";
/*
* PG15+ removed CREATE on the public schema from PUBLIC; grant it explicitly
* for tests that create shadow names in public to check catalog-lookup
* correctness.
*/
GRANT CREATE ON SCHEMA public TO :use_role;
GRANT CREATE ON SCHEMA public TO :"use_role";

-- vi: expandtab ts=2 sw=2
9 changes: 9 additions & 0 deletions test/roles.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Single source of truth for the test role names. \i'd by test/install/load.sql
* (which creates the roles, committed-once) and per-test by test/deps.sql (psql
* variables are session-local, so each rolled-back test file must re-set them).
* The names intentionally require quoting, so a quoting bug in the code under
* test surfaces as a failure rather than passing silently on a quote-free name.
*/
\set no_use_role 'cat_tools testing: NO USE'
\set use_role 'cat_tools testing: USE'
2 changes: 1 addition & 1 deletion test/setup.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- Pulls in deps.sql
\i test/pgxntool/setup.sql

GRANT USAGE ON SCHEMA tap TO :use_role, :no_use_role;
GRANT USAGE ON SCHEMA tap TO :"use_role", :"no_use_role";

CREATE FUNCTION pg_temp.exec(
sql text
Expand Down
4 changes: 2 additions & 2 deletions test/sql/attribute.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SELECT plan(
+ 4 -- pg_attribute__get()
);

SET LOCAL ROLE :no_use_role;
SET LOCAL ROLE :"no_use_role";

SELECT throws_ok(
format(
Expand All @@ -33,7 +33,7 @@ SELECT throws_ok(
FROM func_calls
;

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

/*
* pg_attribute__get()
Expand Down
4 changes: 2 additions & 2 deletions test/sql/enum.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SELECT lives_ok(
, 'Create test enum'
);

SET LOCAL ROLE :no_use_role;
SET LOCAL ROLE :"no_use_role";
SELECT throws_ok(
format( 'SELECT cat_tools.enum_range%s( %L )', suffix, :'test_enum' )
, '42501'
Expand All @@ -27,7 +27,7 @@ SELECT throws_ok(
FROM unnest( array['', '_srf'] ) AS suffix
;

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

-- This will test both functions
SELECT results_eq(
Expand Down
2 changes: 1 addition & 1 deletion test/sql/extension.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-- test_role is set in test/deps.sql

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

SELECT plan(
0
Expand Down
4 changes: 2 additions & 2 deletions test/sql/function.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SELECT plan(
+ 2 -- regprocedure()
);

SET LOCAL ROLE :no_use_role;
SET LOCAL ROLE :"no_use_role";

SELECT throws_ok(
format(
Expand All @@ -35,7 +35,7 @@ SELECT throws_ok(
FROM func_calls
;

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

SELECT is(
:s.function__arg_types($$IN in_int int, INOUT inout_int_array int[], OUT out_char "char", anyelement, boolean DEFAULT false$$)
Expand Down
4 changes: 2 additions & 2 deletions test/sql/name__check.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

SELECT plan(5);

SET LOCAL ROLE :no_use_role;
SET LOCAL ROLE :"no_use_role";

SELECT throws_ok(
format(
Expand All @@ -20,7 +20,7 @@ SELECT throws_ok(
, 'Verify public has no perms'
);

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

SELECT lives_ok(
format(
Expand Down
6 changes: 3 additions & 3 deletions test/sql/object_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-- test_role is set in test/deps.sql

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

CREATE FUNCTION pg_temp.extra_types()
RETURNS text[] LANGUAGE sql IMMUTABLE AS $$
Expand Down Expand Up @@ -76,7 +76,7 @@ SELECT is(
, 'sanity check size of pg_temp.obj_type'
);

SET LOCAL ROLE :no_use_role;
SET LOCAL ROLE :"no_use_role";
SELECT throws_ok(
format( 'SELECT NULL::%I', typename )
, '42704' -- undefined_object; not exactly correct, but close enough
Expand All @@ -100,7 +100,7 @@ SELECT throws_ok(
) v(argtype)
;

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

SELECT function_returns(
'cat_tools'
Expand Down
4 changes: 2 additions & 2 deletions test/sql/pg_depends.sql
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ END;
* END tests to run as owner
*/

SET LOCAL ROLE :no_use_role;
SET LOCAL ROLE :"no_use_role";

SELECT CASE
WHEN pg_temp.major() < 903 THEN
Expand All @@ -96,7 +96,7 @@ SELECT CASE
FROM views
;

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

\i test/pgxntool/finish.sql

Expand Down
6 changes: 3 additions & 3 deletions test/sql/relation_type.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-- test_role is set in test/deps.sql

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";
/*
* Canonical (relkind, kind) pairs per pg_class.h, hard-coded so the assertions
* below actually verify the mapping rather than re-encoding enum order.
Expand Down Expand Up @@ -45,7 +45,7 @@ SELECT is(
, 'Simple sanity check of relation__relkind()'
);

SET LOCAL ROLE :no_use_role;
SET LOCAL ROLE :"no_use_role";
SELECT throws_ok(
format( 'SELECT NULL::%I', typename )
, '42704' -- undefined_object; not exactly correct, but close enough
Expand All @@ -69,7 +69,7 @@ SELECT throws_ok(
) v(suffix, argtype)
;

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

SELECT is(cat_tools.relation__relkind(kind)::text, relkind, format('SELECT cat_tools.relation_relkind(%L)', kind))
FROM kinds
Expand Down
6 changes: 3 additions & 3 deletions test/sql/sequence.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-- test_role is set in test/deps.sql

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

CREATE TEMP TABLE seqtest(s serial);
CREATE TEMP TABLE functions(fname name);
Expand All @@ -29,7 +29,7 @@ SELECT plan((
)::int);

GRANT SELECT ON functions TO public;
SET LOCAL ROLE :no_use_role;
SET LOCAL ROLE :"no_use_role";
SELECT throws_ok(
format( $$SELECT cat_tools.%I('seqtest', 's')$$, fname )
, '42501' -- insufficient_privilege
Expand All @@ -39,7 +39,7 @@ SELECT throws_ok(
FROM functions
;

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

SELECT function_returns( sname, fname, 'bigint'::regtype::text ) FROM fv;
SELECT volatility_is( sname, fname, 'volatile' ) FROM fv;
Expand Down
4 changes: 2 additions & 2 deletions test/sql/trigger.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SELECT plan(
+ 1 -- verify trigger__args_as_array()
);

SET LOCAL ROLE :no_use_role;
SET LOCAL ROLE :"no_use_role";

SELECT throws_ok(
format(
Expand All @@ -34,7 +34,7 @@ SELECT throws_ok(
FROM unnest(:function_array) f
;

SET LOCAL ROLE :use_role;
SET LOCAL ROLE :"use_role";

CREATE TEMP TABLE "test table"();

Expand Down
Loading