diff --git a/src/TestContainers/Hspec.hs b/src/TestContainers/Hspec.hs index d736cc0..87fba84 100644 --- a/src/TestContainers/Hspec.hs +++ b/src/TestContainers/Hspec.hs @@ -30,18 +30,25 @@ import TestContainers.Monad (runTestContainer) -- initialization and de-initialization of the containers. -- -- @ +-- data ContainerPorts = ContainerPorts { +-- redisPort :: Int, +-- kafkaPort :: Int +-- } -- --- containers :: MonadDocker m => m Boolean +-- containers :: MonadDocker m => m ContainerPorts -- containers = do --- _redis <- TestContainers.run $ TestContainers.containerRequest TestContainers.redis --- _kafka <- TestContainers.run $ TestContainers.containerRequest TestContainers.kafka --- pure True +-- 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 "first test" $ \\isBoolean -> do --- isBoolean `shouldBe` True +-- 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. diff --git a/test/TestContainers/HspecSpec.hs b/test/TestContainers/HspecSpec.hs index 0fd88ee..2bfda6b 100644 --- a/test/TestContainers/HspecSpec.hs +++ b/test/TestContainers/HspecSpec.hs @@ -1,21 +1,30 @@ {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RecordWildCards #-} module TestContainers.HspecSpec (main, spec_all) where import Test.Hspec import TestContainers.Hspec ( TestContainer, + containerPort, containerRequest, redis, run, withContainers, ) -containers1 :: - TestContainer () +data ContainerPorts = ContainerPorts + { redisPort :: Int + } + +containers1 :: TestContainer ContainerPorts containers1 = do - _ <- run $ containerRequest redis - pure () + redisContainer <- run $ containerRequest redis + pure + ContainerPorts + { redisPort = containerPort redisContainer "6379/tcp" + } main :: IO () main = hspec spec_all @@ -24,5 +33,5 @@ spec_all :: Spec spec_all = around (withContainers containers1) $ describe "TestContainers tests" $ - it "test1" $ - shouldBe () + it "test1" $ \ContainerPorts {} -> + shouldBe () ()