Implement a mock HTTP server for use in tests

Edit Package perl-Test-HTTP-MockServer
https://metacpan.org/release/Test-HTTP-MockServer

Sometimes, when writing a test, you don't have to oportunity to do dependency injection of the type of transport used in a specific API. Sometimes that code willl unequivocally always use actual HTTP and the only control you have is over the host and port to which it will connect. This class offer a simple way to mock the service being called. It does that by binding to a random port on localhost and allowing you to inspect which port that was. Using a random port means that this can be used by tests running in parallel on the same host. The socket will be bound and listened on the main test process, such that the lifetime of the connection is defined by the lifetime of the test itself. Since the socket will be already bound and listened to, the two conntrol methods (start_mock_server and stop_mock_server) fork only for the accept call, which means that it is safe to call start and stop several times during the test in order to change the expectations of the mocked code. That allows you to easily configure the expectations of the mock server across each step of your test case. On the other hand, it also means that no state is shared between the code running in the mock server and the test code.

Refresh
Refresh
Source Files
Filename Size Changed
Test-HTTP-MockServer-v0.0.1.tar.gz 0000008464 8.27 KB
cpanspec.yml 0000000721 721 Bytes
perl-Test-HTTP-MockServer.changes 0000000392 392 Bytes
perl-Test-HTTP-MockServer.spec 0000003070 3 KB
Latest Revision
Yuchen Lin's avatar Yuchen Lin (maxlin_factory) committed (revision 2)
branch from Backports SP5
Comments 0
openSUSE Build Service is sponsored by