on master help sign in
Use ‘runReq’ for testing with custom configuration
b713732mrkkrp
httpbin-tests/Network/HTTP/ReqSpec.hs+6−17
@@ -323,40 +323,29 @@ spec = do
323instance MonadHttp IO where
323instance MonadHttp IO where
324 handleHttpException = throwIO
324 handleHttpException = throwIO
325
325
326−instance MonadHttp (ReaderT HttpConfig IO) where
327− handleHttpException = liftIO . throwIO
328− getHttpConfig = ask
329−
330----------------------------------------------------------------------------
326----------------------------------------------------------------------------
331-- Helpers
327-- Helpers
332
328
333-- | Run request with such settings that it does not signal error on adverse
329-- | Run request with such settings that it does not signal error on adverse
334-- response status codes.
330-- response status codes.
335
331
336−prepareForShit
332+prepareForShit :: Req a -> IO a
337− :: ReaderT HttpConfig IO a
338− -> IO a
339−prepareForShit m = runReaderT m def { httpConfigCheckResponse = noNoise }
333+prepareForShit = runReq def { httpConfigCheckResponse = noNoise }
340 where
334 where
341 noNoise _ _ = return ()
335 noNoise _ _ = return ()
342
336
343-- | Run request with such settings that it throws on any response.
337-- | Run request with such settings that it throws on any response.
344
338
345−blindlyThrowing
339+blindlyThrowing :: Req a -> IO a
346− :: ReaderT HttpConfig IO a
347− -> IO a
348−blindlyThrowing m = runReaderT m def { httpConfigCheckResponse = doit }
340+blindlyThrowing = runReq def { httpConfigCheckResponse = doit }
349 where
341 where
350 doit _ _ = error "Oops!"
342 doit _ _ = error "Oops!"
351
343
352-- | Run request with such settings that every retry increments the given
344-- | Run request with such settings that every retry increments the given
353-- @'IORef' 'Int'@.
345-- @'IORef' 'Int'@.
354
346
355−countingRetries
347+countingRetries :: IORef Int -> Req a -> IO a
356− :: IORef Int
357− -> ReaderT HttpConfig IO a
358− -> IO a
359−countingRetries nref m = runReaderT m def
348+countingRetries nref = runReq def
360 { httpConfigCheckResponse = noNoise
349 { httpConfigCheckResponse = noNoise
361 , httpConfigRetryPolicy = R.constantDelay 50000 <> R.limitRetries 5
350 , httpConfigRetryPolicy = R.constantDelay 50000 <> R.limitRetries 5
362 , httpConfigRetryJudge = judge }
351 , httpConfigRetryJudge = judge }
pure-tests/Network/HTTP/ReqSpec.hs+1−6
@@ -17,7 +17,6 @@ module Network.HTTP.ReqSpec
17where
17where
18
18
19import Control.Exception (throwIO)
19import Control.Exception (throwIO)
20−import Control.Monad.Reader
21import Data.Aeson (ToJSON (..))
20import Data.Aeson (ToJSON (..))
22import Data.ByteString (ByteString)
21import Data.ByteString (ByteString)
23import Data.Default.Class
22import Data.Default.Class
@@ -54,7 +53,7 @@ spec = do
54 describe "config" $
53 describe "config" $
55 it "getHttpConfig has effect on resulting request" $
54 it "getHttpConfig has effect on resulting request" $
56 property $ \config -> do
55 property $ \config -> do
57− request <- runReaderT (req_ GET url NoReqBody mempty) config
56+ request <- runReq config (req_ GET url NoReqBody mempty)
58 L.proxy request `shouldBe` httpConfigProxy config
57 L.proxy request `shouldBe` httpConfigProxy config
59 L.redirectCount request `shouldBe` httpConfigRedirectCount config
58 L.redirectCount request `shouldBe` httpConfigRedirectCount config
60
59
@@ -296,10 +295,6 @@ spec = do
296instance MonadHttp IO where
295instance MonadHttp IO where
297 handleHttpException = throwIO
296 handleHttpException = throwIO
298
297
299−instance MonadHttp (ReaderT HttpConfig IO) where
300− handleHttpException = liftIO . throwIO
301− getHttpConfig = ask
302−
303instance Arbitrary HttpConfig where
298instance Arbitrary HttpConfig where
304 arbitrary = do
299 arbitrary = do
305 httpConfigProxy <- arbitrary
300 httpConfigProxy <- arbitrary