Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the objects created by the extension #14

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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; ' $< > $@
Expand Down
3 changes: 2 additions & 1 deletion sql/function-status.sql
Original file line number Diff line number Diff line change
@@ -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 @[email protected]_status()
RETURNS text
Expand Down
3 changes: 1 addition & 2 deletions sql/management.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ BEGIN
excluded AS (
SELECT c.oid
FROM pg_class c
JOIN @[email protected]_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 @[email protected]_table_exclusion ste ON ste.table_name = c.relname)
),
internals AS (
SELECT oid FROM excluded
Expand Down
10 changes: 4 additions & 6 deletions sql/table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ CREATE TABLE @[email protected]_column_log (
created_at timestamp with time zone DEFAULT current_timestamp
);
--
--
-- List the table to exclude
--
CREATE TABLE @[email protected]_table_exclusion (
schema_name name,
Expand All @@ -56,7 +56,9 @@ CREATE TABLE @[email protected]_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 @[email protected]_table_exclusion_templates (
schema_name name,
table_name name,
Expand All @@ -65,7 +67,3 @@ CREATE TABLE @[email protected]_table_exclusion_templates (
created_by text DEFAULT current_user,
PRIMARY KEY (schema_name, table_name)
);

--
--
--
6 changes: 4 additions & 2 deletions test/sql/function-status_test.sql.in
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 3 additions & 2 deletions test/sql/function-stop_test.sql.in
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 11 additions & 3 deletions test/sql/function_test.sql.in
Original file line number Diff line number Diff line change
@@ -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;
49 changes: 49 additions & 0 deletions test/sql/main_test.sql.in
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 1 addition & 3 deletions test/sql/management_test.sql.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--
--
-- Test management functions
--
SET search_path=public,pgtap,_TEST_SCHEMA_;

Expand All @@ -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],
Expand Down Expand Up @@ -67,5 +66,4 @@ SELECT results_eq(

SELECT finish();


ROLLBACK;
16 changes: 15 additions & 1 deletion test/sql/table_test.sql.in
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
Loading