Search code examples
k6

disable some calls in default function


export default function() {
http.get(api_1);
http.get(api_2);
http.get(api_3);
};

I want to disable the request for api_2.I want to do this by passing some parameters during the k6 script execution.Is k6 provide some support for this?

I tried using the boolean flag.


Solution

  • Yes, you can use environment variables to control the k6 script execution: https://docs.k6.io/docs/environment-variables

    So, in your case you can run write your function like this:

    export default function() {
      http.get(api_1);
      if (__ENV.SOMETHING) {
        http.get(api_2);
      }
      http.get(api_3);
    };
    

    And then execute k6 run script.js when you don't want to execute the second API call and k6 run --env SOMETHING=true script.js when you do.