Menu
Open source

Mock

You can use this secret source to test your tests quick and easy.

bash
$ k6 run --secret-source=cli=mysecret=value script.js
docker
$ docker run -it --rm \
    -v <scriptdir>:/scripts \
    grafana/k6 run --secret-source=mock=mysecret=value /scripts/script.js

You can even use multiple ones and have some of them named or set as default.

bash
$ k6 run --secret-source=mock=default,cool="cool secret" --secret-source=mock=name=another,cool="not cool secret" multi-source.test.js```
JavaScript
import secrets from "k6/secrets";

export default async () => {
  const my_secret = await secrets.get("cool");
  console.log(my_secret == "cool secret");
  const anothersource = await secrets.source("another")
  console.log(await anothersource.get("cool") == "cool secret");
  console.log(await anothersource.get("cool") == "not cool secret");
}