-
-
Save sshine/12ba219e94ea043aabf171b2918a1c07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE RecordWildCards #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module API where | |
import Servant | |
type API = "ping" :> Get '[JSON] Bool | |
api :: Proxy API | |
api = Proxy | |
app :: Application | |
app = serve api server | |
server :: Server API | |
server = ping | |
--ping :: Handler Bool | |
ping :: Server API | |
ping = pure True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
module APITest where | |
import Network.HTTP.Client | |
import Network.Wai | |
import qualified Network.Wai.Handler.Warp as Warp | |
--import Servant.Client.Core (BaseUrl(..)) | |
import Servant.Client -- (BaseUrl(..), runClientM) | |
import Test.Hspec | |
import API (app, api, ping) | |
withGrendelApp :: (Warp.Port -> IO ()) -> IO () | |
withGrendelApp = Warp.testWithApplication (pure app) | |
spec_businessLogic :: Spec | |
spec_businessLogic = do | |
around withGrendelApp $ do | |
let pingClient = client api | |
baseUrl <- runIO (parseBaseUrl "http://localhost") | |
manager <- runIO (newManager defaultManagerSettings) | |
let clientEnv port = mkClientEnv manager (baseUrl { baseUrlPort = port }) | |
describe "GET /ping" $ do | |
it "should reply with True" $ \port -> do | |
result <- runClientM ping (clientEnv port) | |
result `shouldBe` Right True |
Author
sshine
commented
Oct 31, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment