我有一个使用 Sqlite 数据库的基本 Yesod 服务器,我正在尝试向它添加测试。我对 Haskell 很陌生,所以我什至在努力寻找正确的术语,所以对我来说很简单。
我有这个代码来运行服务器:
runShortblitoWebServer :: Settings -> IO ()
runShortblitoWebServer Settings {..} =
runStderrLoggingT $
withSqlitePool "urls.db" 1 $ \pool -> do
let app =
App
{ appLogLevel = settingLogLevel,
appStatic = shortblitoWebServerStatic,
appConnectionPool = pool,
appGoogleAnalyticsTracking = settingGoogleAnalyticsTracking,
appGoogleSearchConsoleVerification = settingGoogleSearchConsoleVerification
}
flip runSqlPool pool $ do
runMigration migrateTables
liftIO $ Yesod.warp settingPort app
现在我正在尝试使用yesodSpecWithSiteGenerator
或yesodSpecWithSiteGeneratorAndArgument
创建我的Spec
. 像这样的东西:
shortblitoWebServerSpec :: ShortblitoWebServerSpec -> SpecWith a
shortblitoWebServerSpec =
yesodSpecWithSiteGeneratorAndArgument $
withSqlitePool ":memory:" 1 $ \pool -> do
let app =
App
{ appLogLevel = LevelWarn,
appStatic = shortblitoWebServerStatic,
appConnectionPool = pool,
appGoogleAnalyticsTracking = Nothing,
appGoogleSearchConsoleVerification = Nothing
}
flip runSqlPool pool $ do
runMigration migrateTables
app
我收到错误:
• Couldn't match expected type ‘a -> IO App’ with actual type ‘App’
• In a stmt of a 'do' block: app
In the expression:
do let app = ...
flip runSqlPool pool $ do runMigration migrateTables
app
In the second argument of ‘($)’, namely
‘\ pool
-> do let ...
flip runSqlPool pool $ do ...
....’
• Relevant bindings include
shortblitoWebServerSpec :: ShortblitoWebServerSpec -> SpecWith a
(bound at test/Shortblito/Web/Server/TestUtils.hs:49:1)
|
62 | app
| ^^^
而且我不确定该怎么做。我一直在尝试不同的事情,但在这一点上,我真的只是在黑暗中拍摄。
有人知道怎么做吗?您需要额外的信息吗?
谢谢!