pact-foundation / pact-mock_service

Provides a mock service for use with Pact
https://pact.io
MIT License
73 stars 69 forks source link

Stub Service can't handle multiple pact files #83

Closed jawu closed 6 years ago

jawu commented 6 years ago

The documentation says that you can provide multiple pact-files to the stub service. If you provide a path to a directory with pact-files, then they get all loaded (can be seen in the log) but only the requests from the last loaded file are matched and served by the stub service. Requests from the previous loaded files get a 500er response, saying that no interactions were found for that request. I am using package pact-1.22.0-linux-x86_64.tar.gz from here: https://github.com/pact-foundation/pact-ruby-standalone/releases and call it like ./pact-stub-service -p 1234 /path/to/pact/files/* Maybe loading a file clears all interactions that are already existent in the stub service.

jawu commented 6 years ago

I've looked into the code and found the part that causes this problem. pact-mock_service/lib/pact/mock_service/app.rb line 45 can be replaced with:

intreractions.each do | interaction |
    @session.add_expected_interaction interaction

At the moment set_expected_interactions is used and this calls clear_expected_and_actual_interactions which causes the issue.

I'm not a ruby coder and have no dev env for doing it by my own, sorry.

bethesque commented 6 years ago

Thanks for that. I've changed the code to:

interactions = stub_pactfile_paths.collect do | pactfile_path |
  ...
end.flatten
@session.set_expected_interactions interactions

I'll put out a new release of the standalone package.