-- | Coverage for 'Pqi.cmdStatus': the command status tag (e.g.
-- @\"INSERT 0 2\"@) for each kind of command.
module Pqi.Conformance.Operation.CmdStatus
  ( 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
"cmdStatus" do
    String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"reports the command tag for each command" \ByteString
conninfo ->
      Adapter
-> ByteString
-> (Connection
    -> IO
         (Maybe (Maybe ByteString), Maybe (Maybe ByteString),
          Maybe (Maybe ByteString), Maybe (Maybe ByteString)))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection -> do
        _ <- Connection -> ByteString -> IO (Maybe Result)
Pqi.exec Connection
connection ByteString
"create temporary table conformance_cmd_status (id int4, label text)"
        let tagOf ByteString
sql = Connection -> ByteString -> IO (Maybe Result)
Pqi.exec Connection
connection ByteString
sql IO (Maybe Result)
-> (Maybe Result -> IO (Maybe (Maybe ByteString)))
-> IO (Maybe (Maybe ByteString))
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Result -> IO (Maybe ByteString))
-> Maybe Result -> IO (Maybe (Maybe ByteString))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse Result -> IO (Maybe ByteString)
Pqi.cmdStatus
        insert <- tagOf "insert into conformance_cmd_status values (1, 'a'), (2, 'b')"
        update <- tagOf "update conformance_cmd_status set label = 'c' where id = 1"
        delete <- tagOf "delete from conformance_cmd_status where id = 2"
        select <- tagOf "select * from conformance_cmd_status"
        pure (insert, update, delete, select)