on master help sign in
Use ‘runReq’ for testing with custom configuration
commitb7137326407edda0ba59c3e490f31ae967d11b21 authormrkkrp <markkarpov92@gmail.com> dateSun 22 Oct 2017, 14:19 (9 years ago) parentae4a2e2
2 files changed+7−23
httpbin-tests/Network/HTTP/ReqSpec.hs+6−17 pure-tests/Network/HTTP/ReqSpec.hs+1−6
httpbin-tests/Network/HTTP/ReqSpec.hs+6−17
@@ -323,40 +323,29 @@ spec = do
323323instance MonadHttp IO where
324324 handleHttpException = throwIO
325325
326−instance MonadHttp (ReaderT HttpConfig IO) where
327− handleHttpException = liftIO . throwIO
328− getHttpConfig = ask
329−
330326----------------------------------------------------------------------------
331327-- Helpers
332328
333329-- | Run request with such settings that it does not signal error on adverse
334330-- response status codes.
335331
336−prepareForShit
337− :: ReaderT HttpConfig IO a
338− -> IO a
339−prepareForShit m = runReaderT m def { httpConfigCheckResponse = noNoise }
332+prepareForShit :: Req a -> IO a
333+prepareForShit = runReq def { httpConfigCheckResponse = noNoise }
340334 where
341335 noNoise _ _ = return ()
342336
343337-- | Run request with such settings that it throws on any response.
344338
345−blindlyThrowing
346− :: ReaderT HttpConfig IO a
347− -> IO a
348−blindlyThrowing m = runReaderT m def { httpConfigCheckResponse = doit }
339+blindlyThrowing :: Req a -> IO a
340+blindlyThrowing = runReq def { httpConfigCheckResponse = doit }
349341 where
350342 doit _ _ = error "Oops!"
351343
352344-- | Run request with such settings that every retry increments the given
353345-- @'IORef' 'Int'@.
354346
355−countingRetries
356− :: IORef Int
357− -> ReaderT HttpConfig IO a
358− -> IO a
359−countingRetries nref m = runReaderT m def
347+countingRetries :: IORef Int -> Req a -> IO a
348+countingRetries nref = runReq def
360349 { httpConfigCheckResponse = noNoise
361350 , httpConfigRetryPolicy = R.constantDelay 50000 <> R.limitRetries 5
362351 , httpConfigRetryJudge = judge }
pure-tests/Network/HTTP/ReqSpec.hs+1−6
@@ -17,7 +17,6 @@ module Network.HTTP.ReqSpec
1717where
1818
1919import Control.Exception (throwIO)
20−import Control.Monad.Reader
2120import Data.Aeson (ToJSON (..))
2221import Data.ByteString (ByteString)
2322import Data.Default.Class
@@ -54,7 +53,7 @@ spec = do
5453 describe "config" $
5554 it "getHttpConfig has effect on resulting request" $
5655 property $ \config -> do
57− request <- runReaderT (req_ GET url NoReqBody mempty) config
56+ request <- runReq config (req_ GET url NoReqBody mempty)
5857 L.proxy request `shouldBe` httpConfigProxy config
5958 L.redirectCount request `shouldBe` httpConfigRedirectCount config
6059
@@ -296,10 +295,6 @@ spec = do
296295instance MonadHttp IO where
297296 handleHttpException = throwIO
298297
299−instance MonadHttp (ReaderT HttpConfig IO) where
300− handleHttpException = liftIO . throwIO
301− getHttpConfig = ask
302−
303298instance Arbitrary HttpConfig where
304299 arbitrary = do
305300 httpConfigProxy <- arbitrary