test: Make PgSafeUpdateSpec parallel-ready

This commit is contained in:
Wolfgang Walther
2024-05-09 18:05:44 +02:00
parent aa94e436fa
commit c4295b3d63
2 changed files with 17 additions and 33 deletions
+12 -29
View File
@@ -10,7 +10,6 @@ import Test.Hspec.Wai
import Test.Hspec.Wai.JSON
import Protolude hiding (get, put)
import SpecHelper
tblDataBefore = [aesonQQ|[
{ "id": 1, "name": "item-1", "observation": null }
@@ -36,15 +35,9 @@ spec =
{ matchStatus = 400 }
it "allows full table update if a filter is present" $
baseTable "safe_update_items" "id" tblDataBefore
`mutatesWith`
requestMutation methodPatch "/safe_update_items?id=gt.0" mempty [json| {"name": "updated-item"} |]
`shouldMutateInto`
[json|[
{ "id": 1, "name": "updated-item", "observation": null }
, { "id": 2, "name": "updated-item", "observation": null }
, { "id": 3, "name": "updated-item", "observation": null }
]|]
request methodPatch "/safe_update_items?id=gt.0" mempty [json| {"name": "updated-item"} |]
`shouldRespondWith`
204
context "Full table delete" $ do
it "does not delete and throws error if no condition is present" $
@@ -59,31 +52,21 @@ spec =
{ matchStatus = 400 }
it "allows full table delete if a filter is present" $
baseTable "safe_delete_items" "id" tblDataBefore
`mutatesWith`
requestMutation methodDelete "/safe_delete_items?id=gt.0" mempty mempty
`shouldMutateInto`
[json|[]|]
request methodDelete "/safe_delete_items?id=gt.0" mempty mempty
`shouldRespondWith`
204
disabledSpec :: SpecWith ((), Application)
disabledSpec =
describe "Disabling pg-safeupdate" $ do
context "Full table update" $ do
it "works if no condition is present" $
baseTable "unsafe_update_items" "id" tblDataBefore
`mutatesWith`
requestMutation methodPatch "/unsafe_update_items" mempty [json| {"name": "updated-item"} |]
`shouldMutateInto`
[json|[
{ "id": 1, "name": "updated-item", "observation": null }
, { "id": 2, "name": "updated-item", "observation": null }
, { "id": 3, "name": "updated-item", "observation": null }
]|]
request methodPatch "/unsafe_update_items" mempty [json| {"name": "updated-item"} |]
`shouldRespondWith`
204
context "Full table delete" $ do
it "works if no condition is present" $
baseTable "unsafe_delete_items" "id" tblDataBefore
`mutatesWith`
requestMutation methodDelete "/unsafe_delete_items" mempty mempty
`shouldMutateInto`
[json|[]|]
request methodDelete "/unsafe_delete_items" mempty mempty
`shouldRespondWith`
204
+5 -4
View File
@@ -245,10 +245,6 @@ main = do
parallel $ before planEnabledApp $
describe "Feature.Query.PlanSpec.spec" $ Feature.Query.PlanSpec.spec actualPgVersion
-- this test runs with a pre request to enable the pg-safeupdate library per-session
parallel $ before pgSafeUpdateApp $
describe "Feature.Query.PgSafeUpdateSpec.spec" Feature.Query.PgSafeUpdateSpec.spec
-- this test runs with server-trace-header set
parallel $ before obsApp $
describe "Feature.ObservabilitySpec.spec" Feature.ObservabilitySpec.spec
@@ -277,6 +273,11 @@ main = do
before forceRollbackApp $
describe "Feature.RollbackForcedSpec" Feature.RollbackSpec.forced
-- This test runs with a pre request to enable the pg-safeupdate library per-session.
-- This needs to run last, because once pg safe update is loaded, it can't be unloaded again.
before pgSafeUpdateApp $
describe "Feature.Query.PgSafeUpdateSpec.spec" Feature.Query.PgSafeUpdateSpec.spec
where
loadSCache pool conf =
either (panic.show) id <$> P.use pool (HT.transaction HT.ReadCommitted HT.Read $ querySchemaCache conf)