NorfairKing / sydtest

A modern testing framework for Haskell with good defaults and advanced testing features.
115 stars 25 forks source link

servant-based test for APIs that need a context #42

Closed L7R7 closed 2 years ago

L7R7 commented 2 years ago

I'd like to write tests for a servant-backed webservice where the API requires a context. A simple example is an API with basic auth, like described in the cookbook: https://docs.servant.dev/en/stable/cookbook/basic-auth/BasicAuth.html

I think that could be solved by adding servantSpec and servantSpecWithSetupFunc variants for APIs that take a context and under the hood use serveWithContext. What do you think? I'm happy to give it a try in a PR if that's something you'd like to have in the library.

NorfairKing commented 2 years ago

Yeah would love this. Currently I just turn the servant app into a wai app and then use sydtest-wai: https://github.com/NorfairKing/smos/blob/release/smos-server-gen/src/Smos/Server/TestUtils.hs

L7R7 commented 2 years ago

I did this as well in another project because servant-client doesn't support ccookie-based auth. What I like about sydtest-wai is that I don't have to bother with the details of building the request.

I will see what I can come up with, expect a PR in a couple of days

L7R7 commented 2 years ago

Closing this as I'm happy for now. Thanks for helping me contribute!