Skip to content

Commit

Permalink
Update HSpec example in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbiehl committed Jul 5, 2024
1 parent aed0602 commit 7775add
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
19 changes: 13 additions & 6 deletions src/TestContainers/Hspec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 15 additions & 6 deletions test/TestContainers/HspecSpec.hs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,5 +33,5 @@ spec_all :: Spec
spec_all =
around (withContainers containers1) $
describe "TestContainers tests" $
it "test1" $
shouldBe ()
it "test1" $ \ContainerPorts {} ->
shouldBe () ()

0 comments on commit 7775add

Please sign in to comment.