Skip to content

Commit 312a11c

Browse files
jnasbyupgradeclaude
andcommitted
Consolidate relation__ and routine__ test suites
Merge 8 single-function test files into 2 combined suites to reduce repeated setup and keep related tests together: - relation__.sql: relation_type + is_temp + is_catalog + column_names (41 tests) - routine__.sql: routine_type + argument_mode + volatility + parallel_safety (57 tests) Rename conflicting temp table names (test_temp_table → is_temp_test / is_catalog_test) to avoid collision within the merged relation__ suite. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0c54003 commit 312a11c

19 files changed

Lines changed: 449 additions & 543 deletions
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
\set ECHO none
2-
1..23
2+
1..41
33
ok 1 - Verify count from kinds
44
ok 2 - Simple sanity check of relation__kind()
55
ok 3 - Simple sanity check of relation__relkind()
@@ -23,4 +23,22 @@ ok 20 - SELECT cat_tools.relation_type('f')
2323
ok 21 - SELECT cat_tools.relation_type('m')
2424
ok 22 - SELECT cat_tools.relation_type('p')
2525
ok 23 - SELECT cat_tools.relation_type('I')
26+
ok 24 - Verify public has no perms
27+
ok 25 - pg_catalog.pg_class is not a temp relation
28+
ok 26 - Create temp table for testing
29+
ok 27 - temp relation is correctly identified as temp
30+
ok 28 - NULL input returns NULL (STRICT function)
31+
ok 29 - Verify public has no perms
32+
ok 30 - pg_catalog.pg_class is in pg_catalog schema
33+
ok 31 - Create temp table for testing
34+
ok 32 - temp relation is not in pg_catalog schema
35+
ok 33 - NULL input returns NULL (STRICT function)
36+
ok 34 - Verify public has no perms
37+
ok 35 - Create temp table with multiple columns
38+
ok 36 - Temp table returns expected column names
39+
ok 37 - Drop middle column from temp table
40+
ok 38 - Temp table with dropped column returns expected column names
41+
ok 39 - Create test table with columns
42+
ok 40 - Test table returns expected column names
43+
ok 41 - NULL input returns NULL (STRICT function)
2644
# TRANSACTION INTENTIONALLY LEFT OPEN!

test/expected/relation__column_names.out

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/expected/relation__is_catalog.out

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/expected/relation__is_temp.out

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/expected/routine__.out

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
\set ECHO none
2+
1..57
3+
ok 1 - Verify count from routine_kinds
4+
ok 2 - Simple sanity check of routine__type()
5+
ok 3 - Simple sanity check of routine__type() with enum
6+
ok 4 - SELECT cat_tools.routine__type('f'::cat_tools.routine_prokind)
7+
ok 5 - SELECT cat_tools.routine__type('p'::cat_tools.routine_prokind)
8+
ok 6 - SELECT cat_tools.routine__type('a'::cat_tools.routine_prokind)
9+
ok 7 - SELECT cat_tools.routine__type('w'::cat_tools.routine_prokind)
10+
ok 8 - SELECT cat_tools.routine__type('f'::"char")
11+
ok 9 - SELECT cat_tools.routine__type('p'::"char")
12+
ok 10 - SELECT cat_tools.routine__type('a'::"char")
13+
ok 11 - SELECT cat_tools.routine__type('w'::"char")
14+
ok 12 - SELECT cat_tools.routine__type('f')
15+
ok 13 - SELECT cat_tools.routine__type('p')
16+
ok 14 - SELECT cat_tools.routine__type('a')
17+
ok 15 - SELECT cat_tools.routine__type('w')
18+
ok 16 - Verify count from argument_modes
19+
ok 17 - Simple sanity check of routine__argument_mode()
20+
ok 18 - Simple sanity check of routine__argument_mode() with enum
21+
ok 19 - SELECT cat_tools.routine__argument_mode('i'::cat_tools.routine_proargmode)
22+
ok 20 - SELECT cat_tools.routine__argument_mode('o'::cat_tools.routine_proargmode)
23+
ok 21 - SELECT cat_tools.routine__argument_mode('b'::cat_tools.routine_proargmode)
24+
ok 22 - SELECT cat_tools.routine__argument_mode('v'::cat_tools.routine_proargmode)
25+
ok 23 - SELECT cat_tools.routine__argument_mode('t'::cat_tools.routine_proargmode)
26+
ok 24 - SELECT cat_tools.routine__argument_mode('i'::"char")
27+
ok 25 - SELECT cat_tools.routine__argument_mode('o'::"char")
28+
ok 26 - SELECT cat_tools.routine__argument_mode('b'::"char")
29+
ok 27 - SELECT cat_tools.routine__argument_mode('v'::"char")
30+
ok 28 - SELECT cat_tools.routine__argument_mode('t'::"char")
31+
ok 29 - SELECT cat_tools.routine__argument_mode('i')
32+
ok 30 - SELECT cat_tools.routine__argument_mode('o')
33+
ok 31 - SELECT cat_tools.routine__argument_mode('b')
34+
ok 32 - SELECT cat_tools.routine__argument_mode('v')
35+
ok 33 - SELECT cat_tools.routine__argument_mode('t')
36+
ok 34 - Verify count from volatilities
37+
ok 35 - Simple sanity check of routine__volatility()
38+
ok 36 - Simple sanity check of routine__volatility() with enum
39+
ok 37 - SELECT cat_tools.routine__volatility('i'::cat_tools.routine_provolatile)
40+
ok 38 - SELECT cat_tools.routine__volatility('s'::cat_tools.routine_provolatile)
41+
ok 39 - SELECT cat_tools.routine__volatility('v'::cat_tools.routine_provolatile)
42+
ok 40 - SELECT cat_tools.routine__volatility('i'::"char")
43+
ok 41 - SELECT cat_tools.routine__volatility('s'::"char")
44+
ok 42 - SELECT cat_tools.routine__volatility('v'::"char")
45+
ok 43 - SELECT cat_tools.routine__volatility('i')
46+
ok 44 - SELECT cat_tools.routine__volatility('s')
47+
ok 45 - SELECT cat_tools.routine__volatility('v')
48+
ok 46 - Verify count from parallel_safeties
49+
ok 47 - Simple sanity check of routine__parallel_safety()
50+
ok 48 - Simple sanity check of routine__parallel_safety() with enum
51+
ok 49 - SELECT cat_tools.routine__parallel_safety('s'::cat_tools.routine_proparallel)
52+
ok 50 - SELECT cat_tools.routine__parallel_safety('r'::cat_tools.routine_proparallel)
53+
ok 51 - SELECT cat_tools.routine__parallel_safety('u'::cat_tools.routine_proparallel)
54+
ok 52 - SELECT cat_tools.routine__parallel_safety('s'::"char")
55+
ok 53 - SELECT cat_tools.routine__parallel_safety('r'::"char")
56+
ok 54 - SELECT cat_tools.routine__parallel_safety('u'::"char")
57+
ok 55 - SELECT cat_tools.routine__parallel_safety('s')
58+
ok 56 - SELECT cat_tools.routine__parallel_safety('r')
59+
ok 57 - SELECT cat_tools.routine__parallel_safety('u')
60+
# TRANSACTION INTENTIONALLY LEFT OPEN!

test/expected/routine_argument_mode.out

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/expected/routine_parallel_safety.out

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/expected/routine_type.out

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/expected/routine_volatility.out

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/sql/relation__.sql

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
\set ECHO none
2+
3+
\i test/setup.sql
4+
5+
SET LOCAL ROLE :use_role;
6+
CREATE TEMP VIEW kinds AS
7+
SELECT
8+
(cat_tools.enum_range('cat_tools.relation_type'))[gs] AS kind
9+
, (cat_tools.enum_range('cat_tools.relation_relkind'))[gs] AS relkind
10+
FROM generate_series(
11+
1
12+
, greatest(
13+
array_upper(cat_tools.enum_range('cat_tools.relation_type'), 1)
14+
, array_upper(cat_tools.enum_range('cat_tools.relation_relkind'), 1)
15+
)
16+
) gs
17+
;
18+
19+
SELECT plan(
20+
(1 + 2 + 2 * (SELECT count(*)::int FROM kinds)) -- relation_type enum mapping
21+
+ 5 -- relation__is_temp
22+
+ 5 -- relation__is_catalog
23+
+ 8 -- relation__column_names
24+
);
25+
26+
-- relation_type enum mapping
27+
SELECT is(
28+
(SELECT count(*)::int FROM kinds)
29+
, 10
30+
, 'Verify count from kinds'
31+
);
32+
33+
SELECT is(
34+
cat_tools.relation__kind('r')
35+
, 'table'
36+
, 'Simple sanity check of relation__kind()'
37+
);
38+
SELECT is(
39+
cat_tools.relation__relkind('table')
40+
, 'r'
41+
, 'Simple sanity check of relation__relkind()'
42+
);
43+
44+
SELECT is(cat_tools.relation__relkind(kind)::text, relkind, format('SELECT cat_tools.relation_relkind(%L)', kind))
45+
FROM kinds
46+
;
47+
48+
SELECT is(cat_tools.relation__kind(relkind)::text, kind, format('SELECT cat_tools.relation_type(%L)', relkind))
49+
FROM kinds
50+
;
51+
52+
-- relation__is_temp
53+
\set s cat_tools
54+
\set f relation__is_temp
55+
56+
SET LOCAL ROLE :no_use_role;
57+
58+
SELECT throws_ok(
59+
format(
60+
$$SELECT %I.%I( %L )$$
61+
, :'s', :'f'
62+
, 'pg_catalog.pg_class'
63+
)
64+
, '42501'
65+
, NULL
66+
, 'Verify public has no perms'
67+
);
68+
69+
SET LOCAL ROLE :use_role;
70+
71+
SELECT is(
72+
cat_tools.relation__is_temp('pg_catalog.pg_class'::regclass)
73+
, false
74+
, 'pg_catalog.pg_class is not a temp relation'
75+
);
76+
77+
SELECT lives_ok($$CREATE TEMP TABLE is_temp_test()$$, 'Create temp table for testing');
78+
79+
SELECT is(
80+
cat_tools.relation__is_temp('is_temp_test'::regclass)
81+
, true
82+
, 'temp relation is correctly identified as temp'
83+
);
84+
85+
SELECT is(
86+
cat_tools.relation__is_temp(NULL)
87+
, NULL
88+
, 'NULL input returns NULL (STRICT function)'
89+
);
90+
91+
-- relation__is_catalog
92+
\set f relation__is_catalog
93+
94+
SET LOCAL ROLE :no_use_role;
95+
96+
SELECT throws_ok(
97+
format(
98+
$$SELECT %I.%I( %L )$$
99+
, :'s', :'f'
100+
, 'pg_catalog.pg_class'
101+
)
102+
, '42501'
103+
, NULL
104+
, 'Verify public has no perms'
105+
);
106+
107+
SET LOCAL ROLE :use_role;
108+
109+
SELECT is(
110+
cat_tools.relation__is_catalog('pg_catalog.pg_class'::regclass)
111+
, true
112+
, 'pg_catalog.pg_class is in pg_catalog schema'
113+
);
114+
115+
SELECT lives_ok($$CREATE TEMP TABLE is_catalog_test()$$, 'Create temp table for testing');
116+
117+
SELECT is(
118+
cat_tools.relation__is_catalog('is_catalog_test'::regclass)
119+
, false
120+
, 'temp relation is not in pg_catalog schema'
121+
);
122+
123+
SELECT is(
124+
cat_tools.relation__is_catalog(NULL)
125+
, NULL
126+
, 'NULL input returns NULL (STRICT function)'
127+
);
128+
129+
-- relation__column_names
130+
\set f relation__column_names
131+
132+
SET LOCAL ROLE :no_use_role;
133+
134+
SELECT throws_ok(
135+
format(
136+
$$SELECT %I.%I( %L )$$
137+
, :'s', :'f'
138+
, 'temp_test_table'
139+
)
140+
, '42501'
141+
, NULL
142+
, 'Verify public has no perms'
143+
);
144+
145+
SET LOCAL ROLE :use_role;
146+
147+
SELECT lives_ok($$CREATE TEMP TABLE temp_test_table(col1 int, col2 text, col3 boolean, col4 timestamp, col5 numeric)$$, 'Create temp table with multiple columns');
148+
149+
SELECT is(
150+
cat_tools.relation__column_names('temp_test_table'::regclass)
151+
, '{col1,col2,col3,col4,col5}'::text[]
152+
, 'Temp table returns expected column names'
153+
);
154+
155+
SELECT lives_ok($$ALTER TABLE temp_test_table DROP COLUMN col3$$, 'Drop middle column from temp table');
156+
157+
SELECT is(
158+
cat_tools.relation__column_names('temp_test_table'::regclass)
159+
, '{col1,col2,col4,col5}'::text[]
160+
, 'Temp table with dropped column returns expected column names'
161+
);
162+
163+
SELECT lives_ok($$CREATE TEMP TABLE test_table(id int, name text)$$, 'Create test table with columns');
164+
165+
SELECT is(
166+
cat_tools.relation__column_names('test_table'::regclass)
167+
, '{id,name}'::text[]
168+
, 'Test table returns expected column names'
169+
);
170+
171+
SELECT is(
172+
cat_tools.relation__column_names(NULL)
173+
, NULL
174+
, 'NULL input returns NULL (STRICT function)'
175+
);
176+
177+
\i test/pgxntool/finish.sql
178+
179+
-- vi: expandtab ts=2 sw=2

0 commit comments

Comments
 (0)