-- | Coverage for 'Pqi.loCreate': creating a new large object with an
-- explicitly requested OID.
--
-- Each run removes the object it creates, so the explicit OID is free for the
-- reference run and can be compared in full.
module Pqi.Conformance.Operation.LoCreate
  ( spec,
  )
where

import qualified Pqi
import Pqi.Conformance.Harness
import Pqi.Conformance.Prelude
import Pqi.Conformance.Scenario (inTransaction)
import Test.Hspec

spec :: Pqi.Adapter -> SpecWith ByteString
spec :: Adapter -> SpecWith ByteString
spec Adapter
adapter =
  String -> SpecWith ByteString -> SpecWith ByteString
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"loCreate" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"creates a large object with an explicit OID" \ByteString
conninfo ->
      Adapter
-> ByteString
-> (Connection -> IO (Maybe Word32, Maybe (Maybe ())))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection ->
        Connection
-> IO (Maybe Word32, Maybe (Maybe ()))
-> IO (Maybe Word32, Maybe (Maybe ()))
forall a. Connection -> IO a -> IO a
inTransaction Connection
connection do
          -- Best-effort cleanup of leftovers from an earlier crashed run; its
          -- outcome legitimately differs between runs, so it is not observed.
          _ <- Connection -> Word32 -> IO (Maybe ())
Pqi.loUnlink Connection
connection Word32
forall {a}. Num a => a
explicitOid
          created <- Pqi.loCreate connection explicitOid
          unlinked <- for created (Pqi.loUnlink connection)
          pure (created, unlinked)
  where
    explicitOid :: a
explicitOid = a
424242