@@ -23,14 +23,15 @@ import Data.Monoid
23import Data.Proxy
23import Data.Proxy
24import qualified Data.Text as T
24import qualified Data.Text as T
25import GHC.Generics
25import GHC.Generics
26−import Network.HTTP.Client (HttpException(..))
26+import qualified Network.HTTP.Client as C
27import Network.HTTP.Media
27import Network.HTTP.Media
28import Network.HTTP.Types
28import Network.HTTP.Types
29import Network.Socket
29import Network.Socket
30−import Network.Wai
30+import Network.Wai hiding (Response)
31import Network.Wai.Handler.Warp
31import Network.Wai.Handler.Warp
32import Test.Hspec
32import Test.Hspec
33import Test.Hspec.QuickCheck
33import Test.Hspec.QuickCheck
34import Test.QuickCheck
35import Test.QuickCheck
36import Servant.API
37import Servant.API
@@ -64,7 +65,7 @@ instance FromFormUrlEncoded Person where
65deriving instance Eq ServantError
66deriving instance Eq ServantError
67−instance Eq HttpException where
68+instance Eq C.HttpException where
68 a == b = show a == show b
69 a == b = show a == show b
70alice :: Person
71alice :: Person
@@ -128,8 +129,8 @@ getQueryFlag :: Bool -> BaseUrl -> EitherT ServantError IO Bool
128getMatrixParam :: Maybe String -> BaseUrl -> EitherT ServantError IO Person
129getMatrixParam :: Maybe String -> BaseUrl -> EitherT ServantError IO Person
129getMatrixParams :: [String] -> BaseUrl -> EitherT ServantError IO [Person]
130getMatrixParams :: [String] -> BaseUrl -> EitherT ServantError IO [Person]
130getMatrixFlag :: Bool -> BaseUrl -> EitherT ServantError IO Bool
131getMatrixFlag :: Bool -> BaseUrl -> EitherT ServantError IO Bool
131−getRawSuccess :: Method -> BaseUrl -> EitherT ServantError IO (Int, ByteString, MediaType)
132+getRawSuccess :: Method -> BaseUrl -> EitherT ServantError IO (Int, ByteString, MediaType, C.Response ByteString)
132−getRawFailure :: Method -> BaseUrl -> EitherT ServantError IO (Int, ByteString, MediaType)
133+getRawFailure :: Method -> BaseUrl -> EitherT ServantError IO (Int, ByteString, MediaType, C.Response ByteString)
133getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])]
134getMultiple :: String -> Maybe Int -> Bool -> [(String, [Rational])]
134 -> BaseUrl
135 -> BaseUrl
135 -> EitherT ServantError IO (String, Maybe Int, Bool, [(String, [Rational])])
136 -> EitherT ServantError IO (String, Maybe Int, Bool, [(String, [Rational])])
@@ -211,12 +212,22 @@ spec = do
211 Arrow.left show <$> runEitherT (getMatrixFlag flag host) `shouldReturn` Right flag
212 Arrow.left show <$> runEitherT (getMatrixFlag flag host) `shouldReturn` Right flag
213 it "Servant.API.Raw on success" $ withServer $ \ host -> do
214 it "Servant.API.Raw on success" $ withServer $ \ host -> do
214− (Arrow.left show <$> runEitherT (getRawSuccess methodGet host))
215+ res <- runEitherT (getRawSuccess methodGet host)
217+ Left e -> assertFailure $ show e
218+ Right (code, body, ct, response) -> do
215− `shouldReturn` Right (200, "rawSuccess", "application"//"octet-stream")
219+ (code, body, ct) `shouldBe` (200, "rawSuccess", "application"//"octet-stream")
220+ C.responseBody response `shouldBe` body
221+ C.responseStatus response `shouldBe` ok200
217 it "Servant.API.Raw on failure" $ withServer $ \ host -> do
223 it "Servant.API.Raw on failure" $ withServer $ \ host -> do
218− (Arrow.left show <$> runEitherT (getRawFailure methodGet host))
224+ res <- runEitherT (getRawFailure methodGet host)
226+ Left e -> assertFailure $ show e
227+ Right (code, body, ct, response) -> do
219− `shouldReturn` Right (400, "rawFailure", "application"//"octet-stream")
228+ (code, body, ct) `shouldBe` (400, "rawFailure", "application"//"octet-stream")
229+ C.responseBody response `shouldBe` body
230+ C.responseStatus response `shouldBe` badRequest400
221 modifyMaxSuccess (const 20) $ do
232 modifyMaxSuccess (const 20) $ do
222 it "works for a combination of Capture, QueryParam, QueryFlag and ReqBody" $
233 it "works for a combination of Capture, QueryParam, QueryFlag and ReqBody" $
@@ -262,7 +273,7 @@ spec = do
262 Right host <- return $ parseBaseUrl "127.0.0.1:987654"
273 Right host <- return $ parseBaseUrl "127.0.0.1:987654"
263 Left res <- runEitherT (getGet host)
274 Left res <- runEitherT (getGet host)
264 case res of
275 case res of
265− ConnectionError (FailedConnectionException2 "127.0.0.1" 987654 False _) -> return ()
276+ ConnectionError (C.FailedConnectionException2 "127.0.0.1" 987654 False _) -> return ()
266 _ -> fail $ "expected ConnectionError, but got " <> show res
277 _ -> fail $ "expected ConnectionError, but got " <> show res
268 it "reports UnsupportedContentType" $ withFailServer $ \ host -> do
279 it "reports UnsupportedContentType" $ withFailServer $ \ host -> do