Quantcast
Channel: Grafana k6 - Grafana Labs Community Forums
Viewing all articles
Browse latest Browse all 367

Is it possible to turn off have different options for the setup phase?

$
0
0

I am looking to make http requests during the setup phase to generate API Keys to use for tests. So I need the discardResponseBodies set to false.

However, after the setup phase I want to set that to true.

import http from 'k6/http';
import { getScenarios, addTestInfoMetrics } from "/helpers/tests.js";
import { generateKeys } from "/helpers/auth.js";

const { SCENARIO } = __ENV;
export const options = {
  discardResponseBodies: false,
  scenarios: { [SCENARIO]: getScenarios(${jsonencode(var.config)})[SCENARIO] },
};

export function setup() {
  addTestInfoMetrics(${jsonencode(var.config)});
  if (${var.config.auth.enabled}) {
    return generateKeys("${var.name}", ${var.config.auth.key_count})
  }
  return {};
}

export default function (keys) {
  let headers = {};
  if (${var.config.auth.enabled}) {
    const i = Math.floor(Math.random() * keys.length);
    headers = { "Authorization": keys[i] }
  }

  http.get('http://${var.url}/timestamp/json', { headers });
}

Is the only way to solve this to use a different http lib?

2 posts - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 367

Trending Articles