简体   繁体   中英

How to force Pact producer to verify a specific contract version?

I have a consumer that generated the first version of the Pact contract and it uploaded it to the broker. The producer verified that the contract and the verification were published to the broker.

Now I want to extend the contract. When I publish the updated contract to the broker and subsequently run the verification on the producer side, it fails since the contract-fulfilling API is not implemented yet. I'd like to update the contract first, publish it, and avoid breaking the producer build (ie not modifying the consumer and the producer in lockstep).

How can I version consumer/producer/contract so I can specify in the producer that it is currently compatible with a specific consumer/contract version?

I'm using Pact JVM/Java (version 3) with Maven. There is no project versioning in pom.xml - it's just 1.0.0-SNAPSHOT version. projectVersion , as configured in the Pact Maven plugin is the same as Maven project version - 1.0.0-SNAPSHOT .

Should I play with projectVersion and tags ? Should I upgrade to Pact version 4 and use consumer version selectors ?

So I think you're asking about how do effectively add Pact tests into your CI/CD pipeline and feature development workflow?

  1. Effective pact setup guide
  2. CI/CD workshop

The first document explains the general approach, and (2) is a workshop you can follow to implement the steps (in JS). The principles are the same no matter what language you use (in your case Java).

Specifically, however, you will definitely need to use tags to prevent new feature tags from breaking your providers main build (eg featureA created by a consumer, won't break the provider that only looks for production and development for example).

You may also want to look at pending pacts (see https://docs.pact.io/pending and the https://docs.pact.io/implementation_guides/jvm/provider/junit5/#pending-pact-support-version-410-and-later ) which is a newer feature that prevents new contracts from breaking a provider.

Versioning

So you'll need to add more specific versions to your code to make effective use of Pact (and the workflows provided by the broker). You can specify this with the pact.provider.version system property (eg System.setProperty("pact.provider.version", "some git sha"); )

We recommend using your revision control SHA in the version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM