pgtap
pgtap copied to clipboard
trigger_is(): allow testing function arguments
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
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 );
That would be better than nothing.
Another option would be to use the trigger definition parsing code I wrote for cat_tools.
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.
Jesus, trigger parsing code? In PL/pgSQL? o_O
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.
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.
It's MIT license, so have at it.