Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data AppExample app a
- withApp :: IO app -> SpecWith app -> Spec
- withAppSql :: HasSqlPool app => SqlPersistT IO a -> IO app -> SpecWith app -> Spec
- runAppTest :: ReaderT app (LoggingT IO) a -> AppExample app a
- type HasCallStack = ?callStack :: CallStack
- example :: Expectation -> Expectation
- type Spec = SpecWith ()
- beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b
- beforeAll :: HasCallStack => IO a -> SpecWith a -> Spec
- describe :: HasCallStack => String -> SpecWith a -> SpecWith a
- context :: HasCallStack => String -> SpecWith a -> SpecWith a
- it :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- xit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- fit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a)
- shouldNotReturn :: (HasCallStack, MonadIO m, Show a, Eq a) => m a -> a -> m ()
- shouldNotContain :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m ()
- shouldNotSatisfy :: (HasCallStack, MonadIO m, Show a) => a -> (a -> Bool) -> m ()
- shouldNotBe :: (HasCallStack, MonadIO m, Show a, Eq a) => a -> a -> m ()
- shouldReturn :: (HasCallStack, MonadIO m, Show a, Eq a) => m a -> a -> m ()
- shouldMatchList :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m ()
- shouldContain :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m ()
- shouldEndWith :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m ()
- shouldStartWith :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m ()
- shouldSatisfy :: (HasCallStack, MonadIO m, Show a) => a -> (a -> Bool) -> m ()
- shouldBe :: (HasCallStack, MonadIO m, Show a, Eq a) => a -> a -> m ()
- expectationFailure :: (HasCallStack, MonadIO m) => String -> m ()
- data Pool a
- destroyAllResources :: Pool a -> IO ()
- putResource :: LocalPool a -> a -> IO ()
- destroyResource :: Pool a -> LocalPool a -> a -> IO ()
- tryTakeResource :: Pool a -> IO (Maybe (a, LocalPool a))
- tryWithResource :: MonadBaseControl IO m => Pool a -> (a -> m b) -> m (Maybe b)
- takeResource :: Pool a -> IO (a, LocalPool a)
- withResource :: MonadBaseControl IO m => Pool a -> (a -> m b) -> m b
- createPool :: IO a -> (a -> IO ()) -> Int -> NominalDiffTime -> Int -> IO (Pool a)
- data LocalPool a
- data PostgresStatementTimeout
- data PostgresPassword
- data PostgresPasswordSource
- data PostgresConnectionConf = PostgresConnectionConf {}
- class HasSqlPool app where
- getSqlPool :: app -> SqlPool
- type SqlPool = Pool SqlBackend
- makePostgresPool :: IO SqlPool
- runDB :: (HasSqlPool app, MonadUnliftIO m, MonadReader app m) => SqlPersistT m a -> m a
- postgresStatementTimeoutMilliseconds :: PostgresStatementTimeout -> Int
- envPostgresPasswordSource :: Parser PostgresPasswordSource
- envParseDatabaseConf :: PostgresPasswordSource -> Parser PostgresConnectionConf
- makePostgresPoolWith :: PostgresConnectionConf -> IO SqlPool
Documentation
data AppExample app a Source #
An Hspec example over some App
value
Instances
withApp :: IO app -> SpecWith app -> Spec Source #
Spec before helper
spec :: Spec
spec = withApp
loadApp $ do
Reads .env.test
, then .env
, then loads the application. Examples within
this spec can use runAppTest
(and runDB
, if the app HasSqlPool
).
withAppSql :: HasSqlPool app => SqlPersistT IO a -> IO app -> SpecWith app -> Spec Source #
runAppTest :: ReaderT app (LoggingT IO) a -> AppExample app a Source #
Run an action with the test App
Like
, but without exception handling or loggingrunApp
type HasCallStack = ?callStack :: CallStack #
Request a CallStack.
NOTE: The implicit parameter ?callStack :: CallStack
is an
implementation detail and should not be considered part of the
CallStack
API, we may decide to change the implementation in the
future.
Since: base-4.9.0.0
example :: Expectation -> Expectation #
example
is a type restricted version of id
. It can be used to get better
error messages on type mismatches.
Compare e.g.
it "exposes some behavior" $ example $ do putStrLn
with
it "exposes some behavior" $ do putStrLn
beforeWith :: (b -> IO a) -> SpecWith a -> SpecWith b #
Run a custom action before every spec item.
beforeAll :: HasCallStack => IO a -> SpecWith a -> Spec #
Run a custom action before the first spec item.
describe :: HasCallStack => String -> SpecWith a -> SpecWith a #
The describe
function combines a list of specs into a larger spec.
it :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
The it
function creates a spec item.
A spec item consists of:
- a textual description of a desired behavior
- an example for that behavior
describe "absolute" $ do it "returns a positive number when given a negative number" $ absolute (-1) == 1
fit :: (HasCallStack, Example a) => String -> a -> SpecWith (Arg a) #
fit
is an alias for fmap focus . it
shouldNotReturn :: (HasCallStack, MonadIO m, Show a, Eq a) => m a -> a -> m () infix 1 #
action `shouldNotReturn` notExpected
sets the expectation that action
does not return notExpected
.
shouldNotContain :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m () infix 1 #
list `shouldNotContain` sublist
sets the expectation that sublist
is not
contained anywhere in list
.
shouldNotSatisfy :: (HasCallStack, MonadIO m, Show a) => a -> (a -> Bool) -> m () infix 1 #
v `shouldNotSatisfy` p
sets the expectation that p v
is False
.
shouldNotBe :: (HasCallStack, MonadIO m, Show a, Eq a) => a -> a -> m () infix 1 #
actual `shouldNotBe` notExpected
sets the expectation that actual
is not
equal to notExpected
shouldReturn :: (HasCallStack, MonadIO m, Show a, Eq a) => m a -> a -> m () infix 1 #
action `shouldReturn` expected
sets the expectation that action
returns expected
.
shouldMatchList :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m () infix 1 #
xs `shouldMatchList` ys
sets the expectation that xs
has the same
elements that ys
has, possibly in another order
shouldContain :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m () infix 1 #
list `shouldContain` sublist
sets the expectation that sublist
is contained,
wholly and intact, anywhere in list
.
shouldEndWith :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m () infix 1 #
list `shouldEndWith` suffix
sets the expectation that list
ends with suffix
,
shouldStartWith :: (HasCallStack, MonadIO m, Show a, Eq a) => [a] -> [a] -> m () infix 1 #
list `shouldStartWith` prefix
sets the expectation that list
starts with prefix
,
shouldSatisfy :: (HasCallStack, MonadIO m, Show a) => a -> (a -> Bool) -> m () infix 1 #
v `shouldSatisfy` p
sets the expectation that p v
is True
.
shouldBe :: (HasCallStack, MonadIO m, Show a, Eq a) => a -> a -> m () infix 1 #
actual `shouldBe` expected
sets the expectation that actual
is equal
to expected
.
expectationFailure :: (HasCallStack, MonadIO m) => String -> m () #
destroyAllResources :: Pool a -> IO () #
Destroy all resources in all stripes in the pool. Note that this will ignore any exceptions in the destroy function.
This function is useful when you detect that all resources in the
pool are broken. For example after a database has been restarted
all connections opened before the restart will be broken. In that
case it's better to close those connections so that takeResource
won't take a broken connection from the pool but will open a new
connection instead.
Another use-case for this function is that when you know you are done with the pool you can destroy all idle resources immediately instead of waiting on the garbage collector to destroy them, thus freeing up those resources sooner.
putResource :: LocalPool a -> a -> IO () #
Return a resource to the given LocalPool
.
destroyResource :: Pool a -> LocalPool a -> a -> IO () #
Destroy a resource. Note that this will ignore any exceptions in the destroy function.
tryTakeResource :: Pool a -> IO (Maybe (a, LocalPool a)) #
A non-blocking version of takeResource
. The tryTakeResource
function
returns immediately, with Nothing
if the pool is exhausted, or
if a resource could be borrowed from the pool successfully.Just
(a,
LocalPool
a)
tryWithResource :: MonadBaseControl IO m => Pool a -> (a -> m b) -> m (Maybe b) #
Similar to withResource
, but only performs the action if a resource could
be taken from the pool without blocking. Otherwise, tryWithResource
returns immediately with Nothing
(ie. the action function is not called).
Conversely, if a resource can be borrowed from the pool without blocking, the
action is performed and it's result is returned, wrapped in a Just
.
takeResource :: Pool a -> IO (a, LocalPool a) #
Take a resource from the pool, following the same results as
withResource
. Note that this function should be used with caution, as
improper exception handling can lead to leaked resources.
This function returns both a resource and the LocalPool
it came from so
that it may either be destroyed (via destroyResource
) or returned to the
pool (via putResource
).
withResource :: MonadBaseControl IO m => Pool a -> (a -> m b) -> m b #
Temporarily take a resource from a Pool
, perform an action with
it, and return it to the pool afterwards.
- If the pool has an idle resource available, it is used immediately.
- Otherwise, if the maximum number of resources has not yet been reached, a new resource is created and used.
- If the maximum number of resources has been reached, this function blocks until a resource becomes available.
If the action throws an exception of any type, the resource is destroyed, and not returned to the pool.
It probably goes without saying that you should never manually destroy a pooled resource, as doing so will almost certainly cause a subsequent user (who expects the resource to be valid) to throw an exception.
:: IO a | Action that creates a new resource. |
-> (a -> IO ()) | Action that destroys an existing resource. |
-> Int | The number of stripes (distinct sub-pools) to maintain. The smallest acceptable value is 1. |
-> NominalDiffTime | Amount of time for which an unused resource is kept open. The smallest acceptable value is 0.5 seconds. The elapsed time before destroying a resource may be a little longer than requested, as the reaper thread wakes at 1-second intervals. |
-> Int | Maximum number of resources to keep open per stripe. The smallest acceptable value is 1. Requests for resources will block if this limit is reached on a single stripe, even if other stripes have idle resources available. |
-> IO (Pool a) |
Create a striped resource pool.
Although the garbage collector will destroy all idle resources when
the pool is garbage collected it's recommended to manually
destroyAllResources
when you're done with the pool so that the
resources are freed up as soon as possible.
data PostgresStatementTimeout Source #
Instances
Eq PostgresStatementTimeout Source # | |
Defined in Freckle.App.Database | |
Show PostgresStatementTimeout Source # | |
Defined in Freckle.App.Database showsPrec :: Int -> PostgresStatementTimeout -> ShowS # show :: PostgresStatementTimeout -> String # showList :: [PostgresStatementTimeout] -> ShowS # |
data PostgresPassword Source #
Instances
Eq PostgresPassword Source # | |
Defined in Freckle.App.Database (==) :: PostgresPassword -> PostgresPassword -> Bool # (/=) :: PostgresPassword -> PostgresPassword -> Bool # | |
Show PostgresPassword Source # | |
Defined in Freckle.App.Database showsPrec :: Int -> PostgresPassword -> ShowS # show :: PostgresPassword -> String # showList :: [PostgresPassword] -> ShowS # |
data PostgresPasswordSource Source #
Instances
Eq PostgresPasswordSource Source # | |
Defined in Freckle.App.Database | |
Show PostgresPasswordSource Source # | |
Defined in Freckle.App.Database showsPrec :: Int -> PostgresPasswordSource -> ShowS # show :: PostgresPasswordSource -> String # showList :: [PostgresPasswordSource] -> ShowS # |
data PostgresConnectionConf Source #
Instances
Eq PostgresConnectionConf Source # | |
Defined in Freckle.App.Database | |
Show PostgresConnectionConf Source # | |
Defined in Freckle.App.Database showsPrec :: Int -> PostgresConnectionConf -> ShowS # show :: PostgresConnectionConf -> String # showList :: [PostgresConnectionConf] -> ShowS # |
class HasSqlPool app where Source #
getSqlPool :: app -> SqlPool Source #
Instances
HasSqlPool SqlPool Source # | |
Defined in Freckle.App.Database getSqlPool :: SqlPool -> SqlPool Source # |
type SqlPool = Pool SqlBackend Source #
runDB :: (HasSqlPool app, MonadUnliftIO m, MonadReader app m) => SqlPersistT m a -> m a Source #