on master help sign in
I want even higher coverage
b94e47fmrkkrp
httpbin-tests/Network/HTTP/ReqSpec.hs+29−6
@@ -47,6 +47,7 @@ import Control.Monad.Reader
47import Data.Aeson (Value (..), ToJSON (..), object, (.=))
47import Data.Aeson (Value (..), ToJSON (..), object, (.=))
48import Data.Default.Class
48import Data.Default.Class
49import Data.Monoid ((<>))
49import Data.Monoid ((<>))
50+import Data.Proxy
50import Data.Text (Text)
51import Data.Text (Text)
51import Network.HTTP.Req
52import Network.HTTP.Req
52import Test.Hspec
53import Test.Hspec
@@ -117,6 +118,7 @@ spec = do
117 , "headers" .= object
118 , "headers" .= object
118 [ "Accept-Encoding" .= ("gzip" :: Text)
119 [ "Accept-Encoding" .= ("gzip" :: Text)
119 , "Host" .= ("httpbin.org" :: Text) ] ]
120 , "Host" .= ("httpbin.org" :: Text) ] ]
121+ responseHeader r "Content-Type" `shouldBe` return "application/json"
120 responseStatusCode r `shouldBe` 200
122 responseStatusCode r `shouldBe` 200
121 responseStatusMessage r `shouldBe` "OK"
123 responseStatusMessage r `shouldBe` "OK"
122
124
@@ -137,6 +139,9 @@ spec = do
137 , "Content-Length" .= show (T.length reflected) ]
139 , "Content-Length" .= show (T.length reflected) ]
138 , "files" .= emptyObject
140 , "files" .= emptyObject
139 , "form" .= emptyObject ]
141 , "form" .= emptyObject ]
142+ responseHeader r "Content-Type" `shouldBe` return "application/json"
143+ responseStatusCode r `shouldBe` 200
144+ responseStatusMessage r `shouldBe` "OK"
140
145
141 describe "receiving PATCHed file back" $
146 describe "receiving PATCHed file back" $
142 it "works" $ do
147 it "works" $ do
@@ -155,11 +160,15 @@ spec = do
155 , "Content-Length" .= show (T.length contents) ]
160 , "Content-Length" .= show (T.length contents) ]
156 , "files" .= emptyObject
161 , "files" .= emptyObject
157 , "form" .= emptyObject ]
162 , "form" .= emptyObject ]
163+ responseHeader r "Content-Type" `shouldBe` return "application/json"
164+ responseStatusCode r `shouldBe` 200
165+ responseStatusMessage r `shouldBe` "OK"
158
166
159 describe "receiving PUT form URL-encoded data back" $
167 describe "receiving PUT form URL-encoded data back" $
160 it "works" $ do
168 it "works" $ do
161 let params = "foo" =: ("bar" :: Text) <>
169 let params = "foo" =: ("bar" :: Text) <>
162− "baz" =: (5 :: Int)
170+ "baz" =: (5 :: Int) <>
171+ queryFlag "quux"
163 r <- req PUT (httpbin /: "put") (ReqBodyUrlEnc params) jsonResponse mempty
172 r <- req PUT (httpbin /: "put") (ReqBodyUrlEnc params) jsonResponse mempty
164 stripOrigin (responseBody r) `shouldBe` object
173 stripOrigin (responseBody r) `shouldBe` object
165 [ "args" .= emptyObject
174 [ "args" .= emptyObject
@@ -170,11 +179,15 @@ spec = do
170 [ "Content-Type" .= ("application/x-www-form-urlencoded" :: Text)
179 [ "Content-Type" .= ("application/x-www-form-urlencoded" :: Text)
171 , "Accept-Encoding" .= ("gzip" :: Text)
180 , "Accept-Encoding" .= ("gzip" :: Text)
172 , "Host" .= ("httpbin.org" :: Text)
181 , "Host" .= ("httpbin.org" :: Text)
173− , "Content-Length" .= ("13" :: Text) ]
182+ , "Content-Length" .= ("18" :: Text) ]
174 , "files" .= emptyObject
183 , "files" .= emptyObject
175 , "form" .= object
184 , "form" .= object
176 [ "foo" .= ("bar" :: Text)
185 [ "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"
178
191
179 -- TODO /delete
192 -- TODO /delete
180
193
@@ -248,16 +261,26 @@ spec = do
248 -- TODO /deny
261 -- TODO /deny
249 -- TODO /cache
262 -- TODO /cache
250
263
251− describe "getting random bytes" $
264+ describe "getting random bytes" $ do
252 it "works" $
265 it "works" $
253 property $ \n' -> do
266 property $ \n' -> do
254 let n :: Word
267 let n :: Word
255 n = getSmall n'
268 n = getSmall n'
256 r <- req GET (httpbin /: "bytes" /~ n)
269 r <- req GET (httpbin /: "bytes" /~ n)
257− NoReqBody bsResponse mempty
270+ NoReqBody lbsResponse mempty
258− responseBody r `shouldSatisfy` ((== n) . fromIntegral . B.length)
271+ responseBody r `shouldSatisfy` ((== n) . fromIntegral . BL.length)
259 responseStatusCode r `shouldBe` 200
272 responseStatusCode r `shouldBe` 200
260 responseStatusMessage r `shouldBe` "OK"
273 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
261
284
262 describe "streaming random bytes" $
285 describe "streaming random bytes" $
263 it "works" $
286 it "works" $