@@ -7,6 +7,7 @@ import Network.HTTP.Client (Manager, Request, checkStatus,
7 defaultManagerSettings, httpLbs,
7 defaultManagerSettings, httpLbs,
8 newManager)
8 newManager)
9import Network.Wai.Handler.Warp (withApplication)
9import Network.Wai.Handler.Warp (withApplication)
10import Servant (Context (EmptyContext), HasServer,
11import Servant (Context (EmptyContext), HasServer,
11 Server, serveWithContext)
12 Server, serveWithContext)
12import Servant.Client (BaseUrl (..), Scheme (..))
13import Servant.Client (BaseUrl (..), Scheme (..))
@@ -23,12 +24,16 @@ import Servant.QuickCheck.Internal.Equality
24-- | Start a servant application on an open port, run the provided function,
25-- | Start a servant application on an open port, run the provided function,
25-- then stop the application.
26-- then stop the application.
26withServantServer :: HasServer a '[] => Proxy a -> IO (Server a)
29withServantServer :: HasServer a '[] => Proxy a -> IO (Server a)
27 -> (BaseUrl -> IO r) -> IO r
30 -> (BaseUrl -> IO r) -> IO r
28withServantServer api = withServantServerAndContext api EmptyContext
31withServantServer api = withServantServerAndContext api EmptyContext
30-- | Like 'withServantServer', but allows passing in a 'Context' to the
33-- | Like 'withServantServer', but allows passing in a 'Context' to the
31-- application.
34-- application.
32withServantServerAndContext :: HasServer a ctx
37withServantServerAndContext :: HasServer a ctx
33 => Proxy a -> Context ctx -> IO (Server a) -> (BaseUrl -> IO r) -> IO r
38 => Proxy a -> Context ctx -> IO (Server a) -> (BaseUrl -> IO r) -> IO r
34withServantServerAndContext api ctx server t
39withServantServerAndContext api ctx server t
@@ -46,6 +51,8 @@ withServantServerAndContext api ctx server t
47-- Evidently, if the behaviour of the server is expected to be
52-- Evidently, if the behaviour of the server is expected to be
48-- non-deterministic, this function may produce spurious failures
53-- non-deterministic, this function may produce spurious failures
49serversEqual :: HasGenRequest a =>
56serversEqual :: HasGenRequest a =>
50 Proxy a -> BaseUrl -> BaseUrl -> Args -> ResponseEquality LBS.ByteString -> Expectation
57 Proxy a -> BaseUrl -> BaseUrl -> Args -> ResponseEquality LBS.ByteString -> Expectation
51serversEqual api burl1 burl2 args req = do
58serversEqual api burl1 burl2 args req = do
@@ -78,6 +85,8 @@ serversEqual api burl1 burl2 args req = do
78-- > <%> onlyJsonObjects
85-- > <%> onlyJsonObjects
79-- > <%> notAllowedContainsAllowHeader
86-- > <%> notAllowedContainsAllowHeader
80-- > <%> mempty)
87-- > <%> mempty)
81serverSatisfies :: (HasGenRequest a) =>
90serverSatisfies :: (HasGenRequest a) =>
82 Proxy a -> BaseUrl -> Args -> Predicates [Text] [Text] -> Expectation
91 Proxy a -> BaseUrl -> Args -> Predicates [Text] [Text] -> Expectation
83serverSatisfies api burl args preds = do
92serverSatisfies api burl args preds = do