Closed sigrdrifa closed 5 months ago
AFAICS, there are no existing helpers. Here is an example for Postgres
setupDBContainer :: MonadDocker m => m (Text, Int)
setupDBContainer = do
let
pgImageTag = 14
pgUser = "postgres"
pgPassword = "postgres"
pgDbName = "postgres"
pgContainer <- run $ containerRequest (fromTag [int||postgres:#{pgImageTag}|])
& setEnv [("POSTGRES_PASSWORD", pgPassword)]
& setSuffixedName "db"
& setExpose [5432]
& setWaitingFor (waitForLogLine Stderr ("database system is ready to accept connections" `LT.isInfixOf`))
pure $ containerAddress pgContainer 5432
And then use it in your test-suite
withContainers setupDBContainer $ \(pgHost, pgPort) -> testCase "DB test" $ do
...
Thanks so much for the example!
I was specifically interested in Postgres so thank you for the example, and I might see if I can write a postgres helper and do a PR :)
Hey,
just came across this library and it's amazing, I had no idea this existed for Haskell!
I've been looking through the examples and I can see some examples with running nginx, redis and rabbitMQ but I was wondering if there are any examples for using this with popular databases like MySQL and/or PostgresDB? I know that testcontainers have official modules for those and I was wondering if testcontainers-hs supported them or if there was a way to invoke them?
Thanks!