pgtap icon indicating copy to clipboard operation
pgtap copied to clipboard

trigger_is(): allow testing function arguments

Open decibel opened this issue 9 years ago • 7 comments

It'd be good if we could verify the arguments (or at least number of arguments) being passed to a trigger function by a specific trigger. According to [1], The arguments are concatinated together as NUL terminated strings in pg_trigger.tgargs.

1: http://www.postgresql.org/docs/devel/static/catalog-pg-trigger.html

decibel avatar May 08 '15 23:05 decibel

Actually trigger_is is defined as is :

SELECT trigger_is( :schema, :table, :trigger, :func_schema, :function, :description );
SELECT trigger_is( :schema, :table, :trigger, :func_schema, :function );
SELECT trigger_is( :table, :trigger, :function, :description );
SELECT trigger_is( :table, :trigger, :function );

What about adding these functions to detect the number of argument ?

SELECT trigger_is( :schema, :table, :trigger, :func_schema, :function, nbargs, :description );
SELECT trigger_is( :schema, :table, :trigger, :func_schema, :function, nbargs );
SELECT trigger_is( :table, :trigger, :function, :description, nbargs );
SELECT trigger_is( :table, :trigger, :function, nbargs );

rodo avatar Jun 28 '16 20:06 rodo

That would be better than nothing.

Another option would be to use the trigger definition parsing code I wrote for cat_tools.

decibel avatar Jun 29 '16 20:06 decibel

I'll have a look at your function, as your code is under MIT License too it's possible to use it in pgtap, it's better to keep pgtap with less dependencies as possible.

rodo avatar Jun 29 '16 21:06 rodo

Jesus, trigger parsing code? In PL/pgSQL? o_O

theory avatar Jun 29 '16 22:06 theory

Well, I wanted it to be portable... It's not quite as bad as you might think.

If we didn't care about portable then I think the best way to handle this would be a C function that calls (or duplicates) the appropriate bits of backend code. I don't think that some other PL language buys us much over the plpgsql, and the C code means nothing's actually being parsed.

decibel avatar Jun 29 '16 22:06 decibel

I'm sure it's no worse than some of the crazy shit PL/pgSQL already does, like trying to distinguish a string that executes a prepared statement from any other query. Fine with me to integrate that code if you're willing to contribute it, @decibel.

theory avatar Jun 30 '16 11:06 theory

It's MIT license, so have at it.

decibel avatar Jun 30 '16 20:06 decibel