首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法在Pact json中只验证字段名而不验证值?

有没有办法在Pact json中只验证字段名而不验证值?
EN

Stack Overflow用户
提问于 2020-02-13 20:28:24
回答 1查看 157关注 0票数 0

下面的示例是响应。在这里,我只想验证字段,而不是正文中的字段值。

当我做pact验证时:

代码语言:javascript
复制
{
  "provider": {
    "name": "provider"
  },
  "consumer": {
    "name": "consumer"
  },
  "interactions": [
    {
      "description": "A valid data read request",
      "request": {
        "method": "GET",
        "path": "/v1/users",
        "query": {
          "user": [
            "1"
          ]
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json"
        },
        "body": {
          "name": "xyz",
          "work": "gen",
          "age": "29",    
        }
      },
      "providerStates": [
        {
          "name": "user exists state"
        }
      ]
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    },
    "pact-jvm": {
      "version": "4.0.4"
    }
  }
}

我只需要验证字段,如姓名,年龄和工作,而不是字段的值。

EN

回答 1

Stack Overflow用户

发布于 2020-02-14 14:46:54

代码语言:javascript
复制
    got solution we can achieve this using

final DslPart body = new PactDslJsonBody()
                .stringType("name", "xyz")
                .stringType("work", "gen")
                .integerType("age", 29)

or for only optional

     DslPart body = new PactDslJsonBody()
                        .eachKeyLike("name", PactDslJsonRootValue.stringType("xyz"))
                        .eachKeyLike("work", PactDslJsonRootValue.stringType("gen"))
                        .eachKeyLike("age", PactDslJsonRootValue.integerType(29))
                        .asBody()

    and set this body to PactDslWithProvider body and we can have matching rule generated in the json so that when we verify only the field type and field name 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60207882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档