-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathTastySpec.hs
More file actions
108 lines (95 loc) · 2.46 KB
/
Copy pathTastySpec.hs
File metadata and controls
108 lines (95 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
module TestContainers.TastySpec (main, test_all) where
import Test.Tasty (TestTree, defaultMain, testGroup)
import Test.Tasty.HUnit
import TestContainers.Tasty
( TestContainer,
consoleLogConsumer,
containerRequest,
createNetwork,
fromBuildContext,
fromTag,
networkRequest,
redis,
run,
setExpose,
setRm,
setWaitingFor,
successfulExit,
waitForHttp,
waitForState,
waitUntilMappedPortReachable,
waitUntilTimeout,
withContainers,
withCopyFileToContainer,
withFollowLogs,
withNetwork,
(&),
)
containers1 ::
TestContainer ()
containers1 = do
net <-
createNetwork networkRequest
_redisContainer <-
run $
containerRequest redis
& setExpose [6379]
& withNetwork net
& setWaitingFor
( waitUntilTimeout 30 $
waitUntilMappedPortReachable 6379
)
_rabbitmq <-
run $
containerRequest (fromTag "rabbitmq:3.13")
& setRm False
& setExpose [5672]
& withNetwork net
& withFollowLogs consoleLogConsumer
& setWaitingFor
(waitUntilMappedPortReachable 5672)
_nginx <-
run $
containerRequest (fromTag "nginx:1.27-alpine")
& setExpose [80]
& withNetwork net
& setWaitingFor
( waitUntilTimeout 30 $
waitForHttp 80 "/" [200]
)
_jaeger <-
run $
containerRequest (fromTag "jaegertracing/all-in-one:1.62.0")
& setExpose ["5775/udp", "6831/udp", "6832/udp", "5778", "16686/tcp"]
& withNetwork net
& setWaitingFor
(waitForHttp "16686/tcp" "/" [200])
_postgres <-
run $
containerRequest (fromTag "postgres:17-alpine")
& withCopyFileToContainer "test/data/init-script.sql" "/docker-entrypoint-initdb.d/"
_helloWorld <-
run $
containerRequest (fromTag "hello-world:latest")
& setWaitingFor (waitForState successfulExit)
_test <- run $ containerRequest (fromBuildContext "./test/container1" Nothing)
pure ()
main :: IO ()
main = defaultMain test_all
test_all :: TestTree
test_all =
testGroup
"TestContainers tests"
[ withContainers containers1 $ \setup ->
testGroup
"Multiple tests"
[ testCase "test1" $ do
setup
return (),
testCase "test2" $ do
setup
return ()
]
]