-
-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pact-server): allow to run pact mock server on a host other than localhost #115
feat(pact-server): allow to run pact mock server on a host other than localhost #115
Conversation
… localhost/127.0.0.1
2 similar comments
I know I'm not the js expert here, but I'm taking a bet that this is all good and merging. |
Thanks @sebastian-curland! |
@bethesque a pattern I'm seeing is a multi-docker test harness, where the mock-server is running in a separate container. Might be worth us reviewing docs/other library implementations to see how we can simplify this use case. |
@bethesque that's exactly what we're aiming at with @sebastian-curland on this. |
The original Ruby DSL allowed you to say "don't start up the mock service because I've already got my own one running" (in a more concise way). This would be a good feature for the other implementations too. |
This change won't achieve your outcome, as the the property you added will be passed to the mock server which will attempt to startup on the host you provided (the only real options here are going to be things like That being said, whilst not ideal, if you used In the TypeScript branch, I will propose some options for improving the DSL to work with this use case. |
@mefellows we need this support in pact-js/pact-node since we plan on using it inside a docker container as a generic mock service in CI, where we will set its IP to 0.0.0.0, but also it will have a real IP for the container. what did you refer to that is not going to work with this change? |
The current If I understand your use case correctly, I think you want to do something like this:
when you call Alternatively, the Make sense? |
Just a warning note, you cannot use the same mock service process for multiple consumer/provider pairs. It's a one consumer/provider only deal. |
@mefellows actually that's not what we're planning. So it's more like: in the above, the [ test suite] and [ pact mock server] are running in the same container, and the pact mock server will be getting requests from other containers and reply to them. Makes sense? |
I think so, so you'll want the mock server to start on 0.0.0.0 and your tests point to gateway. Interesting. |
I love the way people use things that you write in unexpected ways! Either way, we want a flag that says "don't start up the mock service". I think in the ruby, it was |
I'll think of something. I've been thinking of a nicer DSL which might go out with the 5.0.0 release. But for now that might be the way to go. |
I think last time we tried it, even with the 0.0.0.0 support with the PR from @sebastian-curland ended up in the mock server halting with "server hangup" error messages. I'll check later if it's something on our part, but any ideas how/if that could be related to pact? |
Yes, start it up manually and ping it yourself. Start with this example, and then slowly make changes, one step at a time to get it to the state you want your tests to run with. eg. step 1. swap out the local mock service instance with the docker one One thing I've just realised is that the docker mock service relies on the consumer and provider name being passed in during the |
I've just seen a suggestion that you can run a shell script that references the env vars, so that might work. |
@bethesque any environment variables present at the time of executing that script will be available. e.g. |
When running pact tests (that also start the pact mock server) and the application code (that calls the APIs defined in the pact interactions) on different servers (or different docker containers), the pact server should be binded to a different host other than localhost, otherwise the API calls in the application won't reach the mock server.
pact constructor in src/pact.js already get a "host" option but it is not passed to serviceFactory.createServer() method.