Skip to content
Open
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
44 changes: 42 additions & 2 deletions doc/pgtap.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -2254,12 +2254,12 @@ missing triggers, like so:
: Name of a schema in which to find functions.

`:functions`
: An array of function and/or procedure names.
: An array of function names.

`:description`
: A short description of the test.

This function tests that all of the functions or procedures in the named schema,
This function tests that all of the functions in the named schema,
or that are visible in the search path, are only the functions that *should* be
there. If the `:schema` argument is omitted, functions will be sought in the
search path, excluding `pg_catalog` and `information_schema` If the description
Expand All @@ -2279,6 +2279,46 @@ missing functions, like so:
# Missing functions:
# frobnitz

### `procedures_are()` ###

SELECT ### `procedures_are()` ###

SELECT procedures_are( :schema, :procedures, :description );
SELECT procedures_are( :schema, :procedures );
SELECT procedures_are( :procedures, :description );
SELECT procedures_are( :procedures );

**Parameters**

`:schema`
: Name of a schema in which to find procedures.

`:procedures`
: An array of procedure names.

`:description`
: A short description of the test.

This function tests that all of the procedures in the named schema,
or that are visible in the search path, are only the procedures that *should* be
there. If the `:schema` argument is omitted, procedures will be sought in the
search path, excluding `pg_catalog` and `information_schema` If the description
is omitted, a generally useful default description will be generated. Example:

SELECT procedures_are(
'myschema',
ARRAY[ 'foo', 'bar', 'frobnitz' ]
);

In the event of a failure, you'll see diagnostics listing the extra and/or
missing procedures, like so:

# Failed test 150: "Schema someschema should have the correct procedures"
# Extra procedures:
# schnauzify
# Missing procedures:
# frobnitz

### `roles_are()` ###

SELECT roles_are( :roles, :description );
Expand Down
55 changes: 55 additions & 0 deletions sql/pgtap--1.3.4--1.4.0.sql
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration file is missing the changes to the functions_are() functions.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- procedures_are( schema, procedures[], description )
CREATE OR REPLACE FUNCTION procedures_are ( NAME, NAME[], TEXT )
RETURNS TEXT AS $$
SELECT _are(
'procedures',
ARRAY(
SELECT name FROM tap_funky WHERE schema = $1 and prokind = 'p'
EXCEPT
SELECT $2[i]
FROM generate_series(1, array_upper($2, 1)) s(i)
),
ARRAY(
SELECT $2[i]
FROM generate_series(1, array_upper($2, 1)) s(i)
EXCEPT
SELECT name FROM tap_funky WHERE schema = $1 and prokind = 'p'
),
$3
);
$$ LANGUAGE SQL;

-- procedures_are( schema, procedures[] )
CREATE OR REPLACE FUNCTION procedures_are ( NAME, NAME[] )
RETURNS TEXT AS $$
SELECT procedures_are( $1, $2, 'Schema ' || quote_ident($1) || ' should have the correct procedures' );
$$ LANGUAGE SQL;

-- procedures_are( procedures[], description )
CREATE OR REPLACE FUNCTION procedures_are ( NAME[], TEXT )
RETURNS TEXT AS $$
SELECT _are(
'procedures',
ARRAY(
SELECT name FROM tap_funky WHERE is_visible and prokind = 'p'
AND schema NOT IN ('pg_catalog', 'information_schema')
EXCEPT
SELECT $1[i]
FROM generate_series(1, array_upper($1, 1)) s(i)
),
ARRAY(
SELECT $1[i]
FROM generate_series(1, array_upper($1, 1)) s(i)
EXCEPT
SELECT name FROM tap_funky WHERE is_visible and prokind = 'p'
AND schema NOT IN ('pg_catalog', 'information_schema')
),
$2
);
$$ LANGUAGE SQL;

-- procedures_are( procedures[] )
CREATE OR REPLACE FUNCTION procedures_are ( NAME[] )
RETURNS TEXT AS $$
SELECT procedures_are( $1, 'Search path ' || pg_catalog.current_setting('search_path') || ' should have the correct procedures' );
$$ LANGUAGE SQL;
64 changes: 60 additions & 4 deletions sql/pgtap.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -4979,7 +4979,7 @@ RETURNS TEXT AS $$
SELECT _are(
'functions',
ARRAY(
SELECT name FROM tap_funky WHERE schema = $1
SELECT name FROM tap_funky WHERE schema = $1 and kind != 'p'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we do about people who have used these functions for procedures? With this change, their tests will start failing.

I wonder if maybe we should introduce a warning with a deprecation notice and instructions for them to update their tests when kind = 'p', and then remove it in a year or so.

EXCEPT
SELECT $2[i]
FROM generate_series(1, array_upper($2, 1)) s(i)
Expand All @@ -4988,7 +4988,7 @@ RETURNS TEXT AS $$
SELECT $2[i]
FROM generate_series(1, array_upper($2, 1)) s(i)
EXCEPT
SELECT name FROM tap_funky WHERE schema = $1
SELECT name FROM tap_funky WHERE schema = $1 and kind != 'p'
),
$3
);
Expand All @@ -5006,7 +5006,7 @@ RETURNS TEXT AS $$
SELECT _are(
'functions',
ARRAY(
SELECT name FROM tap_funky WHERE is_visible
SELECT name FROM tap_funky WHERE is_visible and kind != 'p'
AND schema NOT IN ('pg_catalog', 'information_schema')
EXCEPT
SELECT $1[i]
Expand All @@ -5016,7 +5016,7 @@ RETURNS TEXT AS $$
SELECT $1[i]
FROM generate_series(1, array_upper($1, 1)) s(i)
EXCEPT
SELECT name FROM tap_funky WHERE is_visible
SELECT name FROM tap_funky WHERE is_visible and kind != 'p'
AND schema NOT IN ('pg_catalog', 'information_schema')
),
$2
Expand All @@ -5029,6 +5029,62 @@ RETURNS TEXT AS $$
SELECT functions_are( $1, 'Search path ' || pg_catalog.current_setting('search_path') || ' should have the correct functions' );
$$ LANGUAGE SQL;

-- procedures_are( schema, procedures[], description )
CREATE OR REPLACE FUNCTION procedures_are ( NAME, NAME[], TEXT )
RETURNS TEXT AS $$
SELECT _are(
'procedures',
ARRAY(
SELECT name FROM tap_funky WHERE schema = $1 and kind = 'p'
EXCEPT
SELECT $2[i]
FROM generate_series(1, array_upper($2, 1)) s(i)
),
ARRAY(
SELECT $2[i]
FROM generate_series(1, array_upper($2, 1)) s(i)
EXCEPT
SELECT name FROM tap_funky WHERE schema = $1 and kind = 'p'
),
$3
);
$$ LANGUAGE SQL;

-- procedures_are( schema, procedures[] )
CREATE OR REPLACE FUNCTION procedures_are ( NAME, NAME[] )
RETURNS TEXT AS $$
SELECT procedures_are( $1, $2, 'Schema ' || quote_ident($1) || ' should have the correct procedures' );
$$ LANGUAGE SQL;

-- procedures_are( procedures[], description )
CREATE OR REPLACE FUNCTION procedures_are ( NAME[], TEXT )
RETURNS TEXT AS $$
SELECT _are(
'procedures',
ARRAY(
SELECT name FROM tap_funky WHERE is_visible and kind = 'p'
AND schema NOT IN ('pg_catalog', 'information_schema')
EXCEPT
SELECT $1[i]
FROM generate_series(1, array_upper($1, 1)) s(i)
),
ARRAY(
SELECT $1[i]
FROM generate_series(1, array_upper($1, 1)) s(i)
EXCEPT
SELECT name FROM tap_funky WHERE is_visible and kind = 'p'
AND schema NOT IN ('pg_catalog', 'information_schema')
),
$2
);
$$ LANGUAGE SQL;

-- procedures_are( procedures[] )
CREATE OR REPLACE FUNCTION procedures_are ( NAME[] )
RETURNS TEXT AS $$
SELECT procedures_are( $1, 'Search path ' || pg_catalog.current_setting('search_path') || ' should have the correct procedures' );
$$ LANGUAGE SQL;

-- indexes_are( schema, table, indexes[], description )
CREATE OR REPLACE FUNCTION indexes_are( NAME, NAME, NAME[], TEXT )
RETURNS TEXT AS $$
Expand Down
31 changes: 30 additions & 1 deletion test/expected/aretap.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
\unset ECHO
1..459
1..488
ok 1 - tablespaces_are(tablespaces, desc) should pass
ok 2 - tablespaces_are(tablespaces, desc) should have the proper description
ok 3 - tablespaces_are(tablespaces, desc) should have the proper diagnostics
Expand Down Expand Up @@ -459,3 +459,32 @@ ok 456 - foreign_tables_are(schema, tables) extra and missing should have the pr
ok 457 - foreign_tables_are(tables) extra and missing should fail
ok 458 - foreign_tables_are(tables) extra and missing should have the proper description
ok 459 - foreign_tables_are(tables) extra and missing should have the proper diagnostics
ok 460 - procedures_are(schema, procedures, desc) should pass
ok 461 - procedures_are(schema, procedures, desc) should have the proper description
ok 462 - procedures_are(schema, procedures, desc) should have the proper diagnostics
ok 463 - procedures_are(schema, procedures) should pass
ok 464 - procedures_are(schema, procedures) should have the proper description
ok 465 - procedures_are(schema, procedures, desc) + missing should fail
ok 466 - procedures_are(schema, procedures, desc) + missing should have the proper description
ok 467 - procedures_are(schema, procedures, desc) + missing should have the proper diagnostics
ok 468 - procedures_are(schema, procedures, desc) + extra should fail
ok 469 - procedures_are(schema, procedures, desc) + extra should have the proper description
ok 470 - procedures_are(schema, procedures, desc) + extra should have the proper diagnostics
ok 471 - procedures_are(schema, procedures, desc) + extra & missing should fail
ok 472 - procedures_are(schema, procedures, desc) + extra & missing should have the proper description
ok 473 - procedures_are(schema, procedures, desc) + extra & missing should have the proper diagnostics
ok 474 - procedures_are(procedures, desc) should pass
ok 475 - procedures_are(procedures, desc) should have the proper description
ok 476 - procedures_are(procedures, desc) should have the proper diagnostics
ok 477 - procedures_are(procedures) should pass
ok 478 - procedures_are(procedures) should have the proper description
ok 479 - procedures_are(procedures) should have the proper diagnostics
ok 480 - procedures_are(procedures, desc) + missing should fail
ok 481 - procedures_are(procedures, desc) + missing should have the proper description
ok 482 - procedures_are(procedures, desc) + missing should have the proper diagnostics
ok 483 - procedures_are(procedures, desc) + extra should fail
ok 484 - procedures_are(procedures, desc) + extra should have the proper description
ok 485 - procedures_are(procedures, desc) + extra should have the proper diagnostics
ok 486 - procedures_are(procedures, desc) + extra & missing should fail
ok 487 - procedures_are(procedures, desc) + extra & missing should have the proper description
ok 488 - procedures_are(procedures, desc) + extra & missing should have the proper diagnostics
Loading