pact-mock_service
pact-mock_service copied to clipboard
Multiple Providers
The problem is about /pact
DELETE
. I have few tests within same consumer for multiple providers. When interactions for Provider A
are finished I call DELETE
on /pact
and I would like to go with next Provider B
. But when I do this I inherit Provider A
interactions in pact file of Provider B
, so for real they are not deleted.
Is there possibility to create pacts for multiple providers within one instance of pact-mock-service
?
No, it's not designed to be used like this. I don't think there is a DELETE for /pact, only /interactions.
So is there any way to test multiple providers against one instance of pact-mock-service?
You can run multiple pact mock service instances, specifying different ports for each with the --port option, with each instance representing a different provider. Multiple providers in a single running instance is not supported.
That's sad to hear. Any future plans to make it work with more than one provider within the same instance?
There are two or more possibilities to do so. First one. After creating pact, whole history could be deleted. Second make possible to write interaction according to the provider name, which would be passed with interaction.
There are, to the best of my knowledge, no plans to do so, as it would involve quite a bit of work, and potentially a modification to the pact file specification, which is shared by many implementations. Out of curiosity, is there a reason you can't just have a separate mock for each required provider?
If you give the consumer and provider names in the POST /pact call rather than at startup, it will use them to write the pact. Have a look at this code: https://github.com/bethesque/pact-mock_service/blob/master/lib/pact/mock_service/request_handlers/pact_post.rb
Actually, I've just come across DELETE /session - this might be what you're after, I'd forgotten about it because I didn't write it. https://github.com/bethesque/pact-mock_service/blob/master/lib/pact/mock_service/request_handlers/session_delete.rb
@bethesque thanks I was looking for such solution, but I found different one already. :) I will implement docker image, which will be responsible for spawning multiple mock-services, so I will be able to run my tests without order. I guess It will simplify implementation of tests for developers in my company.
Anyway It's worth to add /session [DELETE] to github wiki.
This is how I solved it using one pact-mock-service running on port 1234.
after each provider test:
- Write the current interactions to disk:
POST
http://localhost:1234/pact
X-Pact-Mock-Service: true
{"consumer": {"name": "CONSUMER"}, "provider": {"name": "PROVIDER"}}
- Clear the session:
DELETE
http://localhost:1234/session
X-Pact-Mock-Service: true