sydtest-amqp-0.1.0.0: An amqp companion library for sydtest
Safe HaskellNone
LanguageHaskell2010

Test.Syd.AMQP

Synopsis

Documentation

amqpSpec :: TestDefM (RabbitMQHandle ': outers) Connection result -> TestDefM outers inner result Source #

Run a rabbitmq server around a group of test, and provide a clean connection to each individual test

Example usage

spec :: Spec
spec =
  describe "amqpSpec" $ do
    it "can write and read a message" $ \conn -> do
      chan <- openChannel conn

      -- declare a queue, exchange and binding
      _ <- declareQueue chan newQueue {queueName = "myQueue"}
      declareExchange chan newExchange {exchangeName = "myExchange", exchangeType = "direct"}
      bindQueue chan "myQueue" "myExchange" "myKey"

      -- publish a message to our new exchange
      let body = "hello world"
      _ <-
        publishMsg
          chan
          "myExchange"
          "myKey"
          newMsg
            { msgBody = body,
              msgDeliveryMode = Just Persistent
            }

      mMesg <- getMsg chan Ack "myQueue"
      case mMesg of
        Nothing -> expectationFailure "Should have received a message"
        Just (m, e) -> do
          msgBody m `shouldBe` body
          ackEnv e

amqpConnectionSetupFunc :: RabbitMQHandle -> SetupFunc Connection Source #

Setup function for a connection to a given rabbitmq server