【问题标题】:Wiremock JS has problem with response templatingWiremock JS 的响应模板有问题
【发布时间】:2021-11-24 01:08:53
【问题描述】:
{
    "request": {
        "method": "POST",
        "urlPathPattern": "/v1/customer"
    },
    "response": {
        "status": 200,
        "headers": {
            "Content-Type": "application/json"
        },
        "bodyFileName": "data/customer-{{jsonPath request.body '$.cid'}}.json",
        "transformers": ["response-template"]
    }
}
  • 在 Mac 中,它运行良好!

  • 在 Linux 中,出现此错误:

<pre> Server Error</pre></p><h3>Caused by:</h3>
<pre>java.lang.RuntimeException: java.io.FileNotFoundException:
 /mocks/./__files/data/customer-{{jsonPath request.body &apos;$.cid&apos;}}.json
  (No such file or directory)\n

有什么解决方案或解决方法吗?赞赏!

【问题讨论】:

    标签: javascript node.js linux wiremock


    【解决方案1】:

    我建议始终运行 Wiremock via Docker 以防止出现“它在我的机器上工作”等问题。

    但是,在所有机器上对我们都有效的是:

    {
       "city": "{{jsonPath request.body '$.contact[0].contactMedium[0].characteristic.city'}}",
       "postCode": "{{jsonPath request.body '$.contact[0].contactMedium[0].characteristic.postCode'}}",
       "street1": "{{jsonPath request.body '$.contact[0].contactMedium[0].characteristic.street1'}}",
       "type": "{{jsonPath request.body '$.contact[0].contactMedium[0].characteristic.type'}}",
    }
    

    我猜你的操作系统不喜欢&amp;apos;$.cid&amp;apos;

    并且您需要确保该文件也存在。对我来说,我总是提供一个默认文件来防止 Wiremock 被破坏。然后使用priority 覆盖特定请求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      相关资源
      最近更新 更多