diff --git a/Makefile b/Makefile index 16b307a..747a8d8 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ exclude.sql: $(TOOLSEXC) cat $(TOOLSEXC) > exclude.sql test: $(UNITTESTS) $(INTETESTS) - pg_prove -f test/sql/*.sql + pg_prove -vf test/sql/*.sql test/sql/%.sql: test/sql/%.sql.in sed 's,_TEST_SCHEMA_,$(TEST_SCHEMA),g; ' $< > $@ diff --git a/sql/function-status.sql b/sql/function-status.sql index 107ad9a..ae15bd7 100644 --- a/sql/function-status.sql +++ b/sql/function-status.sql @@ -1,5 +1,6 @@ -- --- Remove the triggers and the functions to stop the process +-- Return the information if the extension is started or not. +-- If not started the has no action -- CREATE OR REPLACE FUNCTION @extschema@.schedoc_status() RETURNS text diff --git a/sql/management.sql b/sql/management.sql index 617f682..4a0bb01 100644 --- a/sql/management.sql +++ b/sql/management.sql @@ -58,8 +58,7 @@ BEGIN excluded AS ( SELECT c.oid FROM pg_class c - JOIN @extschema@.schedoc_table_exclusion ste ON ste.table_name = c.relname - JOIN pg_namespace n ON (n.oid = c.relnamespace AND n.nspname = ste.schema_name) + JOIN @extschema@.schedoc_table_exclusion ste ON ste.table_name = c.relname) ), internals AS ( SELECT oid FROM excluded diff --git a/sql/table.sql b/sql/table.sql index c855678..df8d345 100644 --- a/sql/table.sql +++ b/sql/table.sql @@ -46,7 +46,7 @@ CREATE TABLE @extschema@.schedoc_column_log ( created_at timestamp with time zone DEFAULT current_timestamp ); -- --- +-- List the table to exclude -- CREATE TABLE @extschema@.schedoc_table_exclusion ( schema_name name, @@ -56,7 +56,9 @@ CREATE TABLE @extschema@.schedoc_table_exclusion ( created_by text DEFAULT current_user, PRIMARY KEY (schema_name, table_name) ); - +-- +-- Collection of table names related to specific tools identified by tag +-- CREATE TABLE @extschema@.schedoc_table_exclusion_templates ( schema_name name, table_name name, @@ -65,7 +67,3 @@ CREATE TABLE @extschema@.schedoc_table_exclusion_templates ( created_by text DEFAULT current_user, PRIMARY KEY (schema_name, table_name) ); - --- --- --- diff --git a/test/sql/function-status_test.sql.in b/test/sql/function-status_test.sql.in index d864841..107c190 100644 --- a/test/sql/function-status_test.sql.in +++ b/test/sql/function-status_test.sql.in @@ -1,14 +1,16 @@ -- --- We assume that ddl_historization is installed in public schema +-- Test the function schedoc_status -- SET search_path=public,pgtap; BEGIN; -SELECT plan(2); +SELECT plan(3); SELECT has_extension('schedoc'); SELECT has_function('_TEST_SCHEMA_'::name, 'schedoc_status'::name); +SELECT function_returns('_TEST_SCHEMA_'::name, 'schedoc_status'::name, 'text'); + ROLLBACK; diff --git a/test/sql/function-stop_test.sql.in b/test/sql/function-stop_test.sql.in index 795b542..b774ee0 100644 --- a/test/sql/function-stop_test.sql.in +++ b/test/sql/function-stop_test.sql.in @@ -1,16 +1,17 @@ -- --- We assume that ddl_historization is installed in public schema +-- Test the function schedoc_stop -- SET search_path=public,pgtap; BEGIN; -SELECT plan(2); +SELECT plan(3); SELECT has_extension('schedoc'); SELECT has_function('_TEST_SCHEMA_'::name, 'schedoc_stop'::name); +SELECT function_returns('_TEST_SCHEMA_'::name, 'schedoc_stop'::name, 'void'); ROLLBACK; diff --git a/test/sql/function_test.sql.in b/test/sql/function_test.sql.in index 77dfa97..edc6597 100644 --- a/test/sql/function_test.sql.in +++ b/test/sql/function_test.sql.in @@ -1,18 +1,26 @@ -- --- We assume that ddl_historization is installed in public schema +-- Test functions -- SET search_path=public,pgtap; BEGIN; -SELECT plan(5); +SELECT plan(9); SELECT has_extension('schedoc'); SELECT has_function('_TEST_SCHEMA_'::name, 'schedoc_start'::name); -SELECT has_function('_TEST_SCHEMA_'::name, 'schedoc_fill_raw'::name); +SELECT function_returns('_TEST_SCHEMA_'::name, 'schedoc_start'::name, 'void'); + +SELECT has_function('_TEST_SCHEMA_'::name, 'schedoc_fill_raw'::name, ARRAY['oid', 'oid']); +SELECT function_returns('_TEST_SCHEMA_'::name, 'schedoc_fill_raw'::name, ARRAY['oid', 'oid'], 'void'); + + SELECT has_function('_TEST_SCHEMA_'::name, 'schedoc_get_column_description'::name, ARRAY['oid', 'oid']); +SELECT function_returns('_TEST_SCHEMA_'::name, 'schedoc_get_column_description'::name, ARRAY['oid', 'oid'], 'text'); + SELECT has_function('_TEST_SCHEMA_'::name, 'schedoc_get_column_status'::name, ARRAY['oid', 'oid']); +SELECT function_returns('_TEST_SCHEMA_'::name, 'schedoc_get_column_status'::name, ARRAY['oid', 'oid'], 'text'); ROLLBACK; diff --git a/test/sql/main_test.sql.in b/test/sql/main_test.sql.in new file mode 100644 index 0000000..dec3ac1 --- /dev/null +++ b/test/sql/main_test.sql.in @@ -0,0 +1,49 @@ +-- +-- +-- +-- SELECT e.extname, ne.nspname AS extschema, p.proname, np.nspname AS proschema +-- FROM pg_catalog.pg_extension AS e +-- INNER JOIN pg_catalog.pg_depend AS d ON (d.refobjid = e.oid) +-- INNER JOIN pg_catalog.pg_proc AS p ON (p.oid = d.objid) +-- INNER JOIN pg_catalog.pg_namespace AS ne ON (ne.oid = e.extnamespace) +-- INNER JOIN pg_catalog.pg_namespace AS np ON (np.oid = p.pronamespace) +-- WHERE d.deptype = 'e' +-- ORDER BY 1, 3 +DEALLOCATE PREPARE ALL; +SET search_path=public,pgtap; + +BEGIN; + +SELECT plan(2); + +PREPARE count_functions AS +SELECT count(p.proname)::int +FROM pg_catalog.pg_extension AS e + INNER JOIN pg_catalog.pg_depend AS d ON (d.refobjid = e.oid) + INNER JOIN pg_catalog.pg_proc AS p ON (p.oid = d.objid) +WHERE d.deptype = 'e' AND extname = 'schedoc'; + + +SELECT results_eq( + 'count_functions', + $$VALUES (10)$$, + 'We have the right number of functions'); + +-- +-- Tables +-- +PREPARE count_tables AS +SELECT count(e.extname)::int +FROM pg_catalog.pg_extension AS e + INNER JOIN pg_catalog.pg_depend AS d ON (d.refobjid = e.oid) + INNER JOIN pg_catalog.pg_class AS p ON (p.oid = d.objid) +WHERE d.deptype = 'e' AND e.extname = 'schedoc' AND p.relkind='r'; + +SELECT results_eq( + 'count_tables', + $$VALUES (6)$$, + 'We have the right number of functions'); + +SELECT finish(); + +ROLLBACK; diff --git a/test/sql/management_test.sql.in b/test/sql/management_test.sql.in index a7618ca..0273613 100644 --- a/test/sql/management_test.sql.in +++ b/test/sql/management_test.sql.in @@ -1,5 +1,5 @@ -- --- +-- Test management functions -- SET search_path=public,pgtap,_TEST_SCHEMA_; @@ -19,7 +19,6 @@ SELECT results_eq( ARRAY['False'::boolean], 'Return False on non existing id'); - SELECT results_eq( 'SELECT schedoc_is_table_excluded(oid) FROM pg_class WHERE relname=''ddl_history''', ARRAY['True'::boolean], @@ -67,5 +66,4 @@ SELECT results_eq( SELECT finish(); - ROLLBACK; diff --git a/test/sql/table_test.sql.in b/test/sql/table_test.sql.in index 9125ff0..be11a45 100644 --- a/test/sql/table_test.sql.in +++ b/test/sql/table_test.sql.in @@ -5,20 +5,34 @@ SET search_path=public,pgtap; BEGIN; -SELECT plan(8); +SELECT plan(13); SELECT has_table('_TEST_SCHEMA_'::name, 'schedoc_column_raw'::name); SELECT has_table('_TEST_SCHEMA_'::name, 'schedoc_valid'::name); +SELECT columns_are('_TEST_SCHEMA_'::name, 'schedoc_valid'::name, ARRAY['status']); SELECT has_table('_TEST_SCHEMA_'::name, 'schedoc_valid_status'::name); +SELECT columns_are('_TEST_SCHEMA_'::name, 'schedoc_valid_status'::name, ARRAY['status']); +-- SELECT has_table('_TEST_SCHEMA_'::name, 'schedoc_column_log'::name); +SELECT columns_are('_TEST_SCHEMA_'::name, 'schedoc_column_log'::name, + ARRAY['objoid', 'objsubid', 'comment', 'is_valid', 'created_at']); + +-- +-- SELECT has_table('_TEST_SCHEMA_'::name, 'schedoc_table_exclusion'::name); +SELECT columns_are('_TEST_SCHEMA_'::name, 'schedoc_table_exclusion'::name, + ARRAY['schema_name', 'table_name', 'tag', 'created_at', 'created_by']); SELECT has_table('_TEST_SCHEMA_'::name, 'schedoc_table_exclusion_templates'::name); +SELECT columns_are('_TEST_SCHEMA_'::name, 'schedoc_table_exclusion_templates'::name, + ARRAY['schema_name', 'table_name', 'tags', 'created_at', 'created_by']); +-- +-- SELECT has_enum('_TEST_SCHEMA_'::name, 'schedoc_status'::name); SELECT enum_has_labels('_TEST_SCHEMA_'::name, 'schedoc_status'::name, ARRAY['public', 'private', 'legacy', 'wip']);