Skip to content

Commit

Permalink
Add missing function has_composite() without desc
Browse files Browse the repository at this point in the history
  • Loading branch information
rodo committed Sep 24, 2024
1 parent c2472af commit dac2e9c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Revision history for pgTAP
* Fixed the upgrade from v1.2.0 to v1.3.0. Thanks to @runqitian for the pull
request (#338).

* Add missing function has_composite ( NAME, NAME ) and hasnt_composite ( NAME, NAME )

1.3.3 2024-04-08T13:44:11Z
--------------------------

Expand Down Expand Up @@ -278,7 +280,7 @@ Revision history for pgTAP
Quiédeville (PR #106).
* Add `has_extension()` and `hasnt_extension()`. Thanks to Rodolphe Quiédeville
(PR #101).

0.96.0 2016-05-16T20:53:57Z
---------------------------
* Added an optional `:exclude_pattern` parameter to `findfuncs()` to prevent
Expand Down
14 changes: 13 additions & 1 deletion sql/pgtap--1.3.3--1.3.4.sql
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
-- TBD
-- has_composite( schema, type )
CREATE OR REPLACE FUNCTION has_composite ( NAME, NAME )
RETURNS TEXT AS $$
SELECT has_composite($1, $2,
'Composite type ' || quote_ident($1) || '.' || quote_ident($2) || ' should exist' );
$$ LANGUAGE SQL;

-- hasnt_composite( schema, type )
CREATE OR REPLACE FUNCTION hasnt_composite ( NAME, NAME )
RETURNS TEXT AS $$
SELECT hasnt_composite($1, $2,
'Composite type ' || quote_ident($1) || '.' || quote_ident($2) || ' should not exist' );
$$ LANGUAGE SQL;
18 changes: 16 additions & 2 deletions sql/pgtap.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -869,11 +869,11 @@ BEGIN
SELECT GREATEST((return_percent * iterations)::int, 1) INTO limit_it;

FOR a_time IN SELECT times[i]
FROM generate_series(array_lower(times, 1), array_upper(times, 1)) i
FROM generate_series(array_lower(times, 1), array_upper(times, 1)) i
ORDER BY 1
OFFSET offset_it
LIMIT limit_it LOOP
RETURN NEXT a_time;
RETURN NEXT a_time;
END LOOP;
END;
$$ LANGUAGE plpgsql;
Expand Down Expand Up @@ -1223,6 +1223,13 @@ RETURNS TEXT AS $$
SELECT ok( _rexists( 'c', $1, $2 ), $3 );
$$ LANGUAGE SQL;

-- has_composite( schema, type )
CREATE OR REPLACE FUNCTION has_composite ( NAME, NAME )
RETURNS TEXT AS $$
SELECT has_composite($1, $2,
'Composite type ' || quote_ident($1) || '.' || quote_ident($2) || ' should exist' );
$$ LANGUAGE SQL;

-- has_composite( type, description )
CREATE OR REPLACE FUNCTION has_composite ( NAME, TEXT )
RETURNS TEXT AS $$
Expand All @@ -1241,6 +1248,13 @@ RETURNS TEXT AS $$
SELECT ok( NOT _rexists( 'c', $1, $2 ), $3 );
$$ LANGUAGE SQL;

-- hasnt_composite( schema, type )
CREATE OR REPLACE FUNCTION hasnt_composite ( NAME, NAME )
RETURNS TEXT AS $$
SELECT hasnt_composite($1, $2,
'Composite type ' || quote_ident($1) || '.' || quote_ident($2) || ' should not exist' );
$$ LANGUAGE SQL;

-- hasnt_composite( type, description )
CREATE OR REPLACE FUNCTION hasnt_composite ( NAME, TEXT )
RETURNS TEXT AS $$
Expand Down
42 changes: 34 additions & 8 deletions test/sql/hastap.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
\i test/setup.sql
-- \i sql/pgtap.sql

SELECT plan(1004);
SELECT plan(1013);
--SELECT * FROM no_plan();

-- This will be rolled back. :-)
Expand Down Expand Up @@ -579,6 +579,23 @@ SELECT * FROM check_test(
''
);

SELECT * FROM check_test(
has_composite( 'public'::name, '__SDFSDFD__'::name ),
false,
'has_composite(schema, type)',
'Composite type public."__SDFSDFD__" should exist',
''
);

SELECT * FROM check_test(
has_composite( 'public'::name, 'sometype'::name ),
true,
'has_composite(schema, type)',
'Composite type public.sometype should exist',
''
);


SELECT * FROM check_test(
has_composite( 'public', 'sometype', 'desc' ),
true,
Expand Down Expand Up @@ -638,6 +655,15 @@ SELECT * FROM check_test(
''
);

SELECT * FROM check_test(
hasnt_composite( 'public'::name, '__SDFSDFD__'::name ),
true,
'hasnt_composite(schema, non-existent type',
'Composite type public."__SDFSDFD__" should not exist',
''
);


SELECT * FROM check_test(
hasnt_composite( 'public', 'sometype', 'desc' ),
false,
Expand Down Expand Up @@ -665,7 +691,7 @@ SELECT * FROM check_test(
SELECT * FROM check_test(
has_type( 'public'::name, 'sometype'::name ),
true,
'has_type(scheam, type)',
'has_type(schema, type)',
'Type public.sometype should exist',
''
);
Expand Down Expand Up @@ -2305,7 +2331,7 @@ SELECT * FROM check_test(
domain_type_is( 'public'::name, 'us_postal_code', 'text'),
true,
'domain_type_is(schema, domain, type)',
'Domain public.us_postal_code should extend type text',
'Domain public.us_postal_code should extend type text',
''
);

Expand Down Expand Up @@ -2346,7 +2372,7 @@ SELECT * FROM check_test(
domain_type_is( 'us_postal_code', 'text'),
true,
'domain_type_is(domain, type)',
'Domain us_postal_code should extend type text',
'Domain us_postal_code should extend type text',
''
);

Expand Down Expand Up @@ -2428,7 +2454,7 @@ SELECT * FROM check_test(
domain_type_isnt( 'public'::name, 'us_postal_code', 'int'),
true,
'domain_type_isnt(schema, domain, type)',
'Domain public.us_postal_code should not extend type int',
'Domain public.us_postal_code should not extend type int',
''
);

Expand Down Expand Up @@ -2469,7 +2495,7 @@ SELECT * FROM check_test(
domain_type_isnt( 'us_postal_code', 'int'),
true,
'domain_type_isnt(domain, type)',
'Domain us_postal_code should not extend type int',
'Domain us_postal_code should not extend type int',
''
);

Expand Down Expand Up @@ -2503,7 +2529,7 @@ SELECT * FROM check_test(
CREATE FUNCTION test_fdw() RETURNS SETOF TEXT AS $$
DECLARE
tap record;
BEGIN
BEGIN
IF pg_version_num() >= 90100 THEN
EXECUTE $E$
CREATE FOREIGN DATA WRAPPER dummy;
Expand Down Expand Up @@ -3272,7 +3298,7 @@ BEGIN
) AS b LOOP
RETURN NEXT tap.b;
END LOOP;

FOR tap IN SELECT * FROM check_test(
has_view( 'pg_tables' ),
true,
Expand Down

0 comments on commit dac2e9c

Please sign in to comment.