Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- withContainers :: forall a. TestContainer a -> (a -> IO ()) -> IO ()
- module TestContainers
Running containers for tests
withContainers :: forall a. TestContainer a -> (a -> IO ()) -> IO () Source #
Allow Spec
to depend on Docker containers. Hspec takes care of
initialization and de-initialization of the containers.
data ContainerPorts = ContainerPorts {
redisPort :: Int,
kafkaPort :: Int
}
containers :: MonadDocker m => m ContainerPorts
containers = do
redis <- TestContainers.run $ TestContainers.containerRequest TestContainers.redis
kafka <- TestContainers.run $ TestContainers.containerRequest TestContainers.kafka
pure ContainerPorts {
redisPort = TestContainers.containerPort redis "6379/tcp",
kafkaPort = TestContainers.containerPort kafka "9092/tcp"
}
example :: Spec
example =
around (withContainers containers) $ describe "Example tests"
it "some test that uses redis and kafka" $ ContainerPorts{redisPort, kafkaPort} -> do
redisPort shouldNotBe
kafkaPort
withContainers
allows you naturally scope the handling of containers for your tests.
Re-exports for convenience
module TestContainers