-- | Coverage for 'Pqi.reset': a blocking reset restores a fresh session,
-- discarding transaction state and prepared statements.
module Pqi.Conformance.Operation.Reset
  ( spec,
  )
where

import qualified Pqi
import Pqi.Conformance.Harness
import Pqi.Conformance.Observation
import Pqi.Conformance.Prelude
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
"reset" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"restores a fresh session" \ByteString
conninfo ->
      Adapter
-> ByteString
-> (Connection
    -> IO
         (TransactionStatus, ConnectionObservation,
          Maybe ResultObservation))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
        _ <- Connection
-> ByteString -> ByteString -> Maybe [Word32] -> IO (Maybe Result)
Pqi.prepare Connection
connection ByteString
"conformance_reset" ByteString
"select 1" Maybe [Word32]
forall a. Maybe a
Nothing
        _ <- Pqi.exec connection "begin"
        inTransaction <- Pqi.transactionStatus connection
        Pqi.reset connection
        afterReset <- observeConnection connection
        -- The prepared statement must be gone in the fresh session.
        describeAfter <- Pqi.describePrepared connection "conformance_reset" >>= traverse observeResult
        pure (inTransaction, afterReset, describeAfter)