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

ResponseTemplating: now format='epoch' is read as zero when passed as input to math #1946

Closed
code-and-such opened this issue Sep 5, 2022 · 1 comment
Labels

Comments

@code-and-such
Copy link

The problem

"body" : "[{{#each (range 0 20) as |index|}} [ {{math (now format='epoch') '+' (math index '*' 86400000)}}, {{randomDecimal lower=190.0 upper=220.0}} ] {{#if @last}}{{else}},{{/if}}{{/each}}]",

This will generate a body that looks like

[ [ 0, 196.3580633809619 ] , [ 86400000, 196.39208777016043 ] , [ 172800000, 197.86647674155523 ] , [ 259200000, 205.36354784502032 ] , [ 345600000, 192.65030129839516 ] ..... ]

As you can see it seems like math treats the output from (now format='epoch') as zero. If I use now format='epoch' outside the context of math, it works like a charm.

Might it be that now format='epoch' returns a string or something else that makes math lay down and die?

Details

  • Version: 2.33.2
  • Starting the server docker run -d --name wiremock-timeseries --network host -v $PWD/timeseries-wiremock:/home/wiremock -e uid=$(id -u) wiremock/wiremock --port="8083" --local-response-templating --verbose
  • The full stub (I removed a bunch of stuff I do not want to leave the company)
{
  "id" : "04056434-098e-3775-a070-1ca35778aa25",
  "request" : {
    "urlPattern": "/.*",
    "method" : "POST"
  },
  "response" : {
    "transformers": ["response-template"],
    "status" : 200,
    "body" : "[{{#each (range 0 20) as |index|}} [ {{math (now format='epoch') '+' (math index '*' 86400000)}}, {{randomDecimal lower=190.0 upper=220.0}} ] {{#if @last}}{{else}},{{/if}}{{/each}}]",
    "headers" : {
      "Date" : "Mon, 05 Sep 2022 14:17:55 GMT",
      "Content-Type" : "application/json",
      "X-Content-Type-Options" : "nosniff",
      "X-XSS-Protection" : "1; mode=block",
      "Cache-Control" : "no-cache, no-store, max-age=0, must-revalidate",
      "Pragma" : "no-cache",
      "Expires" : "0"
    }
  },
  "uuid" : "04056434-098e-3775-a070-1ca35778aa25"
}
@code-and-such code-and-such changed the title ResponseTemplating: now format='epoch' is read as zero when passing it into math ResponseTemplating: now format='epoch' is read as zero when passed as input to math Sep 5, 2022
@tomakehurst
Copy link
Member

Confirmed this is an issue. The maths helper can't cope with a date object as an input.

You can work around this by assigning it to a variable, which will cast it to a String e.g.

{{#assign 'currentEpoch'}}{{now format='epoch'}}{{/assign}}
{{math currentEpoch '+' (math index '*' 86400000)}}

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

No branches or pull requests

2 participants