Skip to content

Commit

Permalink
test: the regression test queries now run faster
Browse files Browse the repository at this point in the history
It doesn't call the main function that generates the OpenAPI spec directly anymore.
It saves the output in a table and the tests will query that table instead (via a function).
  • Loading branch information
laurenceisla authored and steve-chavez committed Oct 19, 2024
1 parent 4ffebaa commit b6161a0
Show file tree
Hide file tree
Showing 15 changed files with 410 additions and 384 deletions.
12 changes: 6 additions & 6 deletions test/expected/info.out
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
-- shows the first line of the comment on the schema as title
select jsonb_pretty(postgrest_openapi_spec('{test}')->'info'->'title');
select jsonb_pretty(get_openapi_document('{test}')->'info'->'title');
jsonb_pretty
----------------
"My API title"
(1 row)

-- shows the second line of the comment on the schema as summary
select jsonb_pretty(postgrest_openapi_spec('{test}')->'info'->'summary');
select jsonb_pretty(get_openapi_document('{test}')->'info'->'summary');
jsonb_pretty
------------------
"My API summary"
(1 row)

-- shows the third line of the comment on the schema as description
select jsonb_pretty(postgrest_openapi_spec('{test}')->'info'->'description');
select jsonb_pretty(get_openapi_document('{test}')->'info'->'description');
jsonb_pretty
--------------------------------------------------
"My API description\nthat spans\nmultiple lines"
(1 row)

-- shows default title when there is no comment on the schema
select jsonb_pretty(postgrest_openapi_spec('{types}')->'info'->'title');
select jsonb_pretty(get_openapi_document('{types}')->'info'->'title');
jsonb_pretty
-----------------
"PostgREST API"
(1 row)

-- shows no summary when there is no comment on the schema
select postgrest_openapi_spec('{types}')->'info' ? 'summary';
select get_openapi_document('{types}')->'info' ? 'summary';
?column?
----------
f
(1 row)


-- shows default description when there is no comment on the schema
select jsonb_pretty(postgrest_openapi_spec('{types}')->'info'->'description');
select jsonb_pretty(get_openapi_document('{types}')->'info'->'description');
jsonb_pretty
------------------------------------------------
"This is a dynamic API generated by PostgREST"
Expand Down
14 changes: 7 additions & 7 deletions test/expected/parameters.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- shows common query parameters
select *
from jsonb_each(postgrest_openapi_spec('{test}')->'components'->'parameters')
from jsonb_each(get_openapi_document('{test}')->'components'->'parameters')
where key in ('select', 'order', 'limit', 'offset', 'on_conflict', 'columns', 'or', 'and', 'not.or', 'not.and');
key | value
-------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -18,7 +18,7 @@ where key in ('select', 'order', 'limit', 'offset', 'on_conflict', 'columns', 'o

-- shows common headers
select key, jsonb_pretty(value)
from jsonb_each(postgrest_openapi_spec('{test}')->'components'->'parameters')
from jsonb_each(get_openapi_document('{test}')->'components'->'parameters')
where key in ('preferGet', 'preferPost', 'preferPut', 'preferPatch', 'preferDelete', 'preferPostRpc', 'range');
key | jsonb_pretty
---------------+------------------------------------------------------------------------------
Expand Down Expand Up @@ -283,7 +283,7 @@ where key in ('preferGet', 'preferPost', 'preferPut', 'preferPatch', 'preferDele

-- shows table columns as parameters
select key, jsonb_pretty(value)
from jsonb_each(postgrest_openapi_spec('{test}')->'components'->'parameters')
from jsonb_each(get_openapi_document('{test}')->'components'->'parameters')
where key like 'rowFilter.products.%';
key | jsonb_pretty
--------------------------------+----------------------------
Expand Down Expand Up @@ -333,7 +333,7 @@ where key like 'rowFilter.products.%';

-- shows view columns as parameters
select key, jsonb_pretty(value)
from jsonb_each(postgrest_openapi_spec('{test}')->'components'->'parameters')
from jsonb_each(get_openapi_document('{test}')->'components'->'parameters')
where key like 'rowFilter.big_products.%';
key | jsonb_pretty
-----------------------------+--------------------------
Expand Down Expand Up @@ -369,7 +369,7 @@ where key like 'rowFilter.big_products.%';

-- shows `IN` function arguments as RPC parameters
select key, jsonb_pretty(value)
from jsonb_each(postgrest_openapi_spec('{test}')->'components'->'parameters')
from jsonb_each(get_openapi_document('{test}')->'components'->'parameters')
where key like 'rpcParam.has_in_parameters.%';
key | jsonb_pretty
------------------------------+-----------------------------------------
Expand Down Expand Up @@ -413,7 +413,7 @@ where key like 'rpcParam.has_in_parameters.%';

-- shows `INOUT` function arguments as RPC parameters
select key, jsonb_pretty(value)
from jsonb_each(postgrest_openapi_spec('{test}')->'components'->'parameters')
from jsonb_each(get_openapi_document('{test}')->'components'->'parameters')
where key like 'rpcParam.has_inout_parameters.%';
key | jsonb_pretty
---------------------------------+-----------------------------------------
Expand Down Expand Up @@ -457,7 +457,7 @@ where key like 'rpcParam.has_inout_parameters.%';

-- shows `VARIADIC` function arguments as RPC parameters
select key, jsonb_pretty(value)
from jsonb_each(postgrest_openapi_spec('{test}')->'components'->'parameters')
from jsonb_each(get_openapi_document('{test}')->'components'->'parameters')
where key like 'rpcParam.has_variadic_parameter.%';
key | jsonb_pretty
-----------------------------------+-----------------------------------
Expand Down
Loading

0 comments on commit b6161a0

Please sign in to comment.