【问题标题】:Wiremock testing with Dynamic HEADERS使用 Dynamic HEADERS 进行 Wiremock 测试
【发布时间】:2020-01-31 21:56:06
【问题描述】:

我有一个用于集成测试的wiremock 测试用例。一切都很好,但我被困在动态生成HttpHeaders 的地方,即timestamp 等。 因为我必须在JSON 文件中提到一些虚拟值(如下所示)。 你能帮我把一些东西放在那里,它会动态传递我的代码中生成的任何字符串。

{
  "request": {
    "method": "GET",
    "url": "<SOME_URL>",
    "headers" : {
      "signature" : {
        "contains" : "some dynamically string"
      },
      "timestamp": {
        "contains" : "dynamic timestamp"
      },
      "traceid" : {
        "contains" :"dynamic alpha numeric string"
      }
    }
  },
  "response": {
    "status": 200,
    "jsonBody": {
        //Some response
    }
  }
}

【问题讨论】:

    标签: json spring-boot junit junit4 wiremock


    【解决方案1】:

    用下面的正则表达式替换了我的 JSON

    "headers" : {
      "signature" : {
        "matches" : ".*some-always-present-chars.*"
      },
      "timestamp": {
        "matches" : "2.*"
      },
      "traceid" : {
        "matches" :".*"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-18
      • 2018-06-01
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多