如何强制 Pact 生产者验证特定的契约版本?

huangapple go评论63阅读模式
英文:

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

问题

我有一个消费者生成了 Pact 合同的第一个版本,并将其上传到了经纪人。生产者验证了合同,并且验证结果被发布到了经纪人。

现在我想扩展这个合同。当我将更新后的合同发布到经纪人,然后在生产者端运行验证时,由于尚未实现符合合同的 API,验证失败了。我想先更新合同,然后发布它,以避免破坏生产者构建(即不需要同时修改消费者和生产者)。

我应该如何对消费者/生产者/合同进行版本控制,以便在生产者中指定它当前与特定的消费者/合同版本兼容?

我正在使用 Pact JVM/Java(版本 3)和 Maven。在 pom.xml 中没有项目版本信息 - 只是 1.0.0-SNAPSHOT 版本。projectVersion 在 Pact Maven 插件中的配置与 Maven 项目版本相同 - 都是 1.0.0-SNAPSHOT

我应该调整 projectVersiontags 吗?还是应该升级到 Pact 版本 4 并使用消费者版本选择器

英文:

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 (i.e. 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?

答案1

得分: 0

所以我认为您是在询问如何将 Pact 测试有效地添加到您的 CI/CD 流水线和功能开发工作流中?

  1. 有效的 Pact 设置指南
  2. CI/CD 工作坊

第一个文档解释了一般的方法,(2) 是一个工作坊,您可以按照其中的步骤来实施(使用 JS)。不管您使用什么语言(在您的情况下是 Java),原则都是相同的。

然而,特别地,您肯定需要使用标签来防止新的功能 标签 影响到您的提供者主要构建(例如,由消费者创建的 featureA 不会影响只寻找 productiondevelopment 的提供者)。

您可能还想看一下未决的 pacts(参见 https://docs.pact.io/pendinghttps://docs.pact.io/implementation_guides/jvm/provider/junit5/#pending-pact-support-version-410-and-later),这是一个较新的功能,可以防止新的合同影响到提供者。

版本控制

因此,您需要在代码中添加更具体的版本,以有效地使用 Pact(以及由代理商提供的工作流程)。您可以使用 pact.provider.version 系统属性来指定这一点(例如,System.setProperty("pact.provider.version", "some git sha");

我们建议在版本中使用您的版本控制 SHA。

英文:

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 (e.g. 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 (e.g. System.setProperty("pact.provider.version", "some git sha");)

We recommend using your revision control SHA in the version.

huangapple
  • 本文由 发表于 2020年10月10日 00:38:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/64284058.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定