在多个存根中使用Mountebank复制行为

时间:2019-10-28 19:58:27

标签: mountebank

是否可以在Mountebank存根之间共享变量?

这是一个高级示例:

存根A:

{
    "predicates": [
        {
            "matches": {
                "body": "amount=420"
            }
        }
    ],
    "responses": [
        {
            "is": {
                "statusCode": 200
                },
                "body": {
                      "transaction_id": "123456",
                      "amount": 420
                      },
                "_behaviors": {
                  "copy": [{
                   "from": {"query": "transaction_id"},
                   "into": "${TRANSACTION1}",
                   "using": {
                    "method": "regex",
                    "selector": "(?<=transaction_id%5D=).{6}"
                  }
                 }]
              }

存根B:


{
    "predicates": [
        {
            "matches": {
                "body": "approved=420"
            }
        }
    ],
    "responses": [
        {
            "is": {
                "statusCode": 200
                },
                "body": {
                      "transaction_id": "${TRANSACTION1}",
                      "amount": 420
                      }
              }

我为存根B尝试过的copy _behavior方法似乎无法识别存根A中指定的变量。从文档看,似乎我无法在这些存根之间使用复制。

1 个答案:

答案 0 :(得分:1)

根据开发人员,目前不支持此行为。参见:https://github.com/bbyars/mountebank/issues/476