lookup regex selector on path element not working

56 views
Skip to first unread message

Tony Murphy

unread,
Oct 25, 2023, 4:00:28 PM10/25/23
to mountebank-discuss
The following is a lookup I'm trying to do by extracting a UUID from the path..
but I can't get it to work.. 
Any ideas what I'm doing wrong
"lookup": [{
 "key": {
  "from": "path",
  "using": {
   "method": "regex",
   "selector": "\\/billing\\/v1\\/([^\\/]+)\\/transactions"
  }
 },
 "fromDataSource": {
  "csv": {
   "path": "billing/lookup.csv",
   "keyColumn": "SHIPMENT_ID"
  }
 },
 "into": "${row}"
}]

Tony Murphy

unread,
Nov 8, 2023, 8:30:33 AM11/8/23
to mountebank-discuss
I followed example now in
https://www.mbtest.org/docs/api/behaviors#lookup-regex-replacement
                "key": { "from": "path", "using": { "method": "regex", "selector": "/(.*)$" }, "index": 1 },
I'm wondering if I should just abandon mountebank, very hard to debug 

Simon Brunning

unread,
Nov 8, 2023, 8:47:05 AM11/8/23
to Tony Murphy, mountebank-discuss
Do you need an lookup.key.index there? I'm guessing you'd want to match group 1.

Cheers,
Simon B.
> --
> You received this message because you are subscribed to the Google Groups "mountebank-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mountebank-disc...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mountebank-discuss/ee6c9a4a-ada9-4d27-85e3-f3650c64af82n%40googlegroups.com.

Tony Murphy

unread,
Nov 9, 2023, 8:56:02 AM11/9/23
to mountebank-discuss
I managed to get it to work (with ChatGPTs help - it does need to be properly trained on Mountebank with more examples etc)

"behaviors": [
{

  "lookup": {
  "key": {
    "from": "path",
    "using": { "method": "regex", "selector": "\\/billing\\/v1\\/shipments\\/(.*)\\/transactions\\/(.*)" },
    "index": 2
  },
  "fromDataSource": {
    "csv": {
      "path": "billing/lookup/errors.csv",
      "keyColumn": "BILLING_TRANSACTION_ID",
      "delimiter": ","
    }
  },
  "into": "${row}"
  }
}
],

Also, it's not clear if escaping is required or not, once I got lookup working, I left it. Would be good if debug mode printed the "match"
Also, would be good if the lookup was actually somehow a predicate, so it can skip stub and move onto next one.. Right now, if the lookup fails, it returns the template with placeholders.

I don't want to use injection mode, so I need to try and get my test data setup as concise as possible.



Next step is to get the predicates to work with regex. Right now, the predicate defeats the purpose of my nice lookup regex.

"predicates": [
  { "equals": { "method": "POST" } },
  { "equals": {
    "path": "/billing/v1/shipments/34492b59-4d9d-4912-9efb-5b88f82a1603/transactions/265c13f0-aadd-4980-8966-096c495a38bc"
  }
}
]
Reply all
Reply to author
Forward
0 new messages