bbyars / mountebank

Over the wire test doubles
http://www.mbtest.org
MIT License
2k stars 262 forks source link

Support fallback stubs when proxy origin server down #362

Open bbyars opened 6 years ago

bbyars commented 6 years ago

We have a new requirement to combine the proxy and stub modes in MB.

Currently we need to switch between proxy and stub modes when the downstream system is unavailable.

This is creating lot of manual efforts as the environment is unstable. So we need MB to respond from a static or prerecorded set of data when proxied response has an http status code 500(internal server error). Have to add an assertion on the response from server and route to stubbed response without switching to stub mode explicitly.

Appreciate your support and let me know if any other details are required.

bbyars commented 6 years ago

Also requested at https://groups.google.com/forum/#!msg/mountebank-discuss/hQa6Mf1Y53M/0CLn5tXuCwAJ;context-place=msg/mountebank-discuss/mYb636LwyP4/4Yim9KOaBwAJ

bbyars commented 5 years ago

Initial thought is an interface that looks something like this:

"stubs": [
  {
    "responses": [{
      "proxy": {
        "to": "http://origin-server.com",
        "mode": "proxyOnce",
        "predicateGenerators": [{ "matches": { "path": true } }],
        "failedConnectResponse": {
          "statusCode": 500
        }
      }
    }],
    "_behaviors": {
      "ignoreIf": {
        "startsWith": {
           "statusCode": 5
        }
      }
    }
  },
  {
    "responses": [{
      "is": { ... }
    }]
  }
]

That provides a general purpose (multi-protocol) approach that I think works in all cases, and involves two new fields:

failedConnectResponse should be easy to add. ignoreIf is considerably more difficult. The following should be true if we're ignoring the stub response: