Skip to content

Commit

Permalink
Test and document proc with function assertions
Browse files Browse the repository at this point in the history
Add tests for all of the function assertion test functions to ensure
that they also work as expected with procedures. Document that support
where appropriate. Closes #329.
  • Loading branch information
theory committed Feb 3, 2024
1 parent 1ace153 commit 92495a7
Show file tree
Hide file tree
Showing 5 changed files with 1,372 additions and 979 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Revision history for pgTAP
without aliasing. Thanks to @spencerbryson for the report (#328) and to
Erik Wienhold for the PL/pgSQL technique necessary to properly format
type strings (#315).
* Added tests to ensure that that the function-testing assertions also support
procedures and noted the fact where appropriate in the documentation.
Thanks to @hettie-d for the call-out (#329)!

1.3.1 2023-09-24T15:29:42Z
--------------------------
Expand Down
44 changes: 24 additions & 20 deletions doc/pgtap.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -2255,16 +2255,16 @@ missing triggers, like so:
: Name of a schema in which to find functions.

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

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

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 is
omitted, a generally useful default description will be generated. Example:
This function tests that all of the functions or procedures 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
is omitted, a generally useful default description will be generated. Example:

SELECT functions_are(
'myschema',
Expand Down Expand Up @@ -3727,19 +3727,19 @@ rule does *not* exist.
: Name of a schema in which to find the function.

`:function`
: Name of a function.
: Name of a function or procedure.

`:args`
: Array of data types of the function arguments.

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

Checks to be sure that the given function exists in the named schema and with
the specified argument data types. If `:schema` is omitted, `has_function()`
will search for the function in the schemas defined in the search path. If
`:args` is omitted, `has_function()` will see if the function exists without
regard to its arguments. Some examples:
Checks to be sure that the given function or procedure exists in the named
schema and with the specified argument data types. If `:schema` is omitted,
`has_function()` will search for the function in the schemas defined in the
search path. If `:args` is omitted, `has_function()` will see if the function
exists without regard to its arguments. Some examples:

SELECT has_function(
'pg_catalog',
Expand Down Expand Up @@ -3784,7 +3784,7 @@ future version of pgTAP.
: Name of a schema in which not to find the function.

`:function`
: Name of a function.
: Name of a function or procedure.

`:args`
: Array of data types of the function arguments.
Expand All @@ -3793,7 +3793,8 @@ future version of pgTAP.
: A short description of the test.

This function is the inverse of `has_function()`. The test passes if the
specified function (optionally with the specified signature) does *not* exist.
specified function or procedure (optionally with the specified signature) does
*not* exist.

### `has_cast()` ###

Expand Down Expand Up @@ -5349,7 +5350,7 @@ future.
: Schema in which to find the functions.

`:functions`
: Array of function names.
: Array of function and/or procedure names.

`:description`
: A short description of the test.
Expand Down Expand Up @@ -5474,6 +5475,10 @@ signature will be checked (pass an empty array to specify a function with an
empty signature). If the `:description` is omitted, a reasonable substitute
will be created.

Procedures can also be tested; they always return `void`:

SELECT function_returns( 'my_proc', 'void' );

In the event of a failure, you'll useful diagnostics will tell you what went
wrong, for example:

Expand Down Expand Up @@ -5505,15 +5510,15 @@ But then you check with `has_function()` first, right?
: Schema in which to find the function.

`:function`
: Function name.
: Function or proceudure name.

`:args`
: Array of data types for the function arguments.

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

Tests that a function is a security definer (i.e., a "setuid" function). If
Tests that a function or procedure is a security definer (i.e., a "setuid" function). If
the `:schema` argument is omitted, then the function must be visible in the
search path. If the `:args` argument is passed, then the function with that
argument signature will be the one tested; otherwise, a function with any
Expand Down Expand Up @@ -5550,17 +5555,16 @@ But then you check with `has_function()` first, right?
: Schema in which to find the function.

`:function`
: Function name.
: Function or proceure name.

`:args`
: Array of data types for the function arguments.

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


This function is the inverse of `is_definer()`. The test passes if the specified
function is not a security definer.
function or procedure is not a security definer.

If the function does not exist, a handy diagnostic message will let you know:

Expand Down
Loading

0 comments on commit 92495a7

Please sign in to comment.