filestorage

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 8 Imported by: 0

README

xk6-filestorage

Extension for k6. Allows to manage the file system during the execution of k6 tests.

Requirements

go install go.k6.io/xk6/cmd/xk6@latest

Build

From local repository:

xk6 build --with xk6-filestorage=.

From remote repository:

xk6 build --with github.com/Gwinkamp/xk6-filestorage

Usage

In load testing scenarios:

import { sleep } from "k6";
import fs from 'k6/x/filestorage';

export const options = {
  target: 1,
  duration: '10s',
};

export default function () {
  const storage = new fs.FileStorage("./testdata");

  const test0txt = storage.readFile("test-0.txt");
  const test00txt = storage.readFile("subdir/test-00.txt");

  console.log(`list files: ${storage.listFiles()}`);
  console.log(`is test-3.bin file exists: ${storage.hasFile("test-3.bin")}`);
  console.log(`is subdir/test-01.xml file exists: ${storage.hasFile("subdir/test-01.xml")}`);
  console.log(`is test-4.doc file exists: ${storage.hasFile("test-4.doc")}`);
  console.log(`test-0.txt file name: ${test0txt.name}, path: ${test0txt.path}, content: ${test0txt.content}`);
  console.log(`subdir/test-0.txt file name: ${test00txt.name}, path: ${test00txt.path}, content: ${test00txt.content}`);
  console.log(`random file: ${storage.readRandFile().name}`);
  console.log(`random xml file name: ${storage.readRandFileWithExt(".xml").name}`);

  sleep(1)
}

To run this script, you need to run the k6 executable file, which was previously built with the xk6 build command

./k6 run scripts/example.js

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Name    string
	Path    string
	Content []byte
}

type FileStorage

type FileStorage struct {
	// contains filtered or unexported fields
}

func NewFileStorage

func NewFileStorage(basePath string) *FileStorage

func (*FileStorage) HasFile

func (fs *FileStorage) HasFile(key string) bool

func (*FileStorage) ListFiles

func (fs *FileStorage) ListFiles() []string

func (*FileStorage) ReadFile

func (fs *FileStorage) ReadFile(key string) (File, error)

func (*FileStorage) ReadRandFile

func (fs *FileStorage) ReadRandFile() (File, error)

ReadRandFile reads a random file from the storage

func (*FileStorage) ReadRandFileWithExt

func (fs *FileStorage) ReadRandFileWithExt(ext string) (File, error)

ReadRandFileWithExt reads a random file with the given extension from the storage

type FileStorageExt

type FileStorageExt struct{}

func (*FileStorageExt) XFileStorage

func (b *FileStorageExt) XFileStorage(call goja.ConstructorCall, rt *goja.Runtime) *goja.Object

XFileStorage creates a new FileStorage instance with the given base path. Usage in k6 scripts: `const storage = new FileStorage("./testdata");`

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL