我们有一个提供程序测试,它只在 Jenkins 上失败,这阻止了我调试。
以下是来自 Jenkins 的一些相关日志:
Error Message
0 - $.body.2 -> Expected name='FXUHHqWrZZcodhHBmeLf' but was missing
0) a request to get all clients returns a response which has a matching body
$.body.2 -> Expected name='FXUHHqWrZZcodhHBmeLf' but was missing
Diff:
(有些遗漏...
@10
],
- "id": "c53927c3-0d1c-48a8-8f0a-7560be89daa5",
- "name": "FXUHHqWrZZcodhHBmeLf",
+ "id": "9daaad0a-8a2d-4e73-a963-fa1625cec110",
+ "name": "name",
+ "privileges": [
+ "CHECK_TOKEN",
+ "MANAGE_CLIENT",
+ "MANAGE_IDP",
+ "MANAGE_USER"
+ ],
"redirectUris": [
交互在协议文件中如下所示:
{
"description": "a request to get all clients",
"request": {
"method": "GET",
"path": "/some/url/client"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json; charset=UTF-8"
},
"body": [
{
"accessTokenValiditySeconds": 42721462,
"allowedScopes": [
"JnTfAlnHKVSDzoWnUqZv"
],
"autoApprove": true,
"grantTypes": [
"VfWudsTQINERQCnVKvoK"
],
"id": "c53927c3-0d1c-48a8-8f0a-7560be89daa5",
"name": "FXUHHqWrZZcodhHBmeLf",
"redirectUris": [
"vWxSTjgJQvwUtwphDGcn"
],
"refreshTokenValiditySeconds": 12393550,
"secretRequired": true
}
],
"matchingRules": {
"$.body[*].allowedScopes[*]": {
"match": "type"
},
"$.body[*].redirectUris[*]": {
"match": "type"
},
"$.body[*].grantTypes[*]": {
"match": "type"
},
"$.body[*].redirectUris": {
"min": 0,
"match": "type"
},
"$.body[*].autoApprove": {
"match": "type"
},
"$.body": {
"min": 1,
"match": "type"
},
"$.body[*].id": {
"regex": "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
},
"$.body[*].accessTokenValiditySeconds": {
"match": "integer"
},
"$.body[*].secretRequired": {
"match": "type"
},
"$.body[*].refreshTokenValiditySeconds": {
"match": "integer"
},
"$.body[*].name": {
"match": "type"
},
"$.body[*].allowedScopes": {
"min": 0,
"match": "type"
},
"$.body[*].grantTypes": {
"min": 0,
"match": "type"
}
}
},
"providerState": "the 'zero' client exists"
},
我的印象是名称应该与类型匹配而不是确切的值,并且差异中似乎有一个"名称"字段。
为什么此测试失败?
编辑:
这是生成协议片段的代码:
builder
.given("the 'zero' client exists")
.uponReceiving("a request to get all clients")
.path("/some/url/client")
.method("GET")
.willRespondWith()
.status(200)
.body(PactDslJsonArray
.arrayMinLike(1)
.uuid("id")
.booleanType("secretRequired")
.eachLike("allowedScopes", stringType())
.eachLike("grantTypes", stringType())
.eachLike("redirectUris", stringType())
.integerType("accessTokenValiditySeconds")
.integerType("refreshTokenValiditySeconds")
.booleanType("autoApprove")
.stringType("name")
.closeObject())
.toFragment();
日志中的重要信息位是"但丢失"位。这似乎表明数组中的第三项(由"$.body.2"匹配)缺少 name 属性。
您能否仔细检查完整的回复,如果第三项中有 name 属性,那么您能否在 https://github.com/DiUS/pact-jvm 提出一个问题。