on master help sign in
Fix tests for `NetworkingConfig`

Tests were failing on Travis CI because they were assuming network named "test-network" to exist, which is not true on Travis CI I've got around this issue by creating networks from provided `NetworkingConfig`, but only if they don't exist (this is why status of `createNetwork` is ignored), and by removing any created networks afterwards.

commit21dd26c0c4f838e4a94e5a98d3abf196c7d2dfed authorAlex K <flskif@gmail.com> dateMon 18 Jun 2018, 23:07 (8 years ago) parent84732d3
1 file changed+6
tests/tests.hs+6
tests/tests.hs+6
@@ -2,6 +2,7 @@
22
33module Main where
44
5+import Data.Either (rights)
56import Prelude hiding (all)
67import qualified Test.QuickCheck.Monadic as QCM
78import Test.Tasty
@@ -100,6 +101,7 @@ testRunAndReadLogHelper :: NetworkingConfig -> IO ()
100101testRunAndReadLogHelper networkingConfig =
101102 runDocker $
102103 do let containerConfig = (defaultContainerConfig (testImageName <> ":latest")) {env = [EnvVar "TEST" "123"]}
104+ createdNetworks <- rights <$> mapM createNetworkWithName networkNames
103105 containerId <- createContainer (CreateOpts containerConfig defaultHostConfig networkingConfig) Nothing
104106 c <- fromRight containerId
105107 status1 <- startContainer defaultStartOpts c
@@ -110,9 +112,13 @@ testRunAndReadLogHelper networkingConfig =
110112 lift $ assert $ (C.pack "123") `C.isInfixOf` (toStrict1 logs)
111113 status3 <- deleteContainer (DeleteOpts True True) c
112114 lift $ assertBool ("deleting container, unexpected status: " ++ show status3) $ isRightUnit status3
115+ mapM_ removeNetwork createdNetworks
113116 where
114117 isRightUnit (Right ()) = True
115118 isRightUnit _ = False
119+ networkNames = HM.keys $ endpointsConfig networkingConfig
120+ createNetworkWithName name = createNetwork $
121+ (defaultCreateNetworkOpts name) { createNetworkCheckDuplicate = True }
116122
117123testCreateRemoveNetwork :: IO ()
118124testCreateRemoveNetwork = do