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

Pact Maven Plugin failIfNoPactsFound fails with NotFoundHalResponse when no pacts found/provider unknown #1419

Closed
JapuDCret opened this issue Aug 19, 2021 · 1 comment · Fixed by #1421 or #1437

Comments

@JapuDCret
Copy link
Contributor

JapuDCret commented Aug 19, 2021

The issue

In the implementation guide for Pacts Maven plugin it is mentioned, that you can use failIfNoPactsFound to ignore if there are no pacts defined for a given provider. But when the provider is unknown to the broker, the broker will not return an empty list but a 404:

HTTP/1.1 404 Not Found
Content-Type: application/hal+json;charset=utf-8

{"error":"No provider with name 'MyEventProvider' found"}

This causes the plugin to throw an exception: Execution verify-pact-contracts of goal au.com.dius.pact.provider:maven:4.2.8:verify failed: Call to fetch pacts from Pact Broker failed with an exception: No HAL document found at path 'http://localhost:9292/pacts/provider/MyEventProvider/for-verification'.

I suspect that the PactProviderMojo.loadPactsFromPactBroker() cannot handle a 404 response by the broker (see here).
I think the same change as for the @IgnoreNoPactsToVerify needs to be done (see #1324).

My setup

            <plugin>
                <groupId>au.com.dius.pact.provider</groupId>
                <artifactId>maven</artifactId>
                <version>4.2.8</version>
                <configuration>
                    <pactBrokerUrl>http://localhost:9292</pactBrokerUrl>
                    <projectVersion>0.1-SNAPSHOT</projectVersion>
                    <trimSnapshot>true</trimSnapshot> <!-- the pact broker has issues parsing SNAPSHOT versions -->
                    <skipPactPublish>false</skipPactPublish>
                    <failIfNoPactsFound>false</failIfNoPactsFound> <!-- FIXME: set to true, once the initial pacts are available -->
                    <tags>
                        <tag>dev</tag>
                    </tags>
                    <systemPropertyVariables>
                        <pact.verifier.publishResults>true</pact.verifier.publishResults>
                    </systemPropertyVariables>
                    <serviceProviders>
                        <serviceProvider>
                            <name>MyEventProvider</name>
                            <verificationType>ANNOTATED_METHOD</verificationType>
                        </serviceProvider>
                    </serviceProviders>
                </configuration>
            </plugin>

Misc

For some providers, the broker seems to "know"(?) them and returns a 200 with an empty list, this the plugin can handle:

HTTP/1.1 200 OK
Content-Type: application/hal+json;charset=utf-8

{"_embedded":{"pacts":[]},"_links":{"self":{"href":"http://localhost:9292/pacts/provider/MyOtherEventProvider/for-verification","title":"Pacts to be verified"}}}

Expected behaviour

That the failIfNoPactsFound works like @IgnoreNoPactsToVerify, in that it can also ignore a 404 being returned by the pact broker. Or the pact broker not returning a 404.

@uglyog
Copy link
Member

uglyog commented Sep 4, 2021

4.2.11 released

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