Open AWolf81 opened 5 months ago
This seems like it would be a useful function to complement triggers_are()
, has_trigger()
, and trigger_is()
. Name it something like trigger_events_are()
, which I think fits better with pgTAP's naming conventions (e.g., all the _privs_are()
functions). Would also need a variant that takes the schema name. I suspect the signatures would be:
SELECT trigger_events_are ( :schema, :table, :events, :description );
SELECT trigger_events_are ( :schema, :table, :events );
SELECT trigger_events_are ( :table, :events, :description );
SELECT trigger_events_are ( :table, :events );
To add those functions to the project, append them to sql/pgtap.sql.in
and to sql/pgtap--1.3.3--1.3.4.sql
and put the tests in test/sql/trigger.sql
.
@theory thanks for the advice how to add this.
Yes, you're right, naming trigger_events_are
is better.
I'll create a PR once I have this ready.
At the moment, I'm not sure why my tests are failing. I have to check this. Or do you have an idea what I'm doing wrong? Maybe I have to run the tests with a differnt command?
If I'm running make installcheck
I'm getting the following output:
... other tests are passing
ruletap ... ok 17680 ms
resultset ... ok 8918 ms
util ... ok 2125 ms
policy ... ok 4164 ms
trigger ... FAILED 3666 ms
istap ... ok 2536 ms
=======================
1 of 39 tests failed.
=======================
The differences that caused some tests to fail can be viewed in the
file "/home/alexander/awolf81-fork-pgtap/regression.diffs". A copy of the test summary that you see
above is saved in the file "/home/alexander/awolf81-fork-pgtap/regression.out".
make: *** [/usr/lib/postgresql/12/lib/pgxs/src/makefiles/pgxs.mk:420: installcheck] Error 1
And the regression.diffs
looks like this:
diff -U3 /home/alexander/awolf81-fork-pgtap/test/expected/trigger.out /home/alexander/awolf81-fork-pgtap/results/trigger.out
--- /home/alexander/awolf81-fork-pgtap/test/expected/trigger.out 2024-05-12 21:58:18.365706798 +0200
+++ /home/alexander/awolf81-fork-pgtap/results/trigger.out 2024-05-12 23:56:58.417688814 +0200
@@ -1,5 +1,5 @@
\unset ECHO
-1..84
+1..97
ok 1 - has_trigger(schema, table, trigger, desc) should pass
ok 2 - has_trigger(schema, table, trigger, desc) should have the proper description
ok 3 - has_trigger(schema, table, trigger, desc) should have the proper diagnostics
@@ -84,3 +84,16 @@
ok 82 - triggers_are(table, triggers) + extra & missing should fail
ok 83 - triggers_are(table, triggers) + extra & missing should have the proper description
ok 84 - triggers_are(table, triggers) + extra & missing should have the proper diagnostics
+ok 85 - trigger_events_are(table, trigger, events, desc) should pass
+ok 86 - trigger_events_are(table, trigger, events, desc) + extra should fail
+ok 87 - trigger_events_are(table, trigger, events, desc) + extra should have the proper description
+ok 88 - trigger_events_are(table, trigger, events, desc) + extra should have the proper diagnostics
+ok 89 - trigger_events_are(table, trigger, events, desc) should fail
+ok 90 - trigger_events_are(table, trigger, events, desc) should have the proper description
+ok 91 - trigger_events_are(table, trigger, events, desc) should have the proper diagnostics
+ok 92 - trigger_events_are(table, trigger, events, desc) + extra & missing should fail
+ok 93 - trigger_events_are(table, trigger, events, desc) + extra & missing should have the proper description
+ok 94 - trigger_events_are(table, trigger, events, desc) + extra & missing should have the proper diagnostics
+ok 95 - trigger_events_are(table, non_existent_trigger, events, desc) should fail
+ok 96 - trigger_events_are(non_existent_table, trigger, events, desc) should fail
+ok 97 - trigger_events_are(table, trigger, ARRAY[], desc) should fail
Running the trigger.sql
with pg_prove
like following is working:
pg_prove -d regression test/sql/trigger.sql
test/sql/trigger.sql .. ok
All tests successful.
Files=1, Tests=97, 1 wallclock secs ( 0.19 usr 0.03 sys + 0.35 cusr 0.17 csys = 0.74 CPU)
Result: PASS
Yeah you added new tests so you have to update test/expected/trigger.out
. This should fix it:
cp results/trigger.out test/expected/trigger.out
Sorry for the delayed reply, was completely absorbed in writing a couple conference presentations for the last few weeks.
I'm pretty new to pgTAP but I think there is no easy way to check if a trigger event is avaliable at a given table.
rules_are
is similar but that's not working for triggers.The line in question of a schema that the function will test is marked in the below example definition:
CREATE TRIGGER test_trigger AFTER INSERT OR UPDATE ON test_table FOR EACH ROW EXECUTE FUNCTION test_trigger_function();
So the idea is to add a
has_trigger_events
function.I think the following code is exactly implementing that function:
I haven't checked how to add it to pgTAP but if there is a guide on how to contribute, I could create a PR if this feature is interesting for pgTAP.
If this function is not interesting, that's also no problem.
The tests above are covering all cases.
Topics not covered in the function
has_trigger_events
, would be possible but makes thehas_trigger_events
usage more complicated. Maybe this would be better to add as additional test function.FOR EACH ROW
not covered inhas_trigger_events
- would be better in a separatehas_trigger_definition
functionhasnt_trigger_events
not added yet - is it needed? How to add without duplicating thehas_trigger_events
logic e.g. refactor/rename tocheck_trigger_events
and add an arg.p_check_presence
to check has or hasn't based on it.The mentioned missing parts would be nice to have but I think they're all optional.