Dennis Woditsch
04/21/2022, 12:23 PMrequired
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
@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
}
Stefano Lucka
04/21/2022, 12:57 PMconsumerVersionSelectors
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 findsStefano Lucka
04/21/2022, 12:59 PM-Dpact.filter.pacturl=${PACT_FILTER_URL} \
-Dpact.filter.consumers=${PACT_FILTER_CONSUMER} \
args to the maven/gradle/... command?Dennis Woditsch
04/21/2022, 1:01 PMstage('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
}
}
}
Dennis Woditsch
04/21/2022, 1:03 PM${consumer}
and ${pactUrl}
are from the web hookStefano Lucka
04/21/2022, 1:06 PMStefano Lucka
04/21/2022, 1:06 PM[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]"
Stefano Lucka
04/21/2022, 1:08 PMDennis Woditsch
04/21/2022, 1:09 PMpact 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>
Stefano Lucka
04/21/2022, 1:11 PMorg.apache.hc
you should see outgoing traffic to that URL, do you?Stefano Lucka
04/21/2022, 1:12 PMDennis Woditsch
04/21/2022, 1:16 PMDennis Woditsch
04/21/2022, 1:43 PM`deployed`: if the key is specified, can only be set toI 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. 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 thetrue
CLI. As of October 2021, this is not yet supported in all Pact client libraries.pact-broker record-deployment