Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/next/using-k6/secret-source/mock.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/using-k6/secret-source/mock/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
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

