Writing stubs in mountebank tends to go through the same loop: you set up predicates, fire a real request to see if they match, check the logs when they don't, tweak, and try again. The more predicates a stub has, the longer this loop gets.
There is currently nothing on the mountebank side that shortens this. The --debug flag adds match information to imposter retrievals, but that is post-mortem data after a real request has already hit the imposter. There is no way to ask "if I were to send this request, which stubs would match?" without actually sending it.
Proposal: a new admin endpoint, POST /imposters/:id/test. You hand it a candidate request and mountebank returns, for every stub, whether it would match and which predicates failed if it would not. It reuses the existing predicate matcher, no new matching logic.
Example request:
POST /imposters/3000/test
{
"method": "POST",
"path": "/orders",
"body": { "id": 42 }
}
Example response:
{
"matched": { "stubIndex": 1 },
"candidates": [
{
"stubIndex": 0,
"matched": false,
"failedPredicates": [
{ "equals": { "path": "/order" } }
]
},
{
"stubIndex": 1,
"matched": true
}
]
}
Why it fits mountebank's design:
- Reuses the existing predicate matcher
- Protocol-agnostic, since the predicate engine already is
- No new dependencies
- New endpoint, does not change any existing one
One open question: how detailed should the failure report be in the first version?
-
Plain: return the list of failed predicates as-is, like the example above. The matcher does not change.
-
Detailed: produce a human-readable diff such as body 'foo' did not contain 'order'. This option requires extending the matcher.
If this sounds reasonable I'd be happy to take it on.
Writing stubs in mountebank tends to go through the same loop: you set up predicates, fire a real request to see if they match, check the logs when they don't, tweak, and try again. The more predicates a stub has, the longer this loop gets.
There is currently nothing on the mountebank side that shortens this. The
--debugflag adds match information to imposter retrievals, but that is post-mortem data after a real request has already hit the imposter. There is no way to ask "if I were to send this request, which stubs would match?" without actually sending it.Proposal: a new admin endpoint,
POST /imposters/:id/test. You hand it a candidate request and mountebank returns, for every stub, whether it would match and which predicates failed if it would not. It reuses the existing predicate matcher, no new matching logic.Example request:
Example response:
{ "matched": { "stubIndex": 1 }, "candidates": [ { "stubIndex": 0, "matched": false, "failedPredicates": [ { "equals": { "path": "/order" } } ] }, { "stubIndex": 1, "matched": true } ] }Why it fits mountebank's design:
One open question: how detailed should the failure report be in the first version?
Plain: return the list of failed predicates as-is, like the example above. The matcher does not change.
Detailed: produce a human-readable diff such as
body 'foo' did not contain 'order'. This option requires extending the matcher.If this sounds reasonable I'd be happy to take it on.