script

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package script runs a scenario's JavaScript steps with goja. A script sees the virtual user's variables as `vars` (and may set new ones), the environment as `env`, its feeder rows as `data`, and `vu` and `iteration`; `fail(message)` fails the iteration. Scripts have no network, file or timer access, and each run is bounded by Timeout.

Index

Constants

View Source
const Timeout = time.Second

Timeout bounds one run of a script.

Variables

This section is empty.

Functions

This section is empty.

Types

type Failure

type Failure struct{ Message string }

Failure is a script calling fail(message).

func (*Failure) Error

func (f *Failure) Error() string

type Input

type Input struct {
	Vars      map[string]any
	Env       map[string]string
	Data      map[string]any
	VU        int64
	Iteration int64
	// Log receives console.log output; nil discards it.
	Log func(string)
}

Input is what a script sees.

type Program

type Program struct {

	// Source is the script as written, for error messages.
	Source string
	// contains filtered or unexported fields
}

Program is a compiled script.

func Compile

func Compile(name, code string) (*Program, error)

Compile parses code once, ahead of the run. The body runs as a function in strict mode, so `return` ends it early.

type Runner

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

Runner runs scripts for one virtual user. It is not safe for concurrent use; give each virtual user its own.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, p *Program, in Input) (map[string]any, error)

Run executes p and returns the variables afterwards: in.Vars with the script's changes. in.Vars itself is not modified.

Jump to

Keyboard shortcuts

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