pact-mock_service icon indicating copy to clipboard operation
pact-mock_service copied to clipboard

Multiple Providers

Open dgafka opened this issue 9 years ago • 8 comments

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?

dgafka avatar Feb 13 '16 22:02 dgafka

No, it's not designed to be used like this. I don't think there is a DELETE for /pact, only /interactions.

bethesque avatar Feb 14 '16 03:02 bethesque

So is there any way to test multiple providers against one instance of pact-mock-service?

dgafka avatar Feb 14 '16 09:02 dgafka

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.

sergei-matheson avatar Feb 15 '16 00:02 sergei-matheson

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.

dgafka avatar Feb 15 '16 06:02 dgafka

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?

sergei-matheson avatar Feb 17 '16 00:02 sergei-matheson

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 avatar Feb 17 '16 01:02 bethesque

@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.

dgafka avatar Feb 17 '16 18:02 dgafka

This is how I solved it using one pact-mock-service running on port 1234.

after each provider test:

  1. Write the current interactions to disk:
POST
http://localhost:1234/pact
X-Pact-Mock-Service: true
{"consumer": {"name": "CONSUMER"}, "provider": {"name": "PROVIDER"}}
  1. Clear the session:
DELETE
http://localhost:1234/session
X-Pact-Mock-Service: true

nathandeamer avatar Oct 19 '17 13:10 nathandeamer