Skip to content
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

Set mock ports for multiple providers? #1675

Closed
edeandrea opened this issue Mar 1, 2023 · 4 comments
Closed

Set mock ports for multiple providers? #1675

edeandrea opened this issue Mar 1, 2023 · 4 comments

Comments

@edeandrea
Copy link

edeandrea commented Mar 1, 2023

This question was also asked on StackOverflow by someone else but has yet to receive a response.

In my case I am not using Spring (as that previous entry on StackOverflow is) but I have the same problem: I have a single business method which calls 2 providers. Each provider is statically configured in the application configuration. Injecting a MockServer into the test method doesn't help because the framework itself creates the client implementation (see https://quarkus.io/guides/rest-client-reactive#create-the-interface). The URL for the client is configured at the application level, so the ports of both mock servers need to be known statically before the test class is even created.

Separating into 2 separate tests for each provider is impossible. What we need is either

  1. A single mock server instance on a single port that can handle multiple providers using context path root to differentiate between providers.
  2. A way to statically configure in the @PactTestFor annotation the ability to specify a port per provider.

In my particular case for this exact problem, a single mock server would work because both providers have different context paths that get called. But generically, that may not work for all use cases.

@github-actions
Copy link

github-actions bot commented Mar 6, 2023

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-807). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

@rholshausen
Copy link
Contributor

I've added support for multiple @MockServerConfig annotations, so you can now do

@ExtendWith(PactConsumerTestExt.class)
@MockServerConfig(providerName = "provider1", port = "1234")
@MockServerConfig(providerName = "provider2", port = "1235")
class MultiProviderWithStaticPortsTest {

The provider names must match the ones used to setup the Pacts. See https://github.com/pact-foundation/pact-jvm/blob/master/consumer/junit5/src/test/java/au/com/dius/pact/consumer/junit5/MultiProviderWithStaticPortsTest.java#L26

@edeandrea
Copy link
Author

That's awesome! Thank you!

@edeandrea
Copy link
Author

Closed in 67a6670

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants