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
- createPool :: IO a -> (a -> IO ()) -> Int -> NominalDiffTime -> Int -> IO (Pool a)
- takeResource :: Pool a -> IO (a, LocalPool a)
- withResource :: Pool a -> (a -> IO r) -> IO r
- destroyAllResources :: Pool a -> IO ()
- putResource :: LocalPool a -> a -> IO ()
- destroyResource :: Pool a -> LocalPool a -> a -> IO ()
- newPool :: PoolConfig a -> IO (Pool a)
- data LocalPool a
- data PoolConfig a = PoolConfig {
- createResource :: !(IO a)
- freeResource :: !(a -> IO ())
- poolCacheTTL :: !Double
- poolMaxResources :: !Int
- data PostgresStatementTimeout
- data PostgresPassword
- data PostgresPasswordSource
- data PostgresConnectionConf = PostgresConnectionConf {}
- class HasSqlPool app where
- getSqlPool :: app -> SqlPool
- type SqlPool = Pool SqlBackend
- makePostgresPool :: (MonadUnliftIO m, MonadLoggerIO m) => m SqlPool
- runDB :: (HasSqlPool app, MonadUnliftIO m, MonadReader app m) => SqlPersistT m a -> m a
- postgresStatementTimeoutMilliseconds :: PostgresStatementTimeout -> Int
- envPostgresPasswordSource :: Parser Error PostgresPasswordSource
- envParseDatabaseConf :: PostgresPasswordSource -> Parser Error PostgresConnectionConf
- makePostgresPoolWith :: (MonadUnliftIO m, MonadLoggerIO m) => PostgresConnectionConf -> m 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 () #
Striped resource pool based on Control.Concurrent.QSem.
The number of stripes is arranged to be equal to the number of capabilities so that they never compete over access to the same stripe. This results in a very good performance in a multi-threaded environment.
Instances
HasSqlPool SqlPool Source # | |
Defined in Freckle.App.Database getSqlPool :: SqlPool -> SqlPool Source # |
createPool :: IO a -> (a -> IO ()) -> Int -> NominalDiffTime -> Int -> IO (Pool a) #
Provided for compatibility with resource-pool < 0.3
.
Use newPool
instead.
takeResource :: Pool a -> IO (a, LocalPool a) #
Take a resource from the pool, following the same results as
withResource
.
Note: 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 :: Pool a -> (a -> IO r) -> IO r #
Take a resource from the 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.
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.
newPool :: PoolConfig a -> IO (Pool a) #
Create a new striped resource pool.
The number of stripes is equal to the number of capabilities.
Note: although the runtime system will destroy all idle resources when the
pool is garbage collected, it's recommended to manually call
destroyAllResources
when you're done with the pool so that the resources
are freed up as soon as possible.
data PoolConfig a #
Configuration of a Pool
.
PoolConfig | |
|
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 #
makePostgresPool :: (MonadUnliftIO m, MonadLoggerIO m) => m SqlPool Source #
runDB :: (HasSqlPool app, MonadUnliftIO m, MonadReader app m) => SqlPersistT m a -> m a Source #
makePostgresPoolWith :: (MonadUnliftIO m, MonadLoggerIO m) => PostgresConnectionConf -> m SqlPool Source #