on master help sign in
I want even higher coverage
commitb94e47f9560e47c1b15b876b49af28eeb182716f authormrkkrp <markkarpov@opmbx.org> dateWed 9 Nov 2016, 20:17 (10 years ago) parent07ad098
1 file changed+29−6
httpbin-tests/Network/HTTP/ReqSpec.hs+29−6
httpbin-tests/Network/HTTP/ReqSpec.hs+29−6
@@ -47,6 +47,7 @@ import Control.Monad.Reader
4747import Data.Aeson (Value (..), ToJSON (..), object, (.=))
4848import Data.Default.Class
4949import Data.Monoid ((<>))
50+import Data.Proxy
5051import Data.Text (Text)
5152import Network.HTTP.Req
5253import Test.Hspec
@@ -117,6 +118,7 @@ spec = do
117118 , "headers" .= object
118119 [ "Accept-Encoding" .= ("gzip" :: Text)
119120 , "Host" .= ("httpbin.org" :: Text) ] ]
121+ responseHeader r "Content-Type" `shouldBe` return "application/json"
120122 responseStatusCode r `shouldBe` 200
121123 responseStatusMessage r `shouldBe` "OK"
122124
@@ -137,6 +139,9 @@ spec = do
137139 , "Content-Length" .= show (T.length reflected) ]
138140 , "files" .= emptyObject
139141 , "form" .= emptyObject ]
142+ responseHeader r "Content-Type" `shouldBe` return "application/json"
143+ responseStatusCode r `shouldBe` 200
144+ responseStatusMessage r `shouldBe` "OK"
140145
141146 describe "receiving PATCHed file back" $
142147 it "works" $ do
@@ -155,11 +160,15 @@ spec = do
155160 , "Content-Length" .= show (T.length contents) ]
156161 , "files" .= emptyObject
157162 , "form" .= emptyObject ]
163+ responseHeader r "Content-Type" `shouldBe` return "application/json"
164+ responseStatusCode r `shouldBe` 200
165+ responseStatusMessage r `shouldBe` "OK"
158166
159167 describe "receiving PUT form URL-encoded data back" $
160168 it "works" $ do
161169 let params = "foo" =: ("bar" :: Text) <>
162− "baz" =: (5 :: Int)
170+ "baz" =: (5 :: Int) <>
171+ queryFlag "quux"
163172 r <- req PUT (httpbin /: "put") (ReqBodyUrlEnc params) jsonResponse mempty
164173 stripOrigin (responseBody r) `shouldBe` object
165174 [ "args" .= emptyObject
@@ -170,11 +179,15 @@ spec = do
170179 [ "Content-Type" .= ("application/x-www-form-urlencoded" :: Text)
171180 , "Accept-Encoding" .= ("gzip" :: Text)
172181 , "Host" .= ("httpbin.org" :: Text)
173− , "Content-Length" .= ("13" :: Text) ]
182+ , "Content-Length" .= ("18" :: Text) ]
174183 , "files" .= emptyObject
175184 , "form" .= object
176185 [ "foo" .= ("bar" :: Text)
177− , "baz" .= ("5" :: Text) ] ]
186+ , "baz" .= ("5" :: Text)
187+ , "quux" .= ("" :: Text) ] ]
188+ responseHeader r "Content-Type" `shouldBe` return "application/json"
189+ responseStatusCode r `shouldBe` 200
190+ responseStatusMessage r `shouldBe` "OK"
178191
179192 -- TODO /delete
180193
@@ -248,16 +261,26 @@ spec = do
248261 -- TODO /deny
249262 -- TODO /cache
250263
251− describe "getting random bytes" $
264+ describe "getting random bytes" $ do
252265 it "works" $
253266 property $ \n' -> do
254267 let n :: Word
255268 n = getSmall n'
256269 r <- req GET (httpbin /: "bytes" /~ n)
257− NoReqBody bsResponse mempty
258− responseBody r `shouldSatisfy` ((== n) . fromIntegral . B.length)
270+ NoReqBody lbsResponse mempty
271+ responseBody r `shouldSatisfy` ((== n) . fromIntegral . BL.length)
259272 responseStatusCode r `shouldBe` 200
260273 responseStatusMessage r `shouldBe` "OK"
274+ context "when we try to interpret 1000 random bytes as JSON" $
275+ it "throws correct exception" $ do
276+ let selector :: HttpException -> Bool
277+ selector (JsonHttpException _) = True
278+ selector _ = False
279+ n :: Int
280+ n = 1000
281+ req GET (httpbin /: "bytes" /~ n) NoReqBody
282+ (Proxy :: Proxy (JsonResponse Value)) mempty
283+ `shouldThrow` selector
261284
262285 describe "streaming random bytes" $
263286 it "works" $