-- | Coverage for 'Pqi.enableNoticeReporting': turning on notice
-- accumulation so that a raised notice becomes retrievable via
-- 'Pqi.getNotice'.
module Pqi.Conformance.Operation.EnableNoticeReporting
  ( spec,
  )
where

import qualified Pqi
import Pqi.Conformance.Harness
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
"enableNoticeReporting" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"makes a raised notice retrievable" \ByteString
conninfo ->
      Adapter -> ByteString -> (Connection -> IO (Bool, Bool)) -> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
        beforeEnable <- Connection -> IO Bool
raiseNoticeAndCollect Connection
connection
        Pqi.enableNoticeReporting connection
        afterEnable <- raiseNoticeAndCollect connection
        pure (beforeEnable, afterEnable)

raiseNoticeAndCollect :: Pqi.Connection -> IO Bool
raiseNoticeAndCollect :: Connection -> IO Bool
raiseNoticeAndCollect Connection
connection = do
  _ <- Connection -> ByteString -> IO (Maybe Result)
Pqi.exec Connection
connection ByteString
"do $$ begin raise notice 'conformance notice'; end $$"
  isJust <$> Pqi.getNotice connection