testcontainers / testcontainers-hs

Docker containers for your integration tests! http://hackage.haskell.org/package/testcontainers
MIT License
58 stars 13 forks source link

Expose WaitUntilReady constructors #46

Open crypticmind opened 1 year ago

crypticmind commented 1 year ago

I'd like to add a custom check, a real connection to the database with a test query. Something like this:

mariaDBReady :: TestDBInfo -> WaitUntilReady
mariaDBReady db = WaitReady $ \container -> do
    withFrozenCallStack $ do
        let (endpointHost, endpointPort) = containerAddress container db.dbPort
            ci =
                defaultConnectInfo
                    { connectHost = unpack endpointHost
                    , connectPort = fromIntegral endpointPort
                    , connectUser = unpack db.dbUsername
                    , connectPassword = unpack db.dbPassword
                    , connectDatabase = unpack db.dbName
                    }
            wait = do
                r <- try (connect ci >>= flip query_ "select 2 + 3")
                case r of
                    Right [Only (i :: Int)] -> do
                        pure ()
                    Left (ex :: IOException) -> do
                        threadDelay 500000
                        wait
        liftIO wait

This is currently not possible since WaitReady is not public.

alexbiehl commented 10 months ago

Good idea, happy to take a PR!