Skip to content

Commit c03ac09

Browse files
committed
test: move prepared statements config related tests to spec tests
Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
1 parent 44edf96 commit c03ac09

7 files changed

Lines changed: 47 additions & 42 deletions

File tree

postgrest.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ test-suite spec
260260
Feature.Query.Preferences.HandlingSpec
261261
Feature.Query.Preferences.MaxAffectedSpec
262262
Feature.Query.Preferences.TimezoneSpec
263+
Feature.Query.PreparedStatementsSpec
263264
Feature.Query.QueryLimitedSpec
264265
Feature.Query.QuerySpec
265266
Feature.Query.RangeSpec

test/io/__snapshots__/test_cli/test_schema_cache_snapshot[dbRoutines].yaml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -512,23 +512,6 @@
512512
pdSchema: public
513513
pdVolatility: Volatile
514514

515-
- - qiName: uses_prepared_statements
516-
qiSchema: public
517-
- - pdDescription: null
518-
pdFuncSettings: []
519-
pdHasVariadic: false
520-
pdName: uses_prepared_statements
521-
pdParams: []
522-
pdReturnType:
523-
contents:
524-
contents:
525-
qiName: bool
526-
qiSchema: pg_catalog
527-
tag: Scalar
528-
tag: Single
529-
pdSchema: public
530-
pdVolatility: Volatile
531-
532515
- - qiName: repeatable_read_isolation_level
533516
qiSchema: public
534517
- - pdDescription: null

test/io/fixtures/schema.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ create function v1.get_guc_value(name text) returns text as $$
5454
select nullif(current_setting(name), '')::text;
5555
$$ language sql;
5656

57-
create function uses_prepared_statements() returns bool as $$
58-
select count(name) > 0 from pg_catalog.pg_prepared_statements
59-
$$ language sql;
60-
6157
create function change_max_rows_config(val int, notify bool default false) returns void as $_$
6258
begin
6359
execute format($$

test/io/test_io.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -420,27 +420,6 @@ def test_notify_do_nothing(defaultenv):
420420
assert output == []
421421

422422

423-
def test_db_prepared_statements_enable(defaultenv):
424-
"Should use prepared statements when the setting is enabled."
425-
426-
with run(env=defaultenv) as postgrest:
427-
response = postgrest.session.post("/rpc/uses_prepared_statements")
428-
assert response.text == "true"
429-
430-
431-
def test_db_prepared_statements_disable(defaultenv):
432-
"Should not use any prepared statements when the setting is disabled."
433-
434-
env = {
435-
**defaultenv,
436-
"PGRST_DB_PREPARED_STATEMENTS": "false",
437-
}
438-
439-
with run(env=env) as postgrest:
440-
response = postgrest.session.post("/rpc/uses_prepared_statements")
441-
assert response.text == "false"
442-
443-
444423
def test_statement_timeout(defaultenv, metapostgrest):
445424
"Statement timeout times out slow statements"
446425

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module Feature.Query.PreparedStatementsSpec where
2+
3+
import Network.HTTP.Types
4+
import Test.Hspec hiding (pendingWith)
5+
import Test.Hspec.Wai
6+
import Text.Heredoc
7+
8+
import PostgREST.Config (AppConfig (..))
9+
10+
import Protolude hiding (get)
11+
import SpecHelper
12+
13+
spec :: SpecWithConfig
14+
spec withConfig = do
15+
withConfig baseCfg { configDbPreparedStatements = True } $
16+
it "should use prepared statements when the setting is enabled" $
17+
request methodPost "/rpc/uses_prepared_statements"
18+
[] ""
19+
`shouldRespondWith`
20+
[str|true|]
21+
{ matchStatus = 200 }
22+
23+
withConfig baseCfg { configDbPreparedStatements = False } $
24+
it "should not use any prepared statements when the setting is disabled" $ do
25+
request methodGet "/never_prepared"
26+
[] ""
27+
`shouldRespondWith` 200
28+
29+
request methodPost "/rpc/never_uses_prepared_statements"
30+
[] ""
31+
`shouldRespondWith`
32+
[str|true|]
33+
{ matchStatus = 200 }

test/spec/Main.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import qualified Feature.Query.PostGISSpec
5858
import qualified Feature.Query.Preferences.HandlingSpec
5959
import qualified Feature.Query.Preferences.MaxAffectedSpec
6060
import qualified Feature.Query.Preferences.TimezoneSpec
61+
import qualified Feature.Query.PreparedStatementsSpec
6162
import qualified Feature.Query.QueryLimitedSpec
6263
import qualified Feature.Query.QuerySpec
6364
import qualified Feature.Query.RangeSpec
@@ -148,6 +149,7 @@ main = do
148149
, ("Feature.Query.Preferences.HandlingSpec" , Feature.Query.Preferences.HandlingSpec.spec)
149150
, ("Feature.Query.Preferences.MaxAffectedSpec" , Feature.Query.Preferences.MaxAffectedSpec.spec)
150151
, ("Feature.Query.Preferences.TimezoneSpec.enabledSpec", Feature.Query.Preferences.TimezoneSpec.enabledSpec)
152+
, ("Feature.Query.PreparedStatementsSpec.spec" , Feature.Query.PreparedStatementsSpec.spec)
151153
, ("Feature.Query.QueryLimitedSpec" , Feature.Query.QueryLimitedSpec.spec)
152154
, ("Feature.Query.QuerySpec" , Feature.Query.QuerySpec.spec actualPgVersion)
153155
, ("Feature.Query.RangeSpec" , Feature.Query.RangeSpec.spec)

test/spec/fixtures/schema.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,3 +3881,14 @@ $$ language plpgsql;
38813881
create or replace function "true"() returns boolean as $_$
38823882
select true;
38833883
$_$ language sql;
3884+
3885+
create function uses_prepared_statements() returns bool as $$
3886+
select count(*) > 0 from pg_catalog.pg_prepared_statements;
3887+
$$ language sql;
3888+
3889+
create table never_prepared (id int);
3890+
3891+
create function never_uses_prepared_statements() returns bool as $$
3892+
select count(*) = 0 from pg_catalog.pg_prepared_statements
3893+
where statement ilike '%never_prepared%';
3894+
$$ language sql;

0 commit comments

Comments
 (0)