module Pqi.Conformance.Operation.LoRead
( spec,
)
where
import qualified Pqi
import Pqi.Conformance.Harness
import Pqi.Conformance.Prelude
import Pqi.Conformance.Scenario (inTransaction)
import System.IO (IOMode (..), SeekMode (..))
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
"loRead" do
String
-> (ByteString -> IO ()) -> SpecWith (Arg (ByteString -> IO ()))
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"reads back what was written" \ByteString
conninfo ->
Adapter
-> ByteString
-> (Connection -> IO (Maybe (Maybe (Maybe ByteString))))
-> IO ()
forall a.
(Eq a, Show a, HasCallStack) =>
Adapter -> ByteString -> (Connection -> IO a) -> IO ()
differential Adapter
adapter ByteString
conninfo \Connection
connection ->
Connection
-> IO (Maybe (Maybe (Maybe ByteString)))
-> IO (Maybe (Maybe (Maybe ByteString)))
forall a. Connection -> IO a -> IO a
inTransaction Connection
connection do
oid <- Connection -> IO (Maybe Word32)
Pqi.loCreat Connection
connection
outcome <- for oid \Word32
o -> do
fd <- Connection -> Word32 -> IOMode -> IO (Maybe Int32)
Pqi.loOpen Connection
connection Word32
o IOMode
ReadWriteMode
readBytes <- for fd \Int32
f -> do
_ <- Connection -> Int32 -> ByteString -> IO (Maybe Int)
Pqi.loWrite Connection
connection Int32
f ByteString
"hello, large object"
_ <- Pqi.loSeek connection f AbsoluteSeek 0
Pqi.loRead connection f 5
traverse_ (Pqi.loClose connection) fd
pure readBytes
traverse_ (Pqi.loUnlink connection) oid
pure outcome