git.iko.soy/typeable/servant
on master help sign in
Clean up the comments
0d0fd0dErik Aker
doc/cookbook/testing/Testing.lhs+4−3
@@ -267,10 +267,12 @@ esTestApp = serve (Proxy :: Proxy SearchAPI) esTestServer
267esTestServer :: Server SearchAPI
267esTestServer :: Server SearchAPI
268esTestServer = getESDocument
268esTestServer = getESDocument
269
269
270+-- This is the *mock* handler we're going to use. We create it
271+-- here specifically to trigger different behavior in our tests.
270getESDocument :: Integer -> Handler Value
272getESDocument :: Integer -> Handler Value
271getESDocument docId
273getESDocument docId
272− -- arbitrary things we can trigger in our tests to check for failure
274+ -- arbitrary things we can use in our tests to simulate failure
273− -- We want to try to trigger different code paths
275+ -- We want to trigger different code paths
274 | docId > 1000 = throwError err500
276 | docId > 1000 = throwError err500
275 | docId > 500 = pure . Object $ HM.fromList [("bad", String "data")]
277 | docId > 500 = pure . Object $ HM.fromList [("bad", String "data")]
276 | otherwise = pure $ Object $ HM.fromList [("_source", Object $ HM.fromList [("a", String "b")])]
278 | otherwise = pure $ Object $ HM.fromList [("_source", Object $ HM.fromList [("a", String "b")])]
@@ -294,7 +296,6 @@ thirdPartyResourcesSpec = around_ withElasticsearch $ do
294 -- `get` is a function from hspec-wai`.
296 -- `get` is a function from hspec-wai`.
295 get "/docs/1" `shouldRespondWith` 200
297 get "/docs/1" `shouldRespondWith` 200
296 it "should be able to handle connection failures" $
298 it "should be able to handle connection failures" $
297− -- We can also make custom HTTP requests with the `request` function
298 get "/docs/1001" `shouldRespondWith` 404
299 get "/docs/1001" `shouldRespondWith` 404
299 it "should be able to handle parsing failures" $
300 it "should be able to handle parsing failures" $
300 get "/docs/501" `shouldRespondWith` 400
301 get "/docs/501" `shouldRespondWith` 400