Menu
Choose a product
Viewing: v1.7.x (latest)
Find another version
Scroll for more
Open source
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:
Bash
k6 run --secret-source=mock=mysecret=value script.jsdocker
docker 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:
Bash
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:
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");
}Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.