git.iko.soy/typeable/postgresql-simple
on master help sign in
32 lines 913 B history raw
1module Common (
2 module Database.PostgreSQL.Simple,
3 module Test.Tasty.HUnit,
4 TestEnv(..),
5 md5,
6) where
8import Data.ByteString (ByteString)
9import Data.Text (Text)
10import Database.PostgreSQL.Simple
11import Test.Tasty.HUnit
13import qualified Crypto.Hash.MD5 as MD5
14import qualified Data.ByteString.Base16 as Base16
15import qualified Data.Text.Encoding as TE
17data TestEnv
18 = TestEnv
19 { conn :: Connection
20 -- ^ Connection shared by all the tests
21 , withConn :: forall a. (Connection -> IO a) -> IO a
22 -- ^ Bracket for spawning additional connections
23 }
25-- | Return the MD5 hash of a 'ByteString', in lowercase hex format.
26--
27-- Example:
28--
29-- >[Only hash] <- query_ conn "SELECT md5('hi')"
30-- >assertEqual "md5('hi')" (md5 "hi") hash
31md5 :: ByteString -> Text
32md5 = TE.decodeUtf8 . Base16.encode . MD5.hash