Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Postman requests take into account K6 param options #88

Merged
merged 2 commits into from
May 7, 2021

Conversation

thim81
Copy link
Contributor

@thim81 thim81 commented Apr 27, 2021

This is a PR to provide support in the Postman request for passing K6 params that are globally defined.

https://k6.io/docs/javascript-api/k6-http/params

Example

export default function () {
  let params = {
    cookies: { my_cookie: 'value' },
    headers: { 'X-MyHeader': 'k6test' },
    redirects: 5,
    tags: { k6test: 'yes' },
  };
  let res = http.get('https://k6.io', params);
}

It seemed that the Postman request function does not uses all the "options", when executing the http.request via K6.

Example script.js file

// Auto-generated by the Load Impact converter

import "./libs/shim/core.js";
import { group } from "k6";
import "./requests/Lists/Get-all-list-configurations.js";

export let options = { maxRedirects: 4 , headers: { 'Content-Type': 'application/json' } };

const Request = Symbol.for("request");
postman[Symbol.for("initial")]({
  options,
  collection: {
    baseUrl: "https://example.com/api"
  },
  environment: {
    baseUrl: "https://example.com/api"
  }
});

...

Which results in the following K6 call

INFO[0006] Request:
GET /api/lists/v2?$top=100&$skip=0&$count=false HTTP/1.1
User-Agent: k6/0.29.0 (https://k6.io/)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip

The PR adds the passing of let options configurations, when making the K6 requests.

export let options = { maxRedirects: 4 , headers: { 'Content-Type': 'application/json' } };

Which results in

INFO[0006] Request:
GET /api/lists/v2?$top=100&$skip=0&$count=false HTTP/1.1
User-Agent: k6/0.29.0 (https://k6.io/)
Content-Type: application/json
Accept-Encoding: gzip

This PR would allow the possibility to leverage any K6 Params https://k6.io/docs/javascript-api/k6-http/params to be used when executing the Postman Request via K6.

@simskij
Copy link
Contributor

simskij commented Apr 27, 2021

I need to test this before merging, but from eyeing it this looks great. Good job, @thim81! 👏🏼

@simskij simskij merged commit ae3d1a7 into grafana:master May 7, 2021
@simskij
Copy link
Contributor

simskij commented May 7, 2021

Thanks a bunch for your contribution! 🎉

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

Successfully merging this pull request may close these issues.

None yet

2 participants