Mock
您可以使用此 secret source 快速轻松地测试您的测试。
$ k6 run --secret-source=cli=mysecret=value script.js
$ docker run -it --rm \
-v <scriptdir>:/scripts \
grafana/k6 run --secret-source=mock=mysecret=value /scripts/script.js
您甚至可以使用多个,并为其中一些命名或设置为默认。
$ k6 run --secret-source=mock=default,cool="cool secret" --secret-source=mock=name=another,cool="not cool secret" multi-source.test.js```
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");
}