Closed kpse closed 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
Also, have you tried using https://github.com/pact-foundation/pact-mock-service-docker ?
Thanks for the advice, I will take a look at pact-mock-service-docker
.
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
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.
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 port
twice :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
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.
I've released version 2.8.0 of the mock service gem.
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.
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.