I guess you can say @wojtekmach nerd sniped me into trying out backing Req.Test mocks with Bandit, so that your test Req test requests are actually going through an HTTP stack (instead of only invoking a Plug function). You can optionally use X509 in order to use HTTPS for those test requests.
Caveat: I have no idea if this is a good idea or not, but it’s fun to play with and it’s working for me!
With ReqTestBandit, you still use Req.Test to register the stub & mock requests, and it still uses Req.Test’s ownership model, in fact as a user of this library not much needs to change.
If you have a setup similar to that given in Req.Test’s example, then you’d want to add bandit: true to the app config:
config :myapp, weather_req_options: [
bandit: true,
plug: {Req.Test, MyApp.Weather},
x509: true # optional, if you want to use HTTPS
]
Lastly the plugin needs to be attached:
def get_temperature(location) do
[
base_url: "https://weather-service",
params: [location: location]
]
|> Keyword.merge(Application.get_env(:myapp, :weather_req_options, []))
|> Req.new()
|> ReqTestBandit.attach()
|> Req.request()
end




















