-
Notifications
You must be signed in to change notification settings - Fork 6
/
TestUtils.hs
25 lines (22 loc) · 981 Bytes
/
TestUtils.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module TestUtils where
import Control.Concurrent (forkIO, ThreadId, threadDelay)
import Control.Monad.Logger (runStdoutLoggingT)
import Control.Monad.Reader (runReaderT)
import Database.Persist.Postgresql (withPostgresqlConn, runMigrationSilent)
import Network.HTTP.Client (newManager)
import Network.HTTP.Client.TLS (tlsManagerSettings)
import Servant.Client (ClientEnv(..), parseBaseUrl)
import CacheServer (runServer)
import Cache (RedisInfo, localRedisInfo)
import Database (PGInfo, localConnString)
import BasicSchema (migrateAll)
setupTests :: IO (PGInfo, RedisInfo, ClientEnv, ThreadId)
setupTests = do
mgr <- newManager tlsManagerSettings
baseUrl <- parseBaseUrl "http://127.0.0.1:8000"
let clientEnv = ClientEnv mgr baseUrl Nothing
runStdoutLoggingT $ withPostgresqlConn localConnString $ \dbConn ->
runReaderT (runMigrationSilent migrateAll) dbConn
tid <- forkIO runServer
threadDelay 1000000
return (localConnString, localRedisInfo, clientEnv, tid)