Skip to content

Commit

Permalink
Add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rodo committed Dec 18, 2024
1 parent d20b675 commit 8b1524f
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 19 deletions.
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
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;
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

0 comments on commit 8b1524f

Please sign in to comment.