Check out Control.Proxy.Tutorial . If you can write a proxy wrapper around your type, then you can easily replace the test interface and the real interface as follows:
client <-< simulatedServer client <-< realServer
Edit: To answer your question in a comment, you use Server to write a wrapper around your simpleHTTP requests:
realServer :: HStream ty => Request ty -> Server (Request ty) (Result (Response ty)) IO r realServer = foreverK $ \req -> do result <- lift $ simpleHTTP req respond result
The simulated server will look like this:
simulatedServer :: (Monad m, HStream ty) => Request ty -> Server (Request ty) (Result (Response ty)) mr simulatedServer = foreverK $ \req -> do result <- lift $ simulatedRequest req respond result
And your client will look like this:
client :: (Monad m, HStream ty) => () -> Client (Request ty) (Result (Response ty)) mr client () = forever $ do let req = <something> result <- request req lift $ doSomethingWith result
Then you can test the real server and the fake server using:
client and simulatedServer are polymorphic in the base monad just because I donβt know which base monad they will use for your testing. The only requirement is that the two things you compose have the same base monad or that at least one is polymorphic in the base monad.
source share