Add server spec for NoContentVerbWithStatus
This commit is contained in:
parent
0a1d32d21e
commit
2f9fcdb45d
1 changed files with 19 additions and 11 deletions
|
@ -51,10 +51,11 @@ import Servant.API
|
|||
BasicAuthData (BasicAuthData), Capture, Capture', CaptureAll,
|
||||
Delete, EmptyAPI, Fragment, Get, HasStatus (StatusOf), Header,
|
||||
Headers, HttpVersion, IsSecure (..), JSON, Lenient,
|
||||
NoContent (..), NoContentVerb, NoFraming, OctetStream, Patch,
|
||||
PlainText, Post, Put, QueryFlag, QueryParam, QueryParams, Raw,
|
||||
RemoteHost, ReqBody, SourceIO, StdMethod (..), Stream, Strict,
|
||||
UVerb, Union, Verb, WithStatus (..), addHeader)
|
||||
NoContent (..), NoContentVerb, NoContentVerbWithStatus,
|
||||
NoFraming, OctetStream, Patch, PlainText, Post, Put,
|
||||
QueryFlag, QueryParam, QueryParams, Raw, RemoteHost, ReqBody,
|
||||
SourceIO, StdMethod (..), Stream, Strict, UVerb, Union, Verb,
|
||||
WithStatus (..), addHeader)
|
||||
import Servant.Server
|
||||
(Context ((:.), EmptyContext), Handler, Server, Tagged (..),
|
||||
emptyServer, err401, err403, err404, respond, serve,
|
||||
|
@ -109,19 +110,21 @@ spec = do
|
|||
------------------------------------------------------------------------------
|
||||
|
||||
type VerbApi method status
|
||||
= Verb method status '[JSON] Person
|
||||
:<|> "noContent" :> NoContentVerb method
|
||||
:<|> "header" :> Verb method status '[JSON] (Headers '[Header "H" Int] Person)
|
||||
:<|> "headerNC" :> Verb method status '[JSON] (Headers '[Header "H" Int] NoContent)
|
||||
:<|> "accept" :> ( Verb method status '[JSON] Person
|
||||
:<|> Verb method status '[PlainText] String
|
||||
)
|
||||
= Verb method status '[JSON] Person
|
||||
:<|> "noContent" :> NoContentVerb method
|
||||
:<|> "permanentRedirection" :> NoContentVerbWithStatus method 308
|
||||
:<|> "header" :> Verb method status '[JSON] (Headers '[Header "H" Int] Person)
|
||||
:<|> "headerNC" :> Verb method status '[JSON] (Headers '[Header "H" Int] NoContent)
|
||||
:<|> "accept" :> ( Verb method status '[JSON] Person
|
||||
:<|> Verb method status '[PlainText] String
|
||||
)
|
||||
:<|> "stream" :> Stream method status NoFraming OctetStream (SourceIO BS.ByteString)
|
||||
|
||||
verbSpec :: Spec
|
||||
verbSpec = describe "Servant.API.Verb" $ do
|
||||
let server :: Server (VerbApi method status)
|
||||
server = return alice
|
||||
:<|> return NoContent
|
||||
:<|> return NoContent
|
||||
:<|> return (addHeader 5 alice)
|
||||
:<|> return (addHeader 10 NoContent)
|
||||
|
@ -150,6 +153,11 @@ verbSpec = describe "Servant.API.Verb" $ do
|
|||
liftIO $ statusCode (simpleStatus response) `shouldBe` 204
|
||||
liftIO $ simpleBody response `shouldBe` ""
|
||||
|
||||
it "returns no content on Permanent Redirection" $ do
|
||||
response <- THW.request method "/permanentRedirection" [] ""
|
||||
liftIO $ statusCode (simpleStatus response) `shouldBe` 308
|
||||
liftIO $ simpleBody response `shouldBe` ""
|
||||
|
||||
-- HEAD should not return body
|
||||
when (method == methodHead) $
|
||||
it "HEAD returns no content body" $ do
|
||||
|
|
Loading…
Reference in a new issue