git.iko.soy/typeable/servant
on master help sign in
test suite: testing Client of Capture
cb1772fSönke Hahn
test/Servant/ClientSpec.hs+15−7
@@ -14,29 +14,37 @@ import Network.Wai.Handler.Warp
14import Test.Hspec
14import Test.Hspec
15
15
16import Servant.Client
16import Servant.Client
17−import Servant.API.Sub
17+import Servant.API
18−import Servant.API.Get
19import Servant.Server
18import Servant.Server
20
19
21import Servant.ServerSpec
20import Servant.ServerSpec
22
21
23type Api =
22type Api =
24− "a" :> Get Person
23+ ("a" :> Get Person)
24+ :<|> ("b" :> Capture "name" String :> Get Person)
25api :: Proxy Api
25api :: Proxy Api
26api = Proxy
26api = Proxy
27
27
28server :: Application
28server :: Application
29server = serve api (
29server = serve api (
30− return alice
30+ return alice
31+ :<|> (\ name -> return $ Person name 0)
31 )
32 )
32
33
34+withServer :: (URIAuth -> IO a) -> IO a
35+withServer action = withWaiDaemon (return server) (action . mkHost "localhost")
36+
33getA :: URIAuth -> EitherT String IO Person
37getA :: URIAuth -> EitherT String IO Person
38+getB :: String -> URIAuth -> EitherT String IO Person
34−getA = client api
39+(getA :<|> getB) = client api
35
40
36spec :: Spec
41spec :: Spec
37spec = do
42spec = do
38− it "Servant.API.Get" $ withWaiDaemon (return server) $ \ port -> do
43+ it "Servant.API.Get" $ withServer $ \ host -> do
39− runEitherT (getA (mkHost "localhost" port)) `shouldReturn` Right alice
44+ runEitherT (getA host) `shouldReturn` Right alice
45+
46+ it "Servant.API.Capture" $ withServer $ \ host -> do
47+ runEitherT (getB "Paula" host) `shouldReturn` Right (Person "Paula" 0)
40
48
41
49
42-- * utils
50-- * utils