【问题标题】:Why is this pact-jvm provider test failing?为什么这个 pact-jvm 提供者测试失败了?
【发布时间】:2017-01-19 07:16:36
【问题描述】:

我们有一个仅在 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": [

并且交互在 pact 文件中是这样的:

{
        "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();

【问题讨论】:

标签: pact pact-java


【解决方案1】:

日志中的重要信息位是“但丢失”位。这似乎表明数组中的第三项(由 '$.body.2' 匹配)缺少名称属性。

您能否仔细检查完整的回复,如果第三项中有名称属性,那么您能否在https://github.com/DiUS/pact-jvm 提出问题。

【讨论】:

    猜你喜欢
    • 2023-04-08
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 2021-11-25
    相关资源
    最近更新 更多