随机化`status`值

问题描述 投票:0回答:1

我正在尝试随机化 Wiremock(版本 2.33.2)端点返回的

status

理想情况下,我的配置是这样的:

{
  "mappings": [
    {
      "request": {
        "method": "PATCH",
        "urlPattern": "/giglio/random/supplier-stock/.*",
        "headers": {
          "Content-Type": {
            "equalTo": "application/json"
          }
        }
      },
      "response": {
        "status": {{pickRandom 200 500}}
      }
    }
  ]
}

但是这当然不是有效的 JSON,因此我在尝试启动 Wiremock 时收到错误 (

Error loading file...
)。

如果我将有问题的行换行:

...
      "response": {
        "status": "{{pickRandom 200 500}}"
      }
...

然后 Wiremock 抱怨说它

Cannot deserialize value of type 'int' from String "{{pickRandom 200 500}}": not a valid 'int' value

有办法让这个工作吗?

wiremock wiremock-standalone
1个回答
0
投票

根据 wiremock 文档 值应该用

'
包裹。 示例

{{pickRandom '1' '2' '3'}} // One of 1, 2 or 3

尝试做

"response": {
    "status": "{{pickRandom '200' '500'}}"
}
© www.soinside.com 2019 - 2024. All rights reserved.