Closed BenFradet closed 3 years ago
Hi @BenFradet, nothing like that is currently possible in scala-pact. If this is a common feature across other implementations we can maybe look into adding support for it.
@BenFradet this is possible now in the latest version, 3.0.0
: https://github.com/ITV/scala-pact/blob/master/example/provider_pact-for-verification/src/test/scala/com/example/provider/VerifyContractsSpec.scala#L43
describe("Verifying Consumer Contracts") {
it("should be able to verify it's contracts") {
val consumer = ConsumerVersionSelector("example", latest = true) // This should fetch all the latest pacts of consumer with tag example
verifyPact
.withPactSource(
pactBrokerWithVersionSelectors(
"https://test.pact.dius.com.au",
"scala-pact-provider",
List(consumer),
List(),
PendingPactSettings.PendingDisabled,
None,
//again, these are publicly known creds for a test pact-broker
PactBrokerAuthorization(pactBrokerCredentials = ("dXfltyFMgNOFZAxr8io9wJ37iUpY42M", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"), ""),
Some(5.seconds)
)
)
.setupProviderState("given") {
case "Results: Bob, Fred, Harry" =>
val newHeader = "Pact" -> "modifiedRequest"
ProviderStateResult(true, req => req.copy(headers = Option(req.headers.fold(Map(newHeader))(_ + newHeader))))
}
.runVerificationAgainst("localhost", 8080, 10.seconds)
}
}
Excellent, I was going to start needing it and working on it. Thanks a lot! :+1:
Hello, is there a way to modify requests that are sent for verification like what pact-js does?