Documentation Index
Fetch the curated documentation index at: https://grafana_com_website/llms.txt
Fetch the complete documentation index at: https://grafana_com_website/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: /docs/k6/latest/using-k6/secret-source/mock.md (append .md) or send Accept: text/markdown to /docs/k6/latest/using-k6/secret-source/mock/. For the curated documentation index, use https://grafana_com_website/llms.txt. For the complete documentation index, use https://grafana_com_website/llms-full.txt.
Mock secret source
The mock secret source provides a quick way to test scripts with secrets.
Note
Don’t use the mock secret source in production. This source is designed for testing purposes only.
To use the mock secret source, provide secrets directly in the command line:
k6 run --secret-source=mock=mysecret=value script.jsdocker run -it --rm \
-v <SCRIPT_DIR>:/scripts \
grafana/k6 run --secret-source=mock=mysecret=value /scripts/script.jsIn the Docker example, replace <SCRIPT_DIR> with the absolute path to the directory that contains your script.
Use multiple mock sources
Configure multiple mock sources and assign them names. You can also set one as the default source.
The following example configures two mock sources: one default source and one named another:
k6 run --secret-source=mock=default,cool="cool secret" --secret-source=mock=name=another,cool="not cool secret" multi-source.test.jsThe following script demonstrates how to retrieve secrets from different sources:
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");
}Was this page helpful?
Related resources from Grafana Labs

