mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-26 02:11:53 +00:00
autorenews certificates
This commit is contained in:
@@ -5,31 +5,33 @@
|
||||
module TestImport
|
||||
( module TestImport
|
||||
, module X
|
||||
) where
|
||||
)
|
||||
where
|
||||
|
||||
import Startlude
|
||||
import Application (makeFoundation, makeLogWare)
|
||||
import Foundation as X
|
||||
import Test.Hspec as X
|
||||
import Yesod.Default.Config2 (useEnv, loadYamlSettings)
|
||||
import Yesod.Test as X
|
||||
import Yesod.Core.Unsafe (fakeHandlerGetLogger)
|
||||
import Database.Persist.Sql
|
||||
import Text.Shakespeare.Text (st)
|
||||
import Yesod.Core
|
||||
import qualified Data.Text as T
|
||||
import Startlude
|
||||
import Application ( makeFoundation
|
||||
, makeLogWare
|
||||
)
|
||||
import Foundation as X
|
||||
import Test.Hspec as X
|
||||
import Yesod.Default.Config2 ( useEnv
|
||||
, loadYamlSettings
|
||||
)
|
||||
import Yesod.Test as X
|
||||
import Yesod.Core.Unsafe ( fakeHandlerGetLogger )
|
||||
import Database.Persist.Sql
|
||||
import Text.Shakespeare.Text ( st )
|
||||
import Yesod.Core
|
||||
import qualified Data.Text as T
|
||||
|
||||
runHandler :: Handler a -> YesodExample AgentCtx a
|
||||
runHandler :: Handler a -> YesodExample RegistryCtx a
|
||||
runHandler handler = do
|
||||
app <- getTestYesod
|
||||
fakeHandlerGetLogger appLogger app handler
|
||||
|
||||
withApp :: SpecWith (TestApp AgentCtx) -> Spec
|
||||
withApp :: SpecWith (TestApp RegistryCtx) -> Spec
|
||||
withApp = before $ do
|
||||
settings <- loadYamlSettings
|
||||
["config/settings.yml"]
|
||||
[]
|
||||
useEnv
|
||||
settings <- loadYamlSettings ["config/settings.yml"] [] useEnv
|
||||
foundation <- makeFoundation settings
|
||||
wipeDB foundation
|
||||
logWare <- liftIO $ makeLogWare foundation
|
||||
@@ -37,32 +39,33 @@ withApp = before $ do
|
||||
|
||||
getTables :: DB [Text]
|
||||
getTables = do
|
||||
tables <- rawSql [st|
|
||||
tables <- rawSql
|
||||
[st|
|
||||
SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'public'
|
||||
AND table_type = 'BASE TABLE';
|
||||
|] []
|
||||
|]
|
||||
[]
|
||||
|
||||
return $ fmap unSingle tables
|
||||
|
||||
wipeDB :: AgentCtx -> IO ()
|
||||
wipeDB :: RegistryCtx -> IO ()
|
||||
wipeDB app = runDBWithApp app $ do
|
||||
tables <- getTables
|
||||
tables <- getTables
|
||||
sqlBackend <- ask
|
||||
|
||||
let escapedTables = map (T.unpack . connEscapeName sqlBackend . DBName) tables
|
||||
query = "TRUNCATE TABLE " ++ (intercalate ", " escapedTables)
|
||||
query = "TRUNCATE TABLE " ++ (intercalate ", " escapedTables)
|
||||
rawExecute (T.pack query) []
|
||||
|
||||
runDBtest :: SqlPersistM a -> YesodExample AgentCtx a
|
||||
runDBtest :: SqlPersistM a -> YesodExample RegistryCtx a
|
||||
runDBtest query = do
|
||||
app <- getTestYesod
|
||||
liftIO $ runDBWithApp app query
|
||||
|
||||
runDBWithApp :: AgentCtx -> SqlPersistM a -> IO a
|
||||
runDBWithApp :: RegistryCtx -> SqlPersistM a -> IO a
|
||||
runDBWithApp app query = runSqlPersistMPool query (appConnPool app)
|
||||
|
||||
-- A convenient synonym for database access functions
|
||||
type DB a = forall (m :: * -> *).
|
||||
(MonadUnliftIO m) => ReaderT SqlBackend m a
|
||||
type DB a = forall (m :: * -> *) . (MonadUnliftIO m) => ReaderT SqlBackend m a
|
||||
|
||||
Reference in New Issue
Block a user