Mocking http poison request

Hi all

I am using http poison for request some stuff from my SAP server. My question is, how to create a mock for the request?

Thanks

I’ve done this two ways.

You can either use something like GitHub - jjh42/mock: Mocking library for Elixir language · GitHub and wrap the test in a with_mock HTTPoison, [request: &MockHTTPoison.mock_request/5] and implement a mock function. This excels at timeout testing.

or

use something like GitHub - PSPDFKit-labs/bypass: Bypass provides a quick way to create a custom plug that can be put in place instead of an actual HTTP server to return prebaked responses to client requests. · GitHub which spins up a quick plug server that will return the actual response u want. Its nice because you can put assertions inside the bypass server. This is very hard to do timeout tests but probably excels at everything else.

the bypass is a better choice?

As @ctrlshiftbryan indicated, for most testing bypass will be great.. But if you want to test anything that involves a request timeout, then probably better to mock that test than having bypass block until the timeout happens (which, with default settings, would make it a really slow test).

You could probably provide different timeout settings to the HTTPoison call if you’re in control of the parameters passed, of course, as a possible alternative to mocking.