testcontainers-0.2.0.0: Docker containers for your integration tests.

Safe HaskellNone
LanguageHaskell2010

TestContainers.Tasty

Contents

Synopsis

Running containers for tests

withContainers :: forall a. (forall m. MonadDocker m => m a) -> (IO a -> TestTree) -> TestTree Source #

Allow TestTree to depend on Docker containers. Tasty takes care of initialization and de-initialization of the containers.

containers :: MonadDocker m => m ()
containers = do
  _redis <- TestContainers.run $ TestContainers.containerRequest TestContainers.redis
  _kafka <- TestContainers.run $ TestContainers.containerRequest TestContainers.kafka
  pure ()

example :: TestTree
example =
  withContainers containers $ \runContainers -> testGroup "Example tests"
    [
      testCase "first test" $ do
        -- Actually runs the container.
        runContainers
      testCase "second test" $ do
        -- Start containers. Tasty makes sure to only initialize once as
        --  `first test` might already have started them.
        runContainers
    ]

withContainers allows you naturally scope the handling of containers for your tests.

Re-exports for convenience