I’m building out a package that wraps an API using HTTP.jl. One thing I’m having trouble with is figuring out how to do integration testing. In the past, I’ve used python requests and just used mocking with responses to do such testing. What have y’all done for integration testing with HTTP.jl? I’ve thought about just spinning up a server with HTTP.jl on a different port to test against, but the API only exists on 80/443, so I can’t justify including an option for specifying the port in the package just so that I can run tests using that option.
@non-Jedi did you ever find out a solution to this? I looked into using https://github.com/getsentry/responses but that seems to heavily depend on using Python’s requests library, so I don’t think that’s compatible with HTTP.jl.
For future: I have found this blog post to be satisfactory to test my package: Working with the HTTP Protocol and Forms in Julia | by Erik Engheim | Medium.
I used t = @async HTTP.serve(router, ip"127.0.0.1", 8080)
to run the server and then after my tests, ran schedule(t, InterruptException(), error=true)
. Probably not the prettiest, but it works.
I never did figure out any way other than just running a server like you ended up doing. It’d probably be worthwhile to open an issue on the HTTP.jl repo to either implement a way of mocking http request calls or documenting how to do so (I suspect doing so might be relatively easy).
There is BrokenRecord.jl which you can record and replay server responses with.