pact-foundation / pact-mock_service

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

bind webrick of consumer server to 0.0.0.0 #88

Closed kpse closed 6 years ago

kpse commented 6 years ago

My use case is hosting my test cases with their Pact.service_consumer mock in one of my docker-compose services, bind consumer server to '0.0.0.0' will fix the access between docker-compose services.

bethesque commented 6 years ago

You should be able to specify "0.0.0.0" using the host parameter as documented in the CLI https://github.com/pact-foundation/pact-mock_service#mock-service-usage

bethesque commented 6 years ago

Also, have you tried using https://github.com/pact-foundation/pact-mock-service-docker ?

kpse commented 6 years ago

Thanks for the advice, I will take a look at pact-mock-service-docker.

kpse commented 6 years ago

Does pact-ruby has any support of integrating this pact-mock-service-docker ?

like

Pact.service_consumer "Zoo App" do
  has_pact_with "Animal Service" do
    mock_service :animal_service do
      port 1234
    end
  end
end

Or I can only interact with the mock server via pure http calling? @bethesque

bethesque commented 6 years ago

Yes, you can set standalone: true.

  mock_service :animal_service do
      port 1234
      standalone true
  end

I think this may make your set up more complicated though. I might add a configuration parameter to allow the host to be set in the config if you think that would be easier than managing another docker container.

kpse commented 6 years ago

Sorry for bothering again, I wonder if you have a working example of integrating ruby DSL with https://github.com/pact-foundation/pact-mock-service-docker, I am struggling on the default value of mock-server host is localhost everywhere.

for example when I change my code to:

Pact.service_consumer "Zoo App" do
 port 1111
has_pact_with "Animal Service" do
    mock_service :animal_service do
      app 'some-remote-host-name'
      port 1111
      standalone true
    end
  end
end

very funny that I have to provide the porttwice :D

I found that in the [client.rb] (https://github.com/pact-foundation/pact-mock_service/blob/master/lib/pact/mock_service/client.rb), it is still hardcoded to localhost instead of taking a host parameter.

def initialize port
        @http = Net::HTTP.new('localhost', port)
      end
bethesque commented 6 years ago

Oh, yes. You are right, it is hardcoded to localhost. I'd need to add a host parameter to the mock service config to make that configurable.

I'm going with your original solution, as it's more straightforward than adding a host parameter. I can still add the host if you'd prefer to have a separate docker container though. Let me know.

bethesque commented 6 years ago

I've released version 2.8.0 of the mock service gem.

bethesque commented 6 years ago

This change seems to have caused https://github.com/pact-foundation/pact-mock_service/issues/89

I've reverted it. We'll need to go with the solution that allows the address of the mock service to be configured through the DSL. You're welcome to give this a go, as I don't have a lot of time at the moment.