Allow listing of files in the init context #1005
Labels
evaluation needed
proposal needs to be validated or tested before fully implementing it in k6
feature
ux
Currently, users can
open()
files if they know their filenames, but they can't traverse the filesystem and open files dynamically. A few functions to navigate around the filesystem would help with the UX of writing file-heavy tests, as described in this forum post.This should probably happen after we have a reasonable way to not read the contents of every file in every VU, as
open()
currently does. So, as a quick fix, having the__VU
variable available in the init context would do, but longer-term, something like #592 and #532 would be ideal.And an open question is whether we should try to emulate even parts of the
fs
node API, or if we should do something much simpler and narrower in scope. For now I'm definitely leaning toward the latter option...Current workarounds:
Describe desired files in a
.json
file:If I have a
testfile.json
with an array of file names (or something more complicated with additional metadata), I can just open it, and then iterate over its contents to open all of the other files:Pass a list of file as an environment variable
You could run
k6 run --env filelist="file1;file2;file3" script.js
and then use__ENV.filelist
in the k6 script's init context to open all of the supplied files. Of course, thefilelist
value could also be dynamically generated (e.g.--env filelist="$(find ./some/folder -type f -print0 | tr '\0' ';')"
), as long as we pay attention that the filenames don't contain the chosen separator. And, for the moment, that the separator isn't a comma 🪲 ...Load the files from an HTTP server
As the forum post suggested, the files could be located on a simple HTTP server. This way they can be retrieved in the
setup()
function or in the future per-VU init function.The text was updated successfully, but these errors were encountered: