Skip to content

Commit

Permalink
Merge pull request #92 from mbg/enable-integration-tests
Browse files Browse the repository at this point in the history
Enable integration tests in CI
  • Loading branch information
denibertovic authored Apr 1, 2022
2 parents ad08763 + d57244f commit 16924c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ jobs:
stack --stack-yaml=${{ matrix.resolver }}.yaml --no-terminal build --fast --test --no-run-tests
- name: Test
run: stack --stack-yaml=${{ matrix.resolver }}.yaml --no-terminal test --fast
run: |
export RUN_INTEGRATION_TESTS=1
stack --stack-yaml=${{ matrix.resolver }}.yaml --no-terminal test --fast
25 changes: 15 additions & 10 deletions src/Docker/Client/Http.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ httpHandler manager = HttpHandler $ \request' sink -> do -- runResourceT ..
#endif
Left e -> return $ Left $ GenericDockerError (T.pack $ show e)

-- | Use 'httpHandler' with 'defaultUnixManagerSettings' @unixSocketPath@ as
-- argument as an alternative to 'unixHttpHandler' that lets you customise
-- the settings of the 'HTTP.ManagerSettings' value that is returned.
defaultUnixManagerSettings :: FilePath -- ^ The socket to connect to
-> HTTP.ManagerSettings
defaultUnixManagerSettings fp = defaultManagerSettings {
managerRawConnection = return $ openUnixSocket fp
} where openUnixSocket filePath _ _ _ = do
s <- S.socket S.AF_UNIX S.Stream S.defaultProtocol
S.connect s (S.SockAddrUnix filePath)
makeConnection (SBS.recv s 8096)
(SBS.sendAll s)
(S.close s)

-- | Connect to a unix domain socket (the default docker socket is
-- at \/var\/run\/docker.sock)
--
Expand All @@ -145,19 +159,10 @@ unixHttpHandler :: (
MonadIO m, MonadMask m) => FilePath -- ^ The socket to connect to
-> m (HttpHandler m)
unixHttpHandler fp = do
let mSettings = defaultManagerSettings
{ managerRawConnection = return $ openUnixSocket fp}
let mSettings = defaultUnixManagerSettings fp
manager <- liftIO $ newManager mSettings
return $ httpHandler manager

where
openUnixSocket filePath _ _ _ = do
s <- S.socket S.AF_UNIX S.Stream S.defaultProtocol
S.connect s (S.SockAddrUnix filePath)
makeConnection (SBS.recv s 8096)
(SBS.sendAll s)
(S.close s)

-- TODO:
-- Move this to http-client-tls or network?
-- Add CA.
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ runDocker f
-- let settings = mkManagerSettings (TLSSettings params) Nothing
-- mgr <- newManager settings
= do
h <- defaultHttpHandler
h <- unixHttpHandler "/var/run/docker.sock"
runDockerT (defaultClientOpts, h) f

testDockerVersion :: IO ()
Expand Down

0 comments on commit 16924c5

Please sign in to comment.