Movatterモバイル変換


[0]ホーム

URL:


Hackage :: [Package]

servant-routes-golden:Golden test your Servant APIs using `servant-routes`

[bsd3,library,servant,web ] [Propose Tags ] [Report a vulnerability ]

See the documentation ofServant.API.Routes.Golden.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions[RSS]0.1.0.0
Change logCHANGELOG.md
Dependenciesaeson (>=2.0 && <2.3),aeson-pretty (>=0.8.8 && <0.9),base (>=4.13 && <5),hspec-core (>=2.10.0 && <2.12),hspec-golden (>=0.2 && <0.3),servant-routes (>=0.1.0.0 && <0.2),text (>=1.2 && <2.2) [details]
Tested with ghc ==8.8.4, ghc ==8.10.7, ghc ==9.0.2, ghc ==9.2.4, ghc ==9.2.8, ghc ==9.4.2, ghc ==9.4.5, ghc ==9.6.1, ghc ==9.6.7, ghc ==9.8.2, ghc ==9.10.2, ghc ==9.12.2
LicenseBSD-3-Clause
CopyrightCopyright(c) Frederick Pringle 2025
AuthorFrederick Pringle
Maintainerfreddyjepringle@gmail.com
Uploadedbyfpringle at2025-06-10T09:00:46Z
CategoryServant,Web
Home pagehttps://github.com/fpringle/servant-routes
Bug trackerhttps://github.com/fpringle/servant-routes/issues
Source repohead: git clonehttps://github.com/fpringle/servant-routes(servant-routes-golden)
Distributions
Downloads17 total (1 in the last 30 days)
Rating(no votes yet)[estimated byBayesian average]
Your Rating
  • λ
  • λ
  • λ
StatusDocs uploaded by user
Build status unknown[no reports yet]

Readme for servant-routes-golden-0.1.0.0

[back to package description]

servant-routes-golden

This package lets us defineGolden tests using theHasRoutes class fromservant-routes and thehspec-golden library.

SeeServant.API.Routes.Golden for reference documentation.

Example

-- file src/API.hsmodule API whereimport Servant.APItype UserAPI =  "users"    :> ( "list" :> Get '[JSON] [User]          :<|> "create" :> ReqBody '[JSON] UserCreateData :> Post '[JSON] UserID          :<|> "detail" :> QueryParam' '[Required] "id" UserID :> Get '[JSON] User       )-- file test/APISpec.hsmodule APISpec whereimport APIimport Servant.API.Routes.Goldenimport Hspecspec :: Specspec =  it "UserAPI" $ goldenRoutes @UserAPI (show ''UserAPI)

We can runcabal test to generate the starting "golden file":

$ cabal testAPI  UserAPI [✔]    First time execution. Golden file created.

Of course, if we run the test again, it should pass:

$ cabal testAPI  UserAPI [✔]    Golden and Actual output didn't change

But let's say we change the API definition slightly:

type UserAPI =  "users"    :> ( "list" :> Get '[JSON] [User]-          :<|> "create" :> ReqBody '[JSON] UserCreateData :> Post '[JSON] UserID+          :<|> "create-new" :> ReqBody '[JSON] UserCreateData :> Post '[JSON] UserID          :<|> "detail" :> QueryParam' '[Required] "id" UserID :> Get '[JSON] User       )

Then when we run the tests again:

$ cabal testAPI  UserAPI [✘]    Files golden and actual not matchFailures:  test/APISpec.hs:9:3:   1) Servant.API.Routes.Golden UserAPI       expected: {                     "/users/create": {                         "POST": {                             "auths": [],                             "description": null,                             "method": "POST",                             "params": [],                             "path": "/users/create",                             "request_body": "UserCreateData",                             "request_headers": [],                             "response": {                 @@ 45 lines omitted @@                         but got: {                     "/users/create-new": {                         "POST": {                             "auths": [],                             "description": null,                             "method": "POST",                             "params": [],                             "path": "/users/create-new",                             "request_body": "UserCreateData",                             "request_headers": [],                             "response": {                 @@ 45 lines omitted @@

This forces us to either:

  • acknowledge that the golden files should be updated, and do so by running thehgold CLI, or
  • realise that our changes resulted in a change to the API which we didn't anticipate, so we have to fix them.

Produced byhackage andCabal 3.16.1.0.


[8]ページ先頭

©2009-2026 Movatter.jp