From 66e56c92a7f82bee34ae9b1cf3c6a7b9c2158dfb Mon Sep 17 00:00:00 2001 From: oleiade Date: Wed, 5 Jul 2023 11:12:04 +0200 Subject: [PATCH] Add example of `k6/experimental/fs` module --- examples/experimental/fs/bonjour.txt | 1 + examples/experimental/fs/fs.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 examples/experimental/fs/bonjour.txt create mode 100644 examples/experimental/fs/fs.js diff --git a/examples/experimental/fs/bonjour.txt b/examples/experimental/fs/bonjour.txt new file mode 100644 index 000000000000..589326a33ee8 --- /dev/null +++ b/examples/experimental/fs/bonjour.txt @@ -0,0 +1 @@ +Bonjour, tout le monde! \ No newline at end of file diff --git a/examples/experimental/fs/fs.js b/examples/experimental/fs/fs.js new file mode 100644 index 000000000000..d7347c970076 --- /dev/null +++ b/examples/experimental/fs/fs.js @@ -0,0 +1,20 @@ +import { open } from "k6/experimental/fs"; + +export const options = { + vus: 100, + iterations: 1000, +}; + +// As k6 does not support asynchronous code in the init context, yet, we need to +// use a top-level async function to be able to use the `await` keyword. +let file; +(async function () { + file = await open("bonjour.txt"); +})(); + +export default async function () { + const fileinfo = await file.stat(); + if (fileinfo.name != "bonjour.txt") { + throw new Error("Unexpected file name"); + } +}