Using Copy functionality with Injection

197 views
Skip to first unread message

bpatric...@gmail.com

unread,
Jan 23, 2017, 5:08:30 AM1/23/17
to mountebank-discuss
Hey,

Very new to the world of Mountebank (it's awesome though :) )and attempting to get my head around the copy function/behavior

I had hoped to use regex selectors to pull values from the request and assign them to variables that were accessible when using the inject functionality

"responses": [{
"inject": "<%- stringify(filename, '999.ejs') %>",
"_behaviors": {
"copy": [
{
"from": "body",
"into": "${state.ediVersion}",
"using": { "method": "regex", "selector": "ST" }
},
{
"from": "path",
"into": "${state.Path}",
"using": { "method": "regex", "selector": ".*" }
}
]}
}]


Should hopefully give some context to the type of thing I wanted to do. I thought I might be able to use the state object that is accessible when injecting behavior but it's not quite working. I assume the state isn't really 'reserved' or I'm referencing it wrong externally.

Any ideas?

I think I can just pull the parsing down into the inject function which i'm looking to do now but had wondered if the 2 were compatible with each other

Brandon Byars

unread,
Jan 23, 2017, 8:52:34 AM1/23/17
to bpatric...@gmail.com, mountebank-discuss
Hi there,
Welcome! And thanks for reaching out.

Unfortunately, the copy behavior "into" field only works for response fields, not inject parameters. The copy behavior can work with an "inject" response type, but it's usually used with an "is" response type, avoiding the complexity of "inject". If you want to grab the path in your inject function, you can do so directly from the request parameter passed in:

function (request, state, logger) {
  state.path = request.path;
}

Hope that helps, let me know if you're still stuck.
-Brandon



--
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-discuss+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages