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

let 'main' be a function that passes in Index #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Jonahss
Copy link

@Jonahss Jonahss commented Feb 14, 2017

Hello,

I was looking for a module just like this one, so was glad to find it :)

In my use case, I wanted each request to have different random information in the payload, or a random header. I assumed I could pass bench-rest a function, and it would call the function each time a request is generated so that I can easily calculate different parameters each time.

Here's an example of sending different coordinates to an api endpoint that tracks the location of a package:

  let flow = (index) => {
    return {
      main: [
        {
          post: `${env}/track`,
          headers: {
            'Auth-Token': _.sample(authTokens)
          },
          json: randomLocation(),
          delayAfter: 500,
        }
      ]
    }
  }

Notice how interpolation of the INDEX is no longer necessary, if we just have the flow defined as a function instead of a plain json object. The index can be passed in as the first argument and used by users if they choose.

Of course, the change is backwards compatible, if you pass in a plain object, it uses it. If you pass in a function it runs the function to get the object.

My implementation in this PR is a first draft. If you like the idea I can flesh-out the support and add docs.

What do you think?

@jeffbski
Copy link
Owner

@Jonahss This sounds like a great idea. I had always planned that we might need a way to extend the values that are interpolated, so this seems like a nice way to do it.

I'm going to ponder this a bit to consider if there are any other things we should take into account in this API. If we think that the number of things we pass might grow, we might want to pass an object and then using destructuring it is just as easy to get at what you want, yet it allows us to pass more things later.

@Jonahss
Copy link
Author

Jonahss commented Jun 20, 2017

bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants