-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved testing functionality #1146
Conversation
Main change is that now every test is running inside it's own isolated test database
|
||
-- | Create contexts that can be used for mocking | ||
mockContext :: (InitControllerContext application) => application -> ConfigBuilder -> IO (MockContext application) | ||
mockContext application configBuilder = do | ||
withIHPApp :: (InitControllerContext application) => application -> ConfigBuilder -> (MockContext application -> IO ()) -> IO () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe keep the word Mock, so it's clear it's not a real app? withMockedIHPApp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it's not really mocked anymore as we're now using the real database and action lifecycle for testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
IHP/Test/Mocking.hs
Outdated
@@ -53,11 +58,13 @@ mockContext application configBuilder = do | |||
let requestContext = RequestContext | |||
{ request = defaultRequest {vault = sessionVault} | |||
, requestBody = FormBody [] [] | |||
, respond = \resp -> pure ResponseReceived | |||
, respond = undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it undefined
so it would error out if response is not filled in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now :) Leftover from testing
frameworkConfig@(FrameworkConfig {dbPoolMaxConnections, dbPoolIdleTime, databaseUrl}) <- FrameworkConfig.buildFrameworkConfig configBuilder | ||
databaseConnection <- connectPostgreSQL databaseUrl | ||
|
||
testDatabase <- Database.createTestDatabase databaseUrl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using bracket
to ensure things get cleaned up if there is an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point 👍 6dd1b6e
Main change is that now every test is running inside it's own isolated test database