tmp-proc-rabbitmq (empty) → 0.5.0.0
raw patch · 8 files changed
+247/−0 lines, 8 filesdep +amqpdep +basedep +bytestringsetup-changed
Dependencies added: amqp, base, bytestring, hspec, hspec-tmp-proc, text, tmp-proc, tmp-proc-rabbitmq
Files
- ChangeLog.md +6/−0
- LICENSE +30/−0
- README.md +11/−0
- Setup.hs +2/−0
- src/System/TmpProc/Docker/RabbitMQ.hs +89/−0
- test/Spec.hs +12/−0
- test/Test/TmpProc/Docker/RabbitMQSpec.hs +41/−0
- tmp-proc-rabbitmq.cabal +56/−0
+ ChangeLog.md view
@@ -0,0 +1,6 @@+# Revision history for tmp-proc-rabbitmq++## 0.5.0.0 -- 2021-09-28++* First version+* Initial upload to hackage
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2021, Tim Emiola++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Tim Emiola nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,11 @@+# tmp-proc-rabbitmq++`tmp-proc-rabbitmq` provides an example of using `tmp-proc` to launch dockerized+RabbitMQ in integration tests.++It provides an instance of [Proc][1] for launching the RabbitMQ image, and also+provides an instance of [Conn][2] that simplifies opening connections to the+launched RabbitMQ service from tests that use `tmp-proc`.++[1]: https://hackage.haskell.org/package/tmp-proc-0.5.0.0/docs/System-TmpProc-Docker.html#t:Proc+[2]: https://hackage.haskell.org/package/tmp-proc-0.5.0.0/docs/System-TmpProc-Docker.html#t:Conn
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/System/TmpProc/Docker/RabbitMQ.hs view
@@ -0,0 +1,89 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE NamedFieldPuns #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeFamilies #-}+{-# OPTIONS_HADDOCK prune not-home #-}+{-|+Copyright : (c) 2020-2021 Tim Emiola+SPDX-License-Identifier: BSD3+Maintainer : Tim Emiola <adetokunbo@users.noreply.github.com >++Provides an instance of 'Proc' that launches @RabbitMQ@ as a @tmp proc@.++The instance this module provides can be used in integration tests as is.++It's also possible to write other instances that launch @RabbitMQ@ in different+ways; for those, this instance can be used as a reference example.++-}+module System.TmpProc.Docker.RabbitMQ+ ( -- * 'Proc' instance+ TmpRabbitMQ(..)++ -- * Useful definitions+ , aProc+ , aHandle++ -- * Re-exports+ , module System.TmpProc+ )+where++import qualified Data.ByteString.Char8 as C8+import Data.Proxy (Proxy(..))+import qualified Data.Text as Text++import Network.AMQP++import System.TmpProc (Connectable (..), HList (..), HandlesOf,+ HostIpAddress, Proc (..),+ ProcHandle (..), SvcURI, startupAll,+ toPinged, withTmpConn)+++{-| A singleton 'HList' containing a 'TmpRabbitMQ'. -}+aProc :: HList '[TmpRabbitMQ]+aProc = TmpRabbitMQ `HCons` HNil+++{-| An 'HList' that just contains the handle created by 'aProc'. -}+aHandle :: IO (HandlesOf '[TmpRabbitMQ])+aHandle = startupAll aProc+++{-| Provides the capability to launch a RabbitMQ instance as a @tmp proc@. -}+data TmpRabbitMQ = TmpRabbitMQ+++{-| Specifies how to run @RabbitMQ@ as a @tmp proc@. -}+instance Proc TmpRabbitMQ where+ type Image TmpRabbitMQ = "rabbitmq:3.9"+ type Name TmpRabbitMQ = "a-rabbitmq-server"++ uriOf = mkUri'+ runArgs = []+ ping = toPinged @AMQPException Proxy . openConn'+ reset _ = pure ()+ pingGap = 3 * 1000000+++{-| Specifies how to connect to a tmp @RabbitMQ@ service. -}+instance Connectable TmpRabbitMQ where+ type Conn TmpRabbitMQ = Connection++ openConn = openConn'+ closeConn = closeConnection+++{-| Makes a uri using the guest password . -}+mkUri' :: HostIpAddress -> SvcURI+mkUri' ip =+ "amqp://guest:guest@"+ <> C8.pack (Text.unpack ip)+ <> ":5672@/%2f"+++openConn' :: ProcHandle TmpRabbitMQ -> IO Connection+openConn' = openConnection'' . fromURI . C8.unpack . hUri
+ test/Spec.hs view
@@ -0,0 +1,12 @@+module Main (main) where++import Test.Hspec++import System.IO+import qualified Test.TmpProc.Docker.RabbitMQSpec as RMQ++main :: IO ()+main = do+ hSetBuffering stdin NoBuffering+ hSetBuffering stdout NoBuffering+ hspec RMQ.spec
+ test/Test/TmpProc/Docker/RabbitMQSpec.hs view
@@ -0,0 +1,41 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeApplications #-}+module Test.TmpProc.Docker.RabbitMQSpec where++import Test.Hspec+import Test.Hspec.TmpProc++import Data.Proxy (Proxy (..))+import qualified Data.Text as Text++import System.TmpProc.Docker.RabbitMQ+++spec :: Spec+spec = tdescribe desc $ do+ beforeAll setupHandles $ afterAll terminateAll $ do++ context "when using the Proc from the HList by its 'Name'" $ do++ context "ixPing" $ do++ it "should succeed" $ \hs+ -> ixPing @"a-rabbitmq-server" Proxy hs `shouldReturn` OK++ context "ixReset" $ do++ it "should succeed" $ \hs+ -> ixReset @"a-rabbitmq-server" Proxy hs `shouldReturn` ()+++setupHandles :: IO (HList '[ProcHandle TmpRabbitMQ])+setupHandles = startupAll $ testProc `HCons` HNil+++testProc :: TmpRabbitMQ+testProc = TmpRabbitMQ+++desc :: String+desc = "Tmp.Proc:RabbitMQ:" ++ Text.unpack (nameOf testProc)
+ tmp-proc-rabbitmq.cabal view
@@ -0,0 +1,56 @@+cabal-version: 3.0+name: tmp-proc-rabbitmq+version: 0.5.0.0+synopsis: Shows how to run RabbitMQ as a tmp proc+description:+ An example of using tmp-proc to launch dockerized RabbitMQ in integration tests.++license: BSD-3-Clause+license-file: LICENSE+copyright: 2021 Tim Emiola+author: Tim Emiola+maintainer: adetokunbo@users.noreply.github.com+category: testing+bug-reports: https://github.com/adetokunbo/tmp-proc/issues+build-type: Simple+extra-source-files:+ ChangeLog.md+ README.md+tested-with:+ GHC == 8.10.5++source-repository head+ type: git+ location: https://github.com/adetokunbo/tmp-proc.git++library+ exposed-modules: System.TmpProc.Docker.RabbitMQ+ hs-source-dirs: src+ build-depends:+ , amqp ^>=0.22+ , base >=4.11 && <4.16+ , bytestring >=0.10.8.2 && <0.12+ , text ^>=1.2.3+ , tmp-proc >=0.5.0.0 && <0.6.0.0++ default-language: Haskell2010+ ghc-options: -fno-ignore-asserts -Wall++test-suite integration-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules: Test.TmpProc.Docker.RabbitMQSpec+ hs-source-dirs: test+ build-depends:+ , amqp+ , base+ , bytestring+ , hspec+ , hspec-tmp-proc+ , text+ , tmp-proc+ , tmp-proc-rabbitmq++ default-language: Haskell2010+ ghc-options:+ -threaded -rtsopts -with-rtsopts=-N -fno-ignore-asserts -Wall