From 7f3f37e526a1119f71ee55787bfc5b0a92418129 Mon Sep 17 00:00:00 2001 From: Rodolphe Quiedeville Date: Thu, 12 Dec 2024 12:08:23 +0100 Subject: [PATCH] Fix tests --- test/create_column.sql | 35 +++++++---------- test/integration_tests.sql | 77 ++++---------------------------------- 2 files changed, 22 insertions(+), 90 deletions(-) diff --git a/test/create_column.sql b/test/create_column.sql index d18b3dc..5b1d9eb 100644 --- a/test/create_column.sql +++ b/test/create_column.sql @@ -9,45 +9,38 @@ DROP EXTENSION IF EXISTS schedoc CASCADE; CREATE EXTENSION schedoc CASCADE; SELECT schedoc_start(); -SELECT plan(4); +SELECT plan(3); -TRUNCATE ddl_history; +TRUNCATE schedoc_column_raw; -- 2 CREATE TABLE schedoc_unit_t (id int); -DROP EXTENSION IF EXISTS schedoc CASCADE; -CREATE EXTENSION schedoc CASCADE; - - --- create some objects non concerned by the extension -ALTER TABLE schedoc_unit_t ADD COLUMN toto int; -CREATE INDEX ON schedoc_unit_t (toto); - --- -TRUNCATE ddl_history; COMMENT ON COLUMN schedoc_unit_t.id IS '{"status": "private"}'; +-- 1 row for the column id created during the CREATE TABLE +-- 1 row for the column toto created with THE ALTER -- -SELECT results_eq( - 'SELECT count(*) FROM ddl_history', - 'SELECT CAST(1 as bigint)', - 'We have 1 row in ddl_history'); - SELECT results_eq( 'SELECT count(*) FROM schedoc_column_raw', 'SELECT CAST(1 as bigint)', 'We have 1 row in schedoc_column_raw'); +-- SELECT results_eq( - 'SELECT comment,status::text FROM schedoc_column_raw LIMIT 1', + 'SELECT comment,status::text FROM schedoc_column_raw', 'SELECT ''{"status": "private"}''::jsonb, ''private''::text ', 'We have right values in schedoc_column_raw'); +-- add a column +ALTER TABLE schedoc_unit_t ADD COLUMN toto int; + +-- 1 row for the column id created during the CREATE TABLE +-- 1 row for the column toto created with THE ALTER SELECT results_eq( - 'SELECT status::text FROM schedoc_column_raw', - 'SELECT ''private''::text ', - 'We have right values in schedoc_column_comments'); + 'SELECT count(*) FROM schedoc_column_raw', + 'SELECT CAST(2 as bigint)', + 'We have 2 rows in schedoc_column_raw'); ROLLBACK; diff --git a/test/integration_tests.sql b/test/integration_tests.sql index bc39c03..a531359 100644 --- a/test/integration_tests.sql +++ b/test/integration_tests.sql @@ -6,15 +6,14 @@ SET search_path=public,pgtap; BEGIN; -SELECT plan(11); - -TRUNCATE ddl_history; +SELECT plan(5); DROP EXTENSION IF EXISTS schedoc CASCADE; CREATE EXTENSION schedoc CASCADE; SELECT schedoc_start(); --- 2 -CREATE TABLE foobar_schedoc (id int); + +TRUNCATE schedoc_column_raw; +TRUNCATE ddl_history; -- add test on schema to fail fast SELECT has_extension('schedoc'); @@ -22,34 +21,20 @@ SELECT has_table('schedoc_column_raw'); SELECT has_view('schedoc_column_comments'); -- create some objects non concerned by the extension +CREATE TABLE foobar_schedoc (id int); ALTER TABLE foobar_schedoc ADD COLUMN toto int; CREATE INDEX ON foobar_schedoc (toto); -- -TRUNCATE schedoc_column_raw; + COMMENT ON COLUMN foobar_schedoc.id IS '{"status": "private"}'; -- -SELECT results_eq( - 'SELECT count(*) FROM ddl_history', - 'SELECT CAST(1 as bigint)', - 'We have 1 rows in ddl_history'); SELECT results_eq( 'SELECT count(*) FROM schedoc_column_raw', - 'SELECT CAST(1 as bigint)', - 'We have 1 row in schedoc_column_raw'); - -SELECT results_eq( - 'SELECT comment,status::text FROM schedoc_column_raw LIMIT 1', - 'SELECT ''{"status": "private"}''::jsonb, ''private''::text ', - 'We have right values in schedoc_column_raw'); - - -SELECT results_eq( - 'SELECT status::text FROM schedoc_column_raw', - 'SELECT ''private''::text ', - 'We have right values in schedoc_column_comments'); + 'SELECT CAST(2 as bigint)', + 'We have 2 row in schedoc_column_raw'); -- -- The comment contains unauthorized value on status key @@ -63,52 +48,6 @@ BEGIN END; $EOF$; -PREPARE unauthorized_value AS SELECT * FROM setcomm_unauthorized_value(); -SELECT throws_ok( - 'unauthorized_value', - '22P02', - 'invalid input value for enum schedoc_status: "foobar"', - 'We should get an input value error' -); --- --- The comment is not in JSONB format --- -CREATE OR REPLACE FUNCTION setcomm_wrong_format() -RETURNS void - LANGUAGE plpgsql AS -$EOF$ -BEGIN - COMMENT ON COLUMN foobar_schedoc.id IS 'This is not a JSON'; -END; -$EOF$; - -PREPARE wrong_format AS SELECT * FROM setcomm_wrong_format(); -SELECT throws_ok( - 'wrong_format', - '22P02', - 'invalid input syntax for type json', - 'We should get an input syntax error' -); - --- --- The comment is not in JSONB format --- -CREATE OR REPLACE FUNCTION setcomm_wrong_format_b() -RETURNS void - LANGUAGE plpgsql AS -$EOF$ -BEGIN - COMMENT ON COLUMN foobar_schedoc.id IS '{"this":"is json"}'; -END; -$EOF$; - -PREPARE wrong_format_b AS SELECT * FROM setcomm_wrong_format_b(); -SELECT throws_ok( - 'wrong_format_b', - '22P02', - 'invalid input syntax for type json', - 'We should get an input syntax error' -); -- -- --