为什么 Mountebank 谓词导致 200 而不是 500 作为响应?

Why does Mountebank predicate cause 200 instead of 500 in response?

自学走江湖。我想创建一个模拟端点,以便通过向 http://localhost:2525/test?mock-response-code=500 发出 POST 命令,响应代码将为 500,消息正文将是一些自定义文本。

但是,当我创建冒名顶替者和 运行 相关的 curl 命令时,我收到了 200 响应。

curl -i -X POST http://localhost:2525/imposters --data '@createImposter_r500.ejs'
info: [mb:2525] POST /imposters
info: [http:61161] Open for business...
HTTP/1.1 201 Created
Access-Control-Allow-Origin: *
Location: http://localhost:2525/imposters/61161
Content-Type: application/json; charset=utf-8
Content-Length: 767
Date: Sun, 18 Aug 2019 13:57:57 GMT
Connection: keep-alive

{
  "protocol": "http",
  "port": 61161,
  "numberOfRequests": 0,
  "recordRequests": false,
  "requests": [],
  "stubs": [
    {
      "responses": [
        {
          "is": {
            "statusCode": 500
          }
        }
      ],
      "predicates": [
        {
          "equals": {
            "path": "/test",
            "method": "POST",
            "query": {
              "mock-response-code": 500
            }
          }
        }
      ],
      "_links": {
        "self": {
          "href": "http://localhost:2525/imposters/61161/stubs/0"
        }
      }
    }
  ],
  "_links": {
    "self": {
      "href": "http://localhost:2525/imposters/61161"
    },
    "stubs": {
      "href": "http://localhost:2525/imposters/61161/stubs"
    }
  }
}

createImposter_r500.ejs:

{
  "protocol": "http",
  "stubs": [{
    "responses": [
      { "is": { "statusCode": 500 }}
    ],
    "predicates": [{
          "equals": {
            "path": "/test",
            "method": "POST",
        "query": {"mock-response-code": 500} 
       }
    }]
  }]
}

这是我尝试使用 URL 时发生的情况:

curl -i -X POST http://localhost:61161/test?mock-response-code=500
info: [http:61161] ::1:61429 => POST /test?mock-response-code=500
HTTP/1.1 200 OK
Connection: close
Date: Sun, 18 Aug 2019 14:18:06 GMT
Transfer-Encoding: chunked

这是一些调试输出:

debug: [http:62650] ::1:63139 ESTABLISHED
info: [http:62650] ::1:63139 => POST /test?mock-response-code=400
debug: [http:62650] ::1:63139 => {"requestFrom":"::1:63139","method":"POST","path":"/test","query":{"mock-response-code":"400"},"headers":{"Host":"localhost:62650","User-Agent":"curl/7.54.0","Accept":"*/*"},"body":"","ip":"::1"}
debug: [http:62650] no predicate match
debug: [http:62650] generating response from {"is":{}}
debug: [http:62650] ::1:63139 <= {"statusCode":200,"headers":{"Connection":"close"},"body":"","_mode":"text"}
debug: [http:62650] ::1:63139 CLOSED

(端口与上面不同 b/c 它来自不同的 运行。)

通过不断的实验,我自己找到了答案。

引号 - 就这么简单。

           "query": {"mock-response-code": "400"} 

而不是

           "query": {"mock-response-code": 400}