javascalapactpact-jvmpact4s

Pact - Ignore some interactions when verifying on provider side


Let's say I have a provider which is involved in 2 interactions (with one consumer or many, it shouldn't matter).

On the provider side, I am able to handle one interaction in the sense that I know how to interpret the provider state of one interaction but not the other one.

Is there a way to ignore unknown provider states and avoid to fail the verification (or at least avoid to fail the test, I think it would actually make sense to fail the verification)?

I'm using pact4s in Scala with scalatest but I guess a solution for pact-jvm and Junit would still help and could be applied in a similar manner with pact4s.

Here's the Scala code I'm using:

val provider: ProviderInfoBuilder = ProviderInfoBuilder(
    "scalatest-provider",
    ...
  )
    ...
    .withStateChangeFunction((state: ProviderState) =>
      state match {
        case ProviderState("some state", params) =>
          // Do something as I know how to handle this provider state
        case _ => 
         // Unknown provider state, make the test ignore this interaction and not fail
      }
    )

Solution

  • What I was trying to achieve is actually the purpose of the pending pacts feature.

    When enabled, if a pact has never been verified successfully before, even if it fails verification it won't make the test fail on the provider side.

    The pact will still be flagged as "pending pact" on Pact Broker so that you can be aware of it. But it won't prevent the provider to run its tests successfully.