Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change injection functions to accept an object #294

Closed
bbyars opened this issue Oct 2, 2017 · 4 comments
Closed

Change injection functions to accept an object #294

bbyars opened this issue Oct 2, 2017 · 4 comments

Comments

@bbyars
Copy link
Owner

bbyars commented Oct 2, 2017

As injection functions have expanded in functionality, they've accrued additional parameters, making the signature feel ad-hoc. You may need the fourth parameter but not the third, and why are there so many parameters anyhow?

I'd like to convert all injection functions to accept a single object parameter that contains fields for the current values. For response injection, for example, the current signature is:

function (request, state, logger, callback, imposterState) {...}

And the fifth imposterState parameter is undocumented, added way back when in a PR. Other new parameters will likewise just get shoved in at the end. I'd like to transform the signature to a single object containing the appropriate fields:

function (config) {
  // config.request
  // config.state
  // config.logger
  // config.callback
  // config.imposterState
}

For backwards compatibility, the old interface needs to still work. My preference would be to fix it in the upcast function in compatibility.js, as I'd like to centralize all backwards compatibility logic where possible.

The full list of injection functions can be found by searching for the literal string "eval(" and includes:

  • response injection (responseResolver.js)
  • advanced wait behavior (behaviors.js)
  • decorate behavior (behaviors.js)
  • predicate injection (predicates.js)
  • tcp endOfRequestResolver (tcp.js)
@bbyars bbyars added this to v1.14.0 in Roadmap Oct 27, 2017
@bbyars bbyars added this to Not Started in v1.14.0 Oct 27, 2017
@bbyars bbyars removed this from Not Started in v1.14.0 Feb 18, 2018
@bbyars bbyars added this to To do in v1.15.0 via automation Feb 18, 2018
@bbyars bbyars moved this from v1.14.0 to v1.15.0 in Roadmap Feb 18, 2018
@bbyars bbyars added this to Power user experience in Themes Feb 18, 2018
@bbyars
Copy link
Owner Author

bbyars commented Mar 26, 2018

Copying Igor Korobka's question:

Hi,

Is there a way to inject imposter port into the stubbed response? I'm trying to virtualize a configuration service that returns URLs to some other configuration files. To make it work with mountebank I'd need to compose each URL with {imposter-hostname}:{imposter-port}. I can workaround the hostname part by using "localhost" but can't seem to find a way to inject the port part.

I'm creating imposters via mountebank REST API.

Would appreciate any assistance!

@bbyars bbyars removed this from To do in v1.15.0 Jun 27, 2018
@bbyars bbyars moved this from v1.15.0 to v1.16.0 in Roadmap Jun 27, 2018
@bbyars bbyars added this to Backlog in v1.16.0 Dec 21, 2018
@bbyars bbyars removed this from Backlog in v1.16.0 Dec 21, 2018
@bbyars bbyars moved this from v1.16.0 to v1.17.0 in Roadmap Dec 29, 2018
@bbyars bbyars added this to To do in v1.17.0 Dec 29, 2018
@bbyars
Copy link
Owner Author

bbyars commented Feb 12, 2019

Merge the injectionState and imposterState for responses

@bbyars bbyars removed this from To do in v1.17.0 Feb 12, 2019
@bbyars bbyars moved this from v1.17.0 to v1.18.0 in Roadmap Feb 12, 2019
@bbyars bbyars added this to In progress in v1.17.0 Mar 9, 2019
bbyars added a commit that referenced this issue Mar 11, 2019
Taking a single object parameter allows us to add fields without
creating a clunky interfade
#294
bbyars added a commit that referenced this issue Mar 11, 2019
@bbyars bbyars closed this as completed Mar 14, 2019
@bbyars bbyars moved this from In progress to Done in v1.17.0 Mar 14, 2019
@bbyars bbyars removed this from v2.1.0 in Roadmap May 9, 2019
@jonscottclark
Copy link

Hey @bbyars , I think the code example for addDecorateBehavior (here: http://www.mbtest.org/docs/api/proxies#proxy-add-decorate-behavior) still refers to the old arguments (request, response)

@bbyars
Copy link
Owner Author

bbyars commented Feb 8, 2020

Thanks!

mikeschinkel pushed a commit to jbolda/mountebank that referenced this issue Apr 2, 2021
Taking a single object parameter allows us to add fields without
creating a clunky interfade
bbyars#294
mikeschinkel pushed a commit to jbolda/mountebank that referenced this issue Apr 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Themes
Power user experience
v1.13.0
Awaiting triage
v1.17.0
  
Done
Development

No branches or pull requests

2 participants