artilleryio / artillery

The complete load testing platform. Everything you need for production-grade load tests. Serverless & distributed. Load test with Playwright. Load test HTTP APIs, GraphQL, WebSocket, and more. Use any Node.js module.
https://www.artillery.io
Mozilla Public License 2.0
7.99k stars 508 forks source link

JSON using variables #848

Open PokeyOats opened 4 years ago

PokeyOats commented 4 years ago

Good Day all,

I think I have found a bug in a situation using a variable with JSON.

Whilst the following works:

   - post:
        url: "/jsontest"
        json: 
          { "alerts": [ { "labels": { "alertname": "Watchdog" } } ] }

The following doesn't.

variables:
    jsontest1: "{ \"alerts\": [ { \"labels\": { \"alertname\": \"Watchdog\" } } ] }"

...

    - post:
        url: "/jsontest"
        json: 
          {{ jsontest1 }}
PokeyOats commented 4 years ago

My apologies, I made a mistake.

- post:
        url: "/jsontest"
        body: "{{ jsontest1 }}"

I've even gone as far as reading the json from a file into a var and then sent that but it does not work

    - function: "GetSomeData"
    - post:
      url: "/jsontest"
        body: "{{ funcdata }}"

module.exports = {
    GetSomeData: GetSomeData,
  }

  function GetSomeData(context, ee, next)
  {
    var fs = require('fs');
    fs.readFile('test.txt', 'utf8', function(err, data) 
    {
      if (err) throw err;
      context.vars.funcdata = data;
    });
    return next();
  }
PokeyOats commented 4 years ago
funcdata: { "alerts": [ { "labels": { "alertname": "Watchdog" } } ] }
artvar:   { "alerts": [ { "labels": { "alertname": "Watchdog" } } ] }