我正在使用Pact进行消费者驱动的合同测试。在我的用例中,我的消费者“some-market-service-consumer”正在使用提供者“market-service”。在 some-market-service-consumer “生产”的合同如下所示:
{
"provider": {
"name": "market-service"
},
"consumer": {
"name": "some-market-service-consumer"
},
"interactions": [
{
"description": "Get all markets",
"request": {
"method": "GET",
"path": "/markets"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json; charset=utf-8"
},
"body": {
"markets": [
{
"phone": "HBiQOAeQegaWtbcHfAro"
}
]
},
"matchingRules": {
"$.headers.Content-Type": {
"regex": "application/json; charset=utf-8"
},
"$.body.markets[*].phone": {
"match": "type"
},
"$.body.markets": {
"min": 1,
"match": "type"
}
}
}
}
],
"metadata": {
"pact-specification": {
"version": "2.0.0"
},
"pact-jvm": {
"version": "3.3.6"
}
}
}
在提供者网站上,我使用的是pact-provider-verifier-docker ¹。这是我的测试结果:
WARN: Ignoring unsupported matching rules {"min"=>1} for path $['body']['markets']
.....
@@ -1,7 +1,7 @@
{
"markets": [
... ,
- Pact::UnexpectedIndex,
+ Hash,
]
}
Key: - means "expected, but was not found".
+ means "actual, should not be found".
Values where the expected matches the actual are not shown.
似乎测试工作正常 - “电话”测试有效。但在这一点上,我不知道(预期的)“Pact::UnexpectedIndex”是什么意思,以及它为什么失败。这种期望从何而来,如何解决?
¹ 特别是我自己的版本,它使用最新的外部依赖项。