Hi All, I’m having problems with the gradle plugin...
# pact-jvm
n
Hi All, I’m having problems with the gradle plugin and setting the
pact.filter.pacturl
property. I can’t see if its working. Using the junit5 style tests:
Copy code
@ExtendWith(SpringExtension.class)
@Provider("provider-name-here")
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT})
@PactBroker(url = "${PACT_BROKER_BASE_URL}", authentication = @PactBrokerAuth(token = "${PACT_BROKER_TOKEN}"))
@IgnoreNoPactsToVerify
public class ProviderPactTests {
   ...
}
And then my CICD pipeline rungs the provider pact tests using gradle plugin
Copy code
./gradlew test -Ppact.filter.pacturl=url-from-webhook -Ppact.filter.consumers=consumer-name --tests "*Provider*"
I’d expect in the output for it to tell me it has applied the filter, but instead I get:
Copy code
Verifying a pact between ecom-booking-portal (b21f4285ced5cb513a3bddf579a3d54c2c2c419f) and ecom-booking-portal-service

      Notices:
        1) The pact at <https://xxx.pactflow.io/pacts/provider/ecom-booking-portal-service/consumer/ecom-booking-portal/pact-version/2aa8bcb012d1c007a5f867f3bed41a68f2688e56> is being verified because the pact content belongs to the consumer versions matching the following criteria:
        * consumer version(s) currently deployed to dev (b21f4285ced5cb513a3bddf579a3d54c2c2c419f), ext (b21f4285ced5cb513a3bddf579a3d54c2c2c419f) and production (b21f4285ced5cb513a3bddf579a3d54c2c2c419f)
        * latest version of ecom-booking-portal from the main branch 'main' (b21f4285ced5cb513a3bddf579a3d54c2c2c419f)

      [from Pact Broker <https://xxx.pactflow.io/pacts/provider/ecom-booking-portal-service/consumer/ecom-booking-portal/pact-version/2aa8bcb012d1c007a5f867f3bed41a68f2688e56/metadata/c1tdW2N2XT0xMjUwMCZzW11bY3ZdPTEyNTAwJnNbXVtjdl09MTI1MDAmc1tdW2N2XT0xMjUwMA>]
Where I can see it is checking the deployed versions and latest main.
Copy code
16:35:24.477 [Test worker] DEBUG au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider$Companion - Verifying pacts for provider 'ecom-booking-portal-service' and consumer 'null'
Consumer
null
from the debug lines looks like it is ignoring the properties:
Copy code
pact.filter.consumers=ecom-booking-portal
Copy code
[Test worker] DEBUG au.com.dius.pact.provider.junitsupport.loader.PactBrokerLoader$Companion - Loading pacts from pact broker for provider ecom-booking-portal-service and consumer version selectors []
My theory is should now be using these instead: https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors ?
Or maybe it is as easy as adding
@AllowOverridePactUrl
to my provider test! 🙈
r
This won't work
./gradlew test -Ppact.filter.pacturl=url-from-webhook -Ppact.filter.consumers=consumer-name --tests "*Provider*"
as it sets the property in the Gradle build but not in the tests
You need to pass the project property though to the test JVM by doing something like:
Copy code
test {
Copy code
test {
  systemPropety 'pact.filter.pacturl', project.property('pact.filter.pacturl')
}
m
Thanks Ron!
n
I made it work by:
Copy code
test {
    useJUnitPlatform()
    systemProperties System.properties
}
And then setting the properties with the
-D
flag
Is there another way I can allow override pact url - without having to go into every project and add the annotation to my provider tests?