使 Pact-Test 在其他提供者字段上失败

Make Pact-Test fail on additional provider field

Pact 测试的默认行为是当提供者将字段添加到消费者合同未指定的消息时不会失败,例如:

消费者期望:

{
  "foo": "bar"
}

提供商提供:

{
  "foo": "bar",
  "hello": "world"
}

使用上述消息的 Pact 合同测试将会成功。有没有办法让他们失败?例如,一些“严格”模式需要消息的精确匹配?

不,根据 pact docs 是不可能的:

You cannot expect a field to not be present in a response

Following Postel's law, the provider may return fields that the consumer will just ignore. The provider may have a pact with another consumer that requires those fields, so your consumer cannot tell the provider what it should not do. It can only specify what it should do.