on master help sign in
add servant-generic test
commit8f542bc3effb5331c0fc83617750d03f81a1ea4b authorMark Wotton <mwotton@gmail.com> dateSat 28 Nov 2020, 10:54 (6 years ago) parentbada8f0
2 files changed+28−1
test/Spec.hs+4 test/Valid.hs+24−1
test/Spec.hs+4
@@ -43,6 +43,10 @@ spec = do
4343 it "finds no error in a valid app" $ do
4444 RS.fuzz @Valid.Api Valid.server defaultConfig noCheck
4545 >>= (`shouldSatisfy` isNothing)
46+ it "finds no error in a valid generic app" $ do
47+ RS.fuzz @Valid.RoutedApi Valid.routedServer defaultConfig noCheck
48+ >>= (`shouldSatisfy` isNothing)
49+
4650 it "does fail coverage check" $ do
4751 r <- RS.fuzz @Valid.Api Valid.server defaultConfig { RS.coverageThreshold = 0.6 } noCheck
4852 fmap (RS.failureReason . RS.rsException) r `shouldSatisfy`
test/Valid.hs+24−1
@@ -9,9 +9,32 @@ module Valid where
99
1010import Servant
1111import Data.Void
12+import GHC.Generics
13+import Servant.API.Generic
14+import Servant.Server.Generic
1215
1316type Api = Get '[JSON] Int
1417 :<|> Capture "void" Void :> Get '[JSON] ()
15−
18+
19+data Routes route
20+ = Routes
21+ { getInt :: route :-
22+ Get '[JSON] Int
23+ , captureIt :: route :-
24+ Capture "void" Void :> Get '[JSON] ()
25+ } deriving Generic
26+
27+type RoutedApi = ToServantApi Routes
28+
29+-- routedApi = genericApi (Proxy :: Proxy Routes)
30+routedServer :: Server RoutedApi
31+routedServer = genericServer routes
32+
33+routes :: Routes AsServer
34+routes = Routes
35+ { getInt = pure 7
36+ , captureIt = const (pure ())
37+ }
38+
1639server :: Server Api
1740server = pure 7 :<|> const (pure ())