Add PgTAP unit test for procedure

SQL pattern

PgTAP is a unit testing framework for Postgres. This pattern adds a unit test checking a procedure has been correctly defined.


Apply with the Grit CLI
grit apply add_pg_unit_test

Basic procedure

BEFORE
CREATE PROCEDURE remove_emp(employee_id int) AS
   tot_emps int;
   BEGIN
      DELETE FROM employees
      WHERE employees.employee_id = remove_emp.employee_id;
   tot_emps := tot_emps - 1;
   END;
AFTER
CREATE PROCEDURE remove_emp(employee_id int) AS
   tot_emps int;
   BEGIN
      DELETE FROM employees
      WHERE employees.employee_id = remove_emp.employee_id;
   tot_emps := tot_emps - 1;
   END;


-- Check that 'remove_emp' has been translated into valid plpgsql
SELECT has_function('remove_emp');
SELECT is_procedure('remove_emp');
SELECT function_lang_is('remove_emp', 'pgplsql' );