Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rodo committed Dec 12, 2024
1 parent 6cf60bd commit 7f3f37e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 90 deletions.
35 changes: 14 additions & 21 deletions test/create_column.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
77 changes: 8 additions & 69 deletions test/integration_tests.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,35 @@ 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');
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
Expand All @@ -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'
);
--
--
--
Expand Down

0 comments on commit 7f3f37e

Please sign in to comment.