on master help sign in
Add test for listing containers

We have to start a container before running this test since it will pass regardless if there are no containers

commit2daa5e52992ac86ecdb0cfd80da53cc7fcc64643 authorDeni Bertovic <deni@denibertovic.com> dateThu 16 Nov 2017, 23:54 (9 years ago) parent966b66d
2 files changed+12−1
src/Docker/Client/Types.hs+4−1 tests/tests.hs+8
src/Docker/Client/Types.hs+4−1
@@ -520,7 +520,7 @@ data Container = Container
520520
521521instance FromJSON Container where
522522 parseJSON (JSON.Object v) =
523− Container <$> (v .: "Id")
523+ Container <$> (v .: "Id" >>= parseContainerID)
524524 <*> (v .: "Names")
525525 <*> (v .: "Image")
526526 <*> (v .: "ImageID")
@@ -535,6 +535,9 @@ instance FromJSON Container where
535535 parseNetworks (JSON.Object v) =
536536 (v .: "Networks") >>= parseJSON
537537 parseNetworks _ = fail "Container NetworkSettings: Not a JSON object."
538+ parseContainerID v = case (toContainerID v) of
539+ Nothing -> fail "bla"
540+ Just i -> return i
538541
539542 parseJSON _ = fail "Container: Not a JSON object."
540543
tests/tests.hs+8
@@ -69,6 +69,13 @@ testFindImage =
6969 where
7070 imageFullName = testImageName <> ":latest"
7171
72+testListContainers :: IO ()
73+testListContainers =
74+ runDocker $
75+ do res <- listContainers defaultListOpts
76+ liftIO $ print res
77+ lift $ assert $ isRight res
78+
7279testBuildFromDockerfile :: IO ()
7380testBuildFromDockerfile = do
7481 cur <- getCurrentDirectory
@@ -170,6 +177,7 @@ integrationTests =
170177 [ testCase "Get docker version" testDockerVersion
171178 , testCase "Build image from Dockerfile" testBuildFromDockerfile
172179 , testCase "Find image by name" testFindImage
180+ , testCase "List containers" testListContainers
173181 , testCase "Run a dummy container and read its log" testRunAndReadLog
174182 , testCase "Try to stop a container that doesn't exist" testStopNonexisting
175183 ]