Hey :wave::skin-tone-2: Unfortunately I did not fo...
# pact-jvm
d
Hey 👋🏻 Unfortunately I did not found any information about my current problem. So we have successfully integrated PACT between two (asynchronous) services. Basically all the pieces are tight together, last part I was working on was integrating web hooks whenever a contract changed that
required
verification. To come to the question: We saw that PACT verified several versions - especially from PR's which actually might not exist anymore at this time. I think it would make most sense to just verify against deployed versions of a service right? Basically latest master/main would be fine + all versions deployed on environments (recorded deployments). Is there some configuration available? Here is my current (provider) test setup
Copy code
@Provider("goto-conference-service")
@PactBroker
@SpringBootTest
@Import(KafkaConsumerConfiguration.class)
@AutoConfigureMockMvc
@AllowOverridePactUrl
public class ConferenceEventsContractTests extends TestcontainersIntegrationTests {

    @Autowired
    private MockMvc mockMvc;

    @Autowired
    private ObjectMapper objectMapper;

    @TestTemplate
    @ExtendWith(PactVerificationInvocationContextProvider.class)
    void testTemplate(Pact pact, Interaction interaction, PactVerificationContext context) {
        context.verifyInteraction();
    }

    @BeforeAll
    static void beforeAll(){
        PactBrokerDefaults.initFallbackTokenIfMissing();
        PactBrokerDefaults.initFallbackUrlIfMissing();
    }

    @BeforeEach
    void before(PactVerificationContext context) {
        context.setTarget(new MessageTestTarget());
    }

    @PactVerifyProvider("valid conference created event")
    public String verifyConferenceCreatedEvent() throws Exception {
        ConferenceEvent createdEvent = getEventByCreateTrigger(event -> "ConferenceCreated".equals(event.getEventName()));
        return objectMapper.writeValueAsString(createdEvent);
    }
    
    // some more not relevant pieces of code
}
s
I think you may have forgotten to make use of
consumerVersionSelectors
property of the PactBroker annotation. You basically skipped the "Gold" step of Pact Nirvana I think: https://docs.pact.io/pact_nirvana/step_5 Without the consumerVersionSelector, your provider verifies all latest PACTs it finds
👌 1
However, if all pacts are verified even though your cicd is triggered by the webhook, I suppose something else (or additionall) is off. The Webhook ships the direct pact URL to verify and the provider should ONLY verify the pact from that URL and not all of them. Did you pass the `
Copy code
-Dpact.filter.pacturl=${PACT_FILTER_URL} \
-Dpact.filter.consumers=${PACT_FILTER_CONSUMER} \
args to the maven/gradle/... command?
d
I didnt know about the pact nirvana let me check that, thanks. To your suggestion - yes I'm doing that and that got me confused as well. Here is my pipeline step
Copy code
stage('verify') {
            steps {
                script {
                    def config = readYaml file: 'pact.yaml'
                    def verificationCommand = config.VERIFICATION_COMMAND
                    if (!verificationCommand?.trim()) {
                        error("Please configure a pact 'VERIFICATION_COMMAND'")
                    }
                    verificationCommand = verificationCommand + " -Dpact.filter.consumers=${consumer} -Dpact.filter.pacturl=${pactUrl}"
                    echo "pact provider verification command = ${verificationCommand}"
                    mavenBuilder 'test', customParams: verificationCommand
                }
            }
        }
both
${consumer}
and
${pactUrl}
are from the web hook
s
Do you find the PACT URL appears in the maven build logs?
For me there is such a log entry:
Copy code
[main] DEBUG org.apache.hc.client5.http.wire - http-outgoing-0 >> "GET /pacts/provider/fake-product-api/consumer/some-consumer/pact-version/441f7e998d167ca75aa0a93653e7ce093808f79f/metadata/Y3ZuPWZkODQ0YzImY3Z0W109bWFpbiZ3PXRydWU HTTP/1.1[\r][\n]"
and that URL is identical with the webhook one
d
Looks like that when pactflow triggered my jenkins job it seams I got all the required data
Copy code
pact provider verification command = -Dtest=ConferenceEventsContractTests -Dpact.filter.consumers=goto-provisioning-service -Dpact.filter.pacturl=<https://xxx.pactflow.io/pacts/provider/goto-conference-service/consumer/goto-provisioning-service/pact-version/865103be9f0e9eedd7b29ccdf8339e2d4f0e7458/metadata/Y3ZuPTEuMS4yLVBSLTI4NC1iNWM0MjdmJnc9dHJ1ZQ>
s
So far so good. And if you turn on DEBUG logging of
org.apache.hc
you should see outgoing traffic to that URL, do you?
Something like this basically:
d
that will take some time to test that
Currently I'm not able to log that properly 🙄 But from my understanding in reading this here https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors we actually want to exactly use that kind of version selector as described as following
`deployed`: if the key is specified, can only be set to
true
. Returns the pacts for all versions of the consumer that are currently deployed to any environment. Use of this selector requires that the deployment of the consumer application is recorded in the Pact Broker using the
pact-broker record-deployment
CLI. As of October 2021, this is not yet supported in all Pact client libraries.
I checked the code and it seems like this is still not supported https://github.com/pact-foundation/pact-jvm/blob/master/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/VersionSelector.java