hedgehog-servant: Hedgehog property testing for Servant APIs

[ bsd3, library, testing ] [ Propose Tags ]

An adapter for using Hedgehog to create requests against Servant APIs.


[Skip to Readme]
Versions [faq] 0.0.0.1, 0.0.1.1
Change log CHANGELOG.md
Dependencies base (>=4.9 && <5), bytestring (==0.10.*), case-insensitive (==1.2.*), hedgehog (>=0.6 && <1.1), http-client (>=0.5.14 && <0.7), http-media (==0.8.*), http-types (==0.12.*), servant (>=0.16 && <0.19), servant-client (>=0.16 && <0.19), servant-server (>=0.16 && <0.19), string-conversions (==0.4.*), text (==1.2.*) [details]
License BSD-3-Clause
Copyright Felix Mulder
Author Felix Mulder
Maintainer felix.mulder@gmail.com
Category testing
Bug tracker https://github.com/felixmulder/hedgehog-servant
Source repo head: git clone git://github.com/felixmulder/hedgehog-servant.git
Uploaded by felixmulder at 2021-04-25T08:41:33Z
Distributions NixOS:0.0.1.1
Downloads 332 total (36 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for hedgehog-servant-0.0.1.1

[back to package description]

Hedgehog Servant

Hedgehog servant will eat all your servant bugs.

Basic Usage

Define your servant API endpoints and automatically derive request generators for them!

This is accomplished using the genRequest and the heterogeneous list, called GList, that contains all the generators needed for your API.

So, what do we actually need to do?

  1. Define our API (below SimplestApi).
  2. Define generators for each element that gets captured in the request.
  3. Call the function genRequest with a proxy for the API (Proxy @SimplestApi) and all generators needed in a generator list (GList)!

In code this looks like:

-- POST /cats
type SimplestApi =
  "my" :> "cats" :> ReqBody '[JSON] Cat :> Post '[JSON] ()

-- Generate a request to the Cat API from a base URL
catRequestGen :: BaseUrl -> Gen Request
catRequestGen baseUrl =
  genRequest (Proxy @SimplestApi) (genCat :*: GNil) <&>
    \makeReq -> makeReq baseUrl

We construct generator lists with element1 :*: element2 :*: ... elementN :*: GNil, where GNil denotes the end of the generator list. The genRequest function will derive a request from the generators in the list. This includes request bodies, headers and query parameters.

Note: since the generator list may contain many generators for a specific type, the first one will be chosen. This means that for types that may collide (e.g. common types like String,Integer etc), you should define newtype wrappers.