Skip to content

Commit

Permalink
Add default_draft GUC test
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Apr 12, 2024
1 parent 3d4e430 commit 8c950c6
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 0 deletions.
112 changes: 112 additions & 0 deletions test/expected/default_draft.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
-- Make sure the DSO is loaded.
SELECT jsonschema_is_valid('{"type": "object"}'::json);
jsonschema_is_valid
---------------------
t
(1 row)

-- Should default to 2020
SELECT current_setting('jsonschema.default_draft');
current_setting
-----------------
V2020
(1 row)

SHOW jsonschema.default_draft;
jsonschema.default_draft
--------------------------
V2020
(1 row)

-- Set to 2019
SELECT set_config('jsonschema.default_draft', 'V2019', false);
set_config
------------
V2019
(1 row)

SELECT current_setting('jsonschema.default_draft');
current_setting
-----------------
V2019
(1 row)

SHOW jsonschema.default_draft;
jsonschema.default_draft
--------------------------
V2019
(1 row)

-- Set to v7
SELECT set_config('jsonschema.default_draft', 'V7', false);
set_config
------------
V7
(1 row)

SELECT current_setting('jsonschema.default_draft');
current_setting
-----------------
V7
(1 row)

SHOW jsonschema.default_draft;
jsonschema.default_draft
--------------------------
V7
(1 row)

-- Set to v6
SELECT set_config('jsonschema.default_draft', 'V6', false);
set_config
------------
V6
(1 row)

SELECT current_setting('jsonschema.default_draft');
current_setting
-----------------
V6
(1 row)

SHOW jsonschema.default_draft;
jsonschema.default_draft
--------------------------
V6
(1 row)

-- Set to v4
SELECT set_config('jsonschema.default_draft', 'V4', false);
set_config
------------
V4
(1 row)

SELECT current_setting('jsonschema.default_draft');
current_setting
-----------------
V4
(1 row)

SHOW jsonschema.default_draft;
jsonschema.default_draft
--------------------------
V4
(1 row)

-- Set to invalid value
SELECT set_config('jsonschema.default_draft', 'Nope', false);
ERROR: invalid value for parameter "jsonschema.default_draft": "Nope"
HINT: Available values: V4, V6, V7, V2019, V2020.
SELECT current_setting('jsonschema.default_draft');
current_setting
-----------------
V4
(1 row)

SHOW jsonschema.default_draft;
jsonschema.default_draft
--------------------------
V4
(1 row)

31 changes: 31 additions & 0 deletions test/sql/default_draft.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Make sure the DSO is loaded.
SELECT jsonschema_is_valid('{"type": "object"}'::json);

-- Should default to 2020
SELECT current_setting('jsonschema.default_draft');
SHOW jsonschema.default_draft;

-- Set to 2019
SELECT set_config('jsonschema.default_draft', 'V2019', false);
SELECT current_setting('jsonschema.default_draft');
SHOW jsonschema.default_draft;

-- Set to v7
SELECT set_config('jsonschema.default_draft', 'V7', false);
SELECT current_setting('jsonschema.default_draft');
SHOW jsonschema.default_draft;

-- Set to v6
SELECT set_config('jsonschema.default_draft', 'V6', false);
SELECT current_setting('jsonschema.default_draft');
SHOW jsonschema.default_draft;

-- Set to v4
SELECT set_config('jsonschema.default_draft', 'V4', false);
SELECT current_setting('jsonschema.default_draft');
SHOW jsonschema.default_draft;

-- Set to invalid value
SELECT set_config('jsonschema.default_draft', 'Nope', false);
SELECT current_setting('jsonschema.default_draft');
SHOW jsonschema.default_draft;

0 comments on commit 8c950c6

Please sign in to comment.